mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-29 01:16:20 -05:00
Merge pull request #2499 from PhenomRetroShare/Fix_RsThread
Fix RsThread when nothing to do and run finish before start.
This commit is contained in:
commit
9b2504d407
@ -322,12 +322,12 @@ void RsGenExchange::tick()
|
||||
{
|
||||
mIntegrityCheck = new RsGxsIntegrityCheck( mDataStore, this,
|
||||
*mSerialiser, mGixs);
|
||||
mIntegrityCheck->start("gxs integrity");
|
||||
mChecking = true;
|
||||
std::string thisName = typeid(*this).name();
|
||||
mChecking = mIntegrityCheck->start("gxs IC4 "+thisName);
|
||||
}
|
||||
}
|
||||
|
||||
if(mIntegrityCheck->isDone())
|
||||
if(mIntegrityCheck->isDone() || !mChecking)
|
||||
{
|
||||
std::vector<RsGxsGroupId> grpIds;
|
||||
GxsMsgReq msgIds;
|
||||
|
@ -92,11 +92,11 @@ void RsThread::resetTid()
|
||||
#ifdef WINDOWS_SYS
|
||||
memset (&mTid, 0, sizeof(mTid));
|
||||
#else
|
||||
mTid = 0;
|
||||
mTid = pthread_t(); //Thread identifiers should be considered opaque and can be null.
|
||||
#endif
|
||||
}
|
||||
|
||||
RsThread::RsThread() : mHasStopped(true), mShouldStop(false), mLastTid()
|
||||
RsThread::RsThread() : mInitMtx("RsThread"), mHasStopped(true), mShouldStop(false), mLastTid()
|
||||
#ifdef RS_THREAD_FORCE_STOP
|
||||
, mStopTimeout(0)
|
||||
#endif
|
||||
@ -115,6 +115,7 @@ void RsThread::askForStop()
|
||||
|
||||
void RsThread::wrapRun()
|
||||
{
|
||||
{RS_STACK_MUTEX(mInitMtx);} // Waiting Init done.
|
||||
run();
|
||||
resetTid();
|
||||
mHasStopped = true;
|
||||
@ -184,6 +185,8 @@ bool RsThread::start(const std::string& threadName)
|
||||
// Atomically check if the thread was already started and set it as running
|
||||
if(mHasStopped.exchange(false))
|
||||
{
|
||||
RS_STACK_MUTEX(mInitMtx); // Block thread starting to run
|
||||
|
||||
mShouldStop = false;
|
||||
int pError = pthread_create(
|
||||
&mTid, nullptr, &rsthread_init, static_cast<void*>(this) );
|
||||
@ -196,15 +199,6 @@ bool RsThread::start(const std::string& threadName)
|
||||
print_stacktrace();
|
||||
return false;
|
||||
}
|
||||
if(!mTid)
|
||||
{
|
||||
RsErr() << __PRETTY_FUNCTION__ << " pthread_create could not create"
|
||||
<< " new thread: " << threadName << " mTid: " << mTid
|
||||
<< std::endl;
|
||||
mHasStopped = true;
|
||||
print_stacktrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Store an extra copy of thread id for debugging */
|
||||
mLastTid = mTid;
|
||||
|
@ -261,6 +261,9 @@ private:
|
||||
/** Call @see run() setting the appropriate flags around it*/
|
||||
void wrapRun();
|
||||
|
||||
// To be sure Init (pthread_setname_np) is done before continue thread. Else can finish before and crash.
|
||||
RsMutex mInitMtx;
|
||||
|
||||
/// True if thread is stopped, false otherwise
|
||||
std::atomic<bool> mHasStopped;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user