diff options
author | sapier <Sapier at GMX dot net> | 2014-01-31 22:16:47 +0100 |
---|---|---|
committer | sapier <Sapier at GMX dot net> | 2014-04-19 10:05:23 +0200 |
commit | ea0df3e4cb75a7a104a81e050c019049219c4fee (patch) | |
tree | 02ad409cc7e5b988b2b6093868723b39f9b61dba /src/jthread/win32 | |
parent | c00ed9dac3e3bed36ea06d80fc9856927f1cca95 (diff) | |
download | minetest-ea0df3e4cb75a7a104a81e050c019049219c4fee.tar.gz minetest-ea0df3e4cb75a7a104a81e050c019049219c4fee.tar.bz2 minetest-ea0df3e4cb75a7a104a81e050c019049219c4fee.zip |
jthread remove locks that aren't absolutely required
add c++11 atomic support (optional)
Diffstat (limited to 'src/jthread/win32')
-rwxr-xr-x | src/jthread/win32/jthread.cpp | 52 |
1 files changed, 2 insertions, 50 deletions
diff --git a/src/jthread/win32/jthread.cpp b/src/jthread/win32/jthread.cpp index 6a745c590..a1cf91a2c 100755 --- a/src/jthread/win32/jthread.cpp +++ b/src/jthread/win32/jthread.cpp @@ -44,35 +44,20 @@ JThread::~JThread() Kill(); } -void JThread::Stop() { - runningmutex.Lock(); - requeststop = true; - runningmutex.Unlock(); -} - void JThread::Wait() { - runningmutex.Lock(); if (running) { - runningmutex.Unlock(); WaitForSingleObject(threadhandle, INFINITE); } - else - { - runningmutex.Unlock(); - } } int JThread::Start() { - runningmutex.Lock(); if (running) { - runningmutex.Unlock(); return ERR_JTHREAD_ALREADYRUNNING; } requeststop = false; - runningmutex.Unlock(); continuemutex.Lock(); #ifndef _WIN32_WCE @@ -87,15 +72,10 @@ int JThread::Start() } /* Wait until 'running' is set */ - - runningmutex.Lock(); while (!running) { - runningmutex.Unlock(); Sleep(1); - runningmutex.Lock(); } - runningmutex.Unlock(); continuemutex.Unlock(); @@ -107,48 +87,24 @@ int JThread::Start() int JThread::Kill() { - runningmutex.Lock(); if (!running) { - runningmutex.Unlock(); return ERR_JTHREAD_NOTRUNNING; } TerminateThread(threadhandle,0); CloseHandle(threadhandle); running = false; - runningmutex.Unlock(); return 0; } -bool JThread::IsRunning() -{ - bool r; - - runningmutex.Lock(); - r = running; - runningmutex.Unlock(); - return r; -} - -bool JThread::StopRequested() { - bool r; - - runningmutex.Lock(); - r = requeststop; - runningmutex.Unlock(); - return r; -} - void *JThread::GetReturnValue() { void *val; - runningmutex.Lock(); - if (running) + if (running) { val = NULL; - else + } else { val = retval; - runningmutex.Unlock(); return val; } @@ -169,20 +125,16 @@ DWORD WINAPI JThread::TheThread(void *param) 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; } |