mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-29 00:27:27 -04:00
Merge upstream
This commit is contained in:
commit
2b2a9f9a89
10 changed files with 92 additions and 57 deletions
|
@ -207,15 +207,14 @@ bool ConvertUtf16ToUtf8(const std::wstring& source, std::string& dest)
|
|||
|
||||
bool is_alphanumeric(char c)
|
||||
{
|
||||
return (c>='0' && c<'9') || (c>='a' && c<='z') || (c>='A' && c<='Z') ;
|
||||
return (c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z');
|
||||
}
|
||||
|
||||
bool is_alphanumeric(const std::string& s)
|
||||
{
|
||||
for(uint32_t i=0;i<s.size();++i)
|
||||
if(!is_alphanumeric(s[i]))
|
||||
return false;
|
||||
return true;
|
||||
for( uint32_t i=0; i < s.size(); ++i)
|
||||
if(!is_alphanumeric(s[i])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
} } // librs::util
|
||||
|
|
|
@ -85,7 +85,7 @@ int RS_pthread_setname_np(pthread_t __target_thread, const char *__buf) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
RsThread::RsThread() : mHasStopped(true), mShouldStop(false)
|
||||
void RsThread::resetTid()
|
||||
{
|
||||
#ifdef WINDOWS_SYS
|
||||
memset (&mTid, 0, sizeof(mTid));
|
||||
|
@ -94,6 +94,9 @@ RsThread::RsThread() : mHasStopped(true), mShouldStop(false)
|
|||
#endif
|
||||
}
|
||||
|
||||
RsThread::RsThread() : mHasStopped(true), mShouldStop(false), mLastTid()
|
||||
{ resetTid(); }
|
||||
|
||||
bool RsThread::isRunning() { return !mHasStopped; }
|
||||
|
||||
bool RsThread::shouldStop() { return mShouldStop; }
|
||||
|
@ -102,13 +105,13 @@ void RsThread::askForStop()
|
|||
{
|
||||
/* Call onStopRequested() only once even if askForStop() is called multiple
|
||||
* times */
|
||||
if(!mShouldStop.exchange(true))
|
||||
RsThread::async([&](){ onStopRequested(); });
|
||||
if(!mShouldStop.exchange(true)) onStopRequested();
|
||||
}
|
||||
|
||||
void RsThread::wrapRun()
|
||||
{
|
||||
run();
|
||||
resetTid();
|
||||
mHasStopped = true;
|
||||
}
|
||||
|
||||
|
@ -122,7 +125,8 @@ void RsThread::fullstop()
|
|||
RsErr() << __PRETTY_FUNCTION__ << " called by same thread. This should "
|
||||
<< "never happen! this: " << static_cast<void*>(this)
|
||||
<< std::hex << ", callerTid: " << callerTid
|
||||
<< ", mTid: " << mTid << std::dec << std::endl;
|
||||
<< ", mTid: " << mTid << std::dec
|
||||
<< ", mFullName: " << mFullName << std::endl;
|
||||
print_stacktrace();
|
||||
return;
|
||||
}
|
||||
|
@ -134,9 +138,9 @@ void RsThread::fullstop()
|
|||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
++i;
|
||||
if(!(i%5))
|
||||
RsInfo() << __PRETTY_FUNCTION__ << " " << i*0.2 << " seconds passed"
|
||||
<< " waiting for thread: " << mTid << " " << mFullName
|
||||
<< " to stop" << std::endl;
|
||||
RsDbg() << __PRETTY_FUNCTION__ << " " << i*0.2 << " seconds passed"
|
||||
<< " waiting for thread: " << std::hex << mLastTid
|
||||
<< std::dec << " " << mFullName << " to stop" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,6 +162,9 @@ bool RsThread::start(const std::string& threadName)
|
|||
return false;
|
||||
}
|
||||
|
||||
/* Store an extra copy of thread id for debugging */
|
||||
mLastTid = mTid;
|
||||
|
||||
/* Store thread full name as PThread is not able to keep it entirely */
|
||||
mFullName = threadName;
|
||||
|
||||
|
@ -266,10 +273,10 @@ double RsStackMutex::getCurrentTS()
|
|||
|
||||
RsThread::~RsThread()
|
||||
{
|
||||
if(isRunning())
|
||||
if(!mHasStopped)
|
||||
{
|
||||
RsErr() << __PRETTY_FUNCTION__ << " deleting thread: " << mTid << " "
|
||||
<< mFullName << " that is still "
|
||||
RsErr() << __PRETTY_FUNCTION__ << " deleting thread: " << mLastTid
|
||||
<< " " << mFullName << " that is still "
|
||||
<< "running! Something seems very wrong here and RetroShare is "
|
||||
<< "likely to crash because of this." << std::endl;
|
||||
print_stacktrace();
|
||||
|
|
|
@ -264,9 +264,19 @@ private:
|
|||
|
||||
/// Store the id of the corresponding pthread
|
||||
pthread_t mTid;
|
||||
void resetTid();
|
||||
|
||||
/// Store thread full name
|
||||
/** Store thread full name for debugging because PThread is limited to 15
|
||||
* char thread names */
|
||||
std::string mFullName;
|
||||
|
||||
/** Store a copy of thread id which is never reset to 0 after initialization
|
||||
* due to RsThread functioning. After RsThread initialization this member is
|
||||
* only re-written with a new tread id in start(...).
|
||||
* This is useful for debugging because mTid is reset at the end of wrapRun
|
||||
* and that might happens concurrently (or just before) a debug message
|
||||
* being printed, thus causing the debug message to print a mangled value.*/
|
||||
pthread_t mLastTid;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue