mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04: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,
|
mIntegrityCheck = new RsGxsIntegrityCheck( mDataStore, this,
|
||||||
*mSerialiser, mGixs);
|
*mSerialiser, mGixs);
|
||||||
mIntegrityCheck->start("gxs integrity");
|
std::string thisName = typeid(*this).name();
|
||||||
mChecking = true;
|
mChecking = mIntegrityCheck->start("gxs IC4 "+thisName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mIntegrityCheck->isDone())
|
if(mIntegrityCheck->isDone() || !mChecking)
|
||||||
{
|
{
|
||||||
std::vector<RsGxsGroupId> grpIds;
|
std::vector<RsGxsGroupId> grpIds;
|
||||||
GxsMsgReq msgIds;
|
GxsMsgReq msgIds;
|
||||||
|
@ -92,11 +92,11 @@ void RsThread::resetTid()
|
|||||||
#ifdef WINDOWS_SYS
|
#ifdef WINDOWS_SYS
|
||||||
memset (&mTid, 0, sizeof(mTid));
|
memset (&mTid, 0, sizeof(mTid));
|
||||||
#else
|
#else
|
||||||
mTid = 0;
|
mTid = pthread_t(); //Thread identifiers should be considered opaque and can be null.
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
RsThread::RsThread() : mHasStopped(true), mShouldStop(false), mLastTid()
|
RsThread::RsThread() : mInitMtx("RsThread"), mHasStopped(true), mShouldStop(false), mLastTid()
|
||||||
#ifdef RS_THREAD_FORCE_STOP
|
#ifdef RS_THREAD_FORCE_STOP
|
||||||
, mStopTimeout(0)
|
, mStopTimeout(0)
|
||||||
#endif
|
#endif
|
||||||
@ -115,6 +115,7 @@ void RsThread::askForStop()
|
|||||||
|
|
||||||
void RsThread::wrapRun()
|
void RsThread::wrapRun()
|
||||||
{
|
{
|
||||||
|
{RS_STACK_MUTEX(mInitMtx);} // Waiting Init done.
|
||||||
run();
|
run();
|
||||||
resetTid();
|
resetTid();
|
||||||
mHasStopped = true;
|
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
|
// Atomically check if the thread was already started and set it as running
|
||||||
if(mHasStopped.exchange(false))
|
if(mHasStopped.exchange(false))
|
||||||
{
|
{
|
||||||
|
RS_STACK_MUTEX(mInitMtx); // Block thread starting to run
|
||||||
|
|
||||||
mShouldStop = false;
|
mShouldStop = false;
|
||||||
int pError = pthread_create(
|
int pError = pthread_create(
|
||||||
&mTid, nullptr, &rsthread_init, static_cast<void*>(this) );
|
&mTid, nullptr, &rsthread_init, static_cast<void*>(this) );
|
||||||
@ -196,15 +199,6 @@ bool RsThread::start(const std::string& threadName)
|
|||||||
print_stacktrace();
|
print_stacktrace();
|
||||||
return false;
|
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 */
|
/* Store an extra copy of thread id for debugging */
|
||||||
mLastTid = mTid;
|
mLastTid = mTid;
|
||||||
|
@ -261,6 +261,9 @@ private:
|
|||||||
/** Call @see run() setting the appropriate flags around it*/
|
/** Call @see run() setting the appropriate flags around it*/
|
||||||
void wrapRun();
|
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
|
/// True if thread is stopped, false otherwise
|
||||||
std::atomic<bool> mHasStopped;
|
std::atomic<bool> mHasStopped;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user