diff options
author | sapier <Sapier at GMX dot net> | 2013-11-30 01:51:54 +0100 |
---|---|---|
committer | sapier <Sapier at GMX dot net> | 2013-11-30 02:15:31 +0100 |
commit | d19a69cd0d22dfbe802286baf8b33ebb8c6f4fa2 (patch) | |
tree | 813d0cf5a003d6b9e7966c20878a2b131299564d /src/jthread | |
parent | d02ce1cf4d5d283cc6045771612e5b351740e07e (diff) | |
download | minetest-d19a69cd0d22dfbe802286baf8b33ebb8c6f4fa2.tar.gz minetest-d19a69cd0d22dfbe802286baf8b33ebb8c6f4fa2.tar.bz2 minetest-d19a69cd0d22dfbe802286baf8b33ebb8c6f4fa2.zip |
Fix broken thread stop handling
Diffstat (limited to 'src/jthread')
-rw-r--r-- | src/jthread/jthread.h | 2 | ||||
-rw-r--r-- | src/jthread/pthread/jthread.cpp | 13 | ||||
-rw-r--r-- | src/jthread/win32/jthread.cpp | 13 |
3 files changed, 26 insertions, 2 deletions
diff --git a/src/jthread/jthread.h b/src/jthread/jthread.h index 92b05f1c5..867701c75 100644 --- a/src/jthread/jthread.h +++ b/src/jthread/jthread.h @@ -47,6 +47,7 @@ public: int Kill(); virtual void *Thread() = 0; bool IsRunning(); + bool StopRequested(); void *GetReturnValue(); bool IsSameThread(); protected: @@ -69,6 +70,7 @@ private: #endif // WIN32 void *retval; bool running; + bool requeststop; JMutex runningmutex; JMutex continuemutex,continuemutex2; diff --git a/src/jthread/pthread/jthread.cpp b/src/jthread/pthread/jthread.cpp index 2980e26b1..c4d9162c8 100644 --- a/src/jthread/pthread/jthread.cpp +++ b/src/jthread/pthread/jthread.cpp @@ -34,6 +34,7 @@ JThread::JThread() { retval = NULL; mutexinit = false; + requeststop = false; running = false; } @@ -44,7 +45,7 @@ JThread::~JThread() void JThread::Stop() { runningmutex.Lock(); - running = false; + requeststop = true; runningmutex.Unlock(); } @@ -78,6 +79,7 @@ int JThread::Start() runningmutex.Unlock(); return ERR_JTHREAD_ALREADYRUNNING; } + requeststop = false; runningmutex.Unlock(); pthread_attr_t attr; @@ -141,6 +143,15 @@ bool JThread::IsRunning() return r; } +bool JThread::StopRequested() { + bool r; + + runningmutex.Lock(); + r = requeststop; + runningmutex.Unlock(); + return r; +} + void *JThread::GetReturnValue() { void *val; diff --git a/src/jthread/win32/jthread.cpp b/src/jthread/win32/jthread.cpp index 1cf4f93a3..e56c16271 100644 --- a/src/jthread/win32/jthread.cpp +++ b/src/jthread/win32/jthread.cpp @@ -35,6 +35,7 @@ JThread::JThread() { retval = NULL; mutexinit = false; + requeststop = false; running = false; } @@ -45,7 +46,7 @@ JThread::~JThread() void JThread::Stop() { runningmutex.Lock(); - running = false; + requeststop = false; runningmutex.Unlock(); } @@ -76,6 +77,7 @@ int JThread::Start() runningmutex.Unlock(); return ERR_JTHREAD_ALREADYRUNNING; } + requeststop = false;e runningmutex.Unlock(); continuemutex.Lock(); @@ -134,6 +136,15 @@ bool JThread::IsRunning() return r; } +bool JThread::StopRequested() { + bool r; + + runningmutex.Lock(); + r = requeststop; + runningmutex.Unlock(); + return r; +} + void *JThread::GetReturnValue() { void *val; |