mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-26 23:36:59 -05:00
fixed a bug in RsThread which made finished threads unaware of their state
This commit is contained in:
parent
5410c51ab9
commit
a7eb167f96
@ -61,6 +61,16 @@ int RS_pthread_setname_np(pthread_t __target_thread, const char *__buf) {
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void RsThread::go()
|
||||||
|
{
|
||||||
|
mShouldStopSemaphore.set(0) ;
|
||||||
|
mHasStoppedSemaphore.set(0) ;
|
||||||
|
|
||||||
|
runloop();
|
||||||
|
|
||||||
|
mHasStoppedSemaphore.set(1);
|
||||||
|
mShouldStopSemaphore.set(0);
|
||||||
|
}
|
||||||
void *RsThread::rsthread_init(void* p)
|
void *RsThread::rsthread_init(void* p)
|
||||||
{
|
{
|
||||||
RsThread *thread = (RsThread *) p;
|
RsThread *thread = (RsThread *) p;
|
||||||
@ -76,7 +86,7 @@ void *RsThread::rsthread_init(void* p)
|
|||||||
std::cerr << "[Thread ID:" << std::hex << pthread_self() << std::dec << "] thread is started. Calling runloop()..." << std::endl;
|
std::cerr << "[Thread ID:" << std::hex << pthread_self() << std::dec << "] thread is started. Calling runloop()..." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
thread -> runloop();
|
thread->go();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
RsThread::RsThread()
|
RsThread::RsThread()
|
||||||
@ -216,14 +226,11 @@ RsTickingThread::RsTickingThread()
|
|||||||
|
|
||||||
void RsSingleJobThread::runloop()
|
void RsSingleJobThread::runloop()
|
||||||
{
|
{
|
||||||
mHasStoppedSemaphore.set(0) ;
|
|
||||||
run() ;
|
run() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsTickingThread::runloop()
|
void RsTickingThread::runloop()
|
||||||
{
|
{
|
||||||
mHasStoppedSemaphore.set(0) ; // first time we are 100% the thread is actually running.
|
|
||||||
|
|
||||||
#ifdef DEBUG_THREADS
|
#ifdef DEBUG_THREADS
|
||||||
THREAD_DEBUG << "RsTickingThread::runloop(). Setting stopped=0" << std::endl;
|
THREAD_DEBUG << "RsTickingThread::runloop(). Setting stopped=0" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -235,7 +242,6 @@ void RsTickingThread::runloop()
|
|||||||
#ifdef DEBUG_THREADS
|
#ifdef DEBUG_THREADS
|
||||||
THREAD_DEBUG << "pqithreadstreamer::runloop(): asked to stop. setting hasStopped=1, and returning. Thread ends." << std::endl;
|
THREAD_DEBUG << "pqithreadstreamer::runloop(): asked to stop. setting hasStopped=1, and returning. Thread ends." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
mHasStoppedSemaphore.set(1);
|
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,6 +263,7 @@ class RsThread
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void runloop() =0; /* called once the thread is started. Should be overloaded by subclasses. */
|
virtual void runloop() =0; /* called once the thread is started. Should be overloaded by subclasses. */
|
||||||
|
void go() ; // this one calls runloop and also sets the flags correctly when the thread is finished running.
|
||||||
|
|
||||||
RsSemaphore mHasStoppedSemaphore;
|
RsSemaphore mHasStoppedSemaphore;
|
||||||
RsSemaphore mShouldStopSemaphore;
|
RsSemaphore mShouldStopSemaphore;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user