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:
parent
2e6e8e179a
commit
63b1d4397a
|
@ -194,7 +194,7 @@ CMSWindowsScreen::mainLoop()
|
|||
|
||||
// handle quit message
|
||||
if (event.m_msg.message == WM_QUIT) {
|
||||
break;
|
||||
CThread::getCurrentThread().cancel();
|
||||
}
|
||||
|
||||
// dispatch message
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "CLock.h"
|
||||
#include "CThread.h"
|
||||
#include "CLog.h"
|
||||
#include "TMethodJob.h"
|
||||
#include "stdvector.h"
|
||||
#include <cstring>
|
||||
#include <shlobj.h>
|
||||
|
@ -556,9 +557,13 @@ CWin32Platform::runDaemon(RunFunc run, StopFunc stop)
|
|||
// mark server as running
|
||||
setStatus(m_statusHandle, SERVICE_RUNNING);
|
||||
|
||||
// run callback
|
||||
// run callback in another thread
|
||||
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;
|
||||
|
||||
// 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
|
||||
CWin32Platform::serviceMain(DWORD argc, LPTSTR* argvIn)
|
||||
{
|
||||
|
|
|
@ -71,6 +71,8 @@ private:
|
|||
void serviceMain(DWORD, LPTSTR*);
|
||||
static void WINAPI serviceMainEntry(DWORD, LPTSTR*);
|
||||
|
||||
void runDaemonThread(void*);
|
||||
|
||||
void serviceHandler(DWORD ctrl);
|
||||
static void WINAPI serviceHandlerEntry(DWORD ctrl);
|
||||
|
||||
|
|
Loading…
Reference in New Issue