From 63b1d4397a87cdd0cfa2e18762b84b88c7a33b79 Mon Sep 17 00:00:00 2001 From: crs Date: Wed, 24 Jul 2002 19:26:18 +0000 Subject: [PATCH] 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. --- platform/CMSWindowsScreen.cpp | 2 +- platform/CWin32Platform.cpp | 16 ++++++++++++++-- platform/CWin32Platform.h | 2 ++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/platform/CMSWindowsScreen.cpp b/platform/CMSWindowsScreen.cpp index b6e87f56..45041f72 100644 --- a/platform/CMSWindowsScreen.cpp +++ b/platform/CMSWindowsScreen.cpp @@ -194,7 +194,7 @@ CMSWindowsScreen::mainLoop() // handle quit message if (event.m_msg.message == WM_QUIT) { - break; + CThread::getCurrentThread().cancel(); } // dispatch message diff --git a/platform/CWin32Platform.cpp b/platform/CWin32Platform.cpp index 3553c38a..b30f0bc6 100644 --- a/platform/CWin32Platform.cpp +++ b/platform/CWin32Platform.cpp @@ -2,6 +2,7 @@ #include "CLock.h" #include "CThread.h" #include "CLog.h" +#include "TMethodJob.h" #include "stdvector.h" #include #include @@ -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(this, + &CWin32Platform::runDaemonThread, run)); + result = reinterpret_cast(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(vrun); + CThread::exit(reinterpret_cast(run(m_serviceMutex))); +} + void CWin32Platform::serviceMain(DWORD argc, LPTSTR* argvIn) { diff --git a/platform/CWin32Platform.h b/platform/CWin32Platform.h index 0fed1011..8d0985c7 100644 --- a/platform/CWin32Platform.h +++ b/platform/CWin32Platform.h @@ -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);