diff options
Diffstat (limited to 'src/jthread/win32/jthread.cpp')
-rw-r--r-- | src/jthread/win32/jthread.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/jthread/win32/jthread.cpp b/src/jthread/win32/jthread.cpp index 48b83b894..1cf4f93a3 100644 --- a/src/jthread/win32/jthread.cpp +++ b/src/jthread/win32/jthread.cpp @@ -43,6 +43,12 @@ JThread::~JThread() Kill(); } +void JThread::Stop() { + runningmutex.Lock(); + running = false; + runningmutex.Unlock(); +} + int JThread::Start() { if (!mutexinit) @@ -63,7 +69,7 @@ int JThread::Start() return ERR_JTHREAD_CANTINITMUTEX; } mutexinit = true; } - + runningmutex.Lock(); if (running) { @@ -71,7 +77,7 @@ int JThread::Start() return ERR_JTHREAD_ALREADYRUNNING; } runningmutex.Unlock(); - + continuemutex.Lock(); #ifndef _WIN32_WCE threadhandle = (HANDLE)_beginthreadex(NULL,0,TheThread,this,0,&threadid); @@ -83,10 +89,10 @@ int JThread::Start() continuemutex.Unlock(); return ERR_JTHREAD_CANTSTARTTHREAD; } - + /* Wait until 'running' is set */ - runningmutex.Lock(); + runningmutex.Lock(); while (!running) { runningmutex.Unlock(); @@ -94,18 +100,18 @@ int JThread::Start() runningmutex.Lock(); } runningmutex.Unlock(); - + continuemutex.Unlock(); - + continuemutex2.Lock(); continuemutex2.Unlock(); - + return 0; } int JThread::Kill() { - runningmutex.Lock(); + runningmutex.Lock(); if (!running) { runningmutex.Unlock(); @@ -121,8 +127,8 @@ int JThread::Kill() bool JThread::IsRunning() { bool r; - - runningmutex.Lock(); + + runningmutex.Lock(); r = running; runningmutex.Unlock(); return r; @@ -131,7 +137,7 @@ bool JThread::IsRunning() void *JThread::GetReturnValue() { void *val; - + runningmutex.Lock(); if (running) val = NULL; @@ -156,23 +162,23 @@ DWORD WINAPI JThread::TheThread(void *param) void *ret; jthread = (JThread *)param; - + jthread->continuemutex2.Lock(); jthread->runningmutex.Lock(); jthread->running = true; jthread->runningmutex.Unlock(); - + jthread->continuemutex.Lock(); jthread->continuemutex.Unlock(); - + ret = jthread->Thread(); - + jthread->runningmutex.Lock(); jthread->running = false; jthread->retval = ret; CloseHandle(jthread->threadhandle); jthread->runningmutex.Unlock(); - return 0; + return 0; } void JThread::ThreadStarted() |