1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Fix broken thread stop handling

This commit is contained in:
sapier 2013-11-30 01:51:54 +01:00
parent d02ce1cf4d
commit d19a69cd0d
5 changed files with 35 additions and 6 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;