fixes for win32 due to changes in how s_restartable is handled.

the main change is that WM_QUIT now causes the thread to be
cancelled instead of mainLoop() just returning.  this also
requires runDaemon() to call the run function in a new thread
each time it calls it because it could can cancelled.
This commit is contained in:
crs 2002-07-24 19:26:18 +00:00
parent 2e6e8e179a
commit 63b1d4397a
3 changed files with 17 additions and 3 deletions

View File

@ -194,7 +194,7 @@ CMSWindowsScreen::mainLoop()
// handle quit message // handle quit message
if (event.m_msg.message == WM_QUIT) { if (event.m_msg.message == WM_QUIT) {
break; CThread::getCurrentThread().cancel();
} }
// dispatch message // dispatch message

View File

@ -2,6 +2,7 @@
#include "CLock.h" #include "CLock.h"
#include "CThread.h" #include "CThread.h"
#include "CLog.h" #include "CLog.h"
#include "TMethodJob.h"
#include "stdvector.h" #include "stdvector.h"
#include <cstring> #include <cstring>
#include <shlobj.h> #include <shlobj.h>
@ -556,9 +557,13 @@ CWin32Platform::runDaemon(RunFunc run, StopFunc stop)
// mark server as running // mark server as running
setStatus(m_statusHandle, SERVICE_RUNNING); setStatus(m_statusHandle, SERVICE_RUNNING);
// run callback // run callback in another thread
m_serviceRunning = true; m_serviceRunning = true;
result = run(m_serviceMutex); {
CThread thread(new TMethodJob<CWin32Platform>(this,
&CWin32Platform::runDaemonThread, run));
result = reinterpret_cast<int>(thread.getResult());
}
m_serviceRunning = false; m_serviceRunning = false;
// notify handler that the server stopped. if handler // notify handler that the server stopped. if handler
@ -620,6 +625,13 @@ CWin32Platform::runDaemon(RunFunc run, StopFunc stop)
} }
} }
void
CWin32Platform::runDaemonThread(void* vrun)
{
RunFunc run = reinterpret_cast<RunFunc>(vrun);
CThread::exit(reinterpret_cast<void*>(run(m_serviceMutex)));
}
void void
CWin32Platform::serviceMain(DWORD argc, LPTSTR* argvIn) CWin32Platform::serviceMain(DWORD argc, LPTSTR* argvIn)
{ {

View File

@ -71,6 +71,8 @@ private:
void serviceMain(DWORD, LPTSTR*); void serviceMain(DWORD, LPTSTR*);
static void WINAPI serviceMainEntry(DWORD, LPTSTR*); static void WINAPI serviceMainEntry(DWORD, LPTSTR*);
void runDaemonThread(void*);
void serviceHandler(DWORD ctrl); void serviceHandler(DWORD ctrl);
static void WINAPI serviceHandlerEntry(DWORD ctrl); static void WINAPI serviceHandlerEntry(DWORD ctrl);