Skip to content
Snippets Groups Projects
Commit 9adf357e authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

Bonk the threads

parent dd157ebb
No related branches found
No related tags found
2 merge requests!3Update to main branch,!2Rebase onto current main branch
...@@ -146,10 +146,8 @@ void LLThread::threadRun() ...@@ -146,10 +146,8 @@ void LLThread::threadRun()
#endif #endif
LL_PROFILER_SET_THREAD_NAME( mName.c_str() ); LL_PROFILER_SET_THREAD_NAME( mName.c_str() );
#ifndef LL_RELEASE_FOR_DOWNLOAD
// for now, hard code all LLThreads to report to single master thread recorder, which is known to be running on main thread // for now, hard code all LLThreads to report to single master thread recorder, which is known to be running on main thread
mRecorder = new LLTrace::ThreadRecorder(*LLTrace::get_master_thread_recorder()); mRecorder = std::make_unique<LLTrace::ThreadRecorder>(*LLTrace::get_master_thread_recorder());
#endif
// Run the user supplied function // Run the user supplied function
do do
...@@ -176,10 +174,7 @@ void LLThread::threadRun() ...@@ -176,10 +174,7 @@ void LLThread::threadRun()
//LL_INFOS() << "LLThread::staticRun() Exiting: " << threadp->mName << LL_ENDL; //LL_INFOS() << "LLThread::staticRun() Exiting: " << threadp->mName << LL_ENDL;
#ifndef LL_RELEASE_FOR_DOWNLOAD mRecorder.reset();
delete mRecorder;
mRecorder = NULL;
#endif
// We're done with the run function, this thread is done executing now. // We're done with the run function, this thread is done executing now.
//NB: we are using this flag to sync across threads...we really need memory barriers here //NB: we are using this flag to sync across threads...we really need memory barriers here
...@@ -192,9 +187,6 @@ LLThread::LLThread(const std::string& name, apr_pool_t *poolp) : ...@@ -192,9 +187,6 @@ LLThread::LLThread(const std::string& name, apr_pool_t *poolp) :
mPaused(FALSE), mPaused(FALSE),
mName(name), mName(name),
mStatus(STOPPED) mStatus(STOPPED)
#ifndef LL_RELEASE_FOR_DOWNLOAD
, mRecorder(NULL)
#endif
{ {
mRunCondition = std::make_unique<LLCondition>(); mRunCondition = std::make_unique<LLCondition>();
mDataLock = std::make_unique<LLMutex>(); mDataLock = std::make_unique<LLMutex>();
...@@ -254,25 +246,33 @@ void LLThread::shutdown() ...@@ -254,25 +246,33 @@ void LLThread::shutdown()
} }
} }
if(mThreadp->joinable()) if (!isStopped())
{ {
mThreadp->join(); // This thread just wouldn't stop, even though we gave it time
LL_INFOS() << "Successfully joined thread: " << mName << LL_ENDL; LL_WARNS() << "LLThread::~LLThread() exiting thread: " << mName << " before clean exit!" << LL_ENDL;
// Put a stake in its heart. (A very hostile method to force a thread to quit)
#if LL_WINDOWS
TerminateThread(mNativeHandle, 0);
#else
pthread_cancel(mNativeHandle);
#endif
mRecorder.reset();
mStatus = STOPPED;
return;
} }
} }
mThreadp.reset(); mThreadp.reset();
mRunCondition.reset(); mRunCondition.reset();
mDataLock.reset(); mDataLock.reset();
#ifndef LL_RELEASE_FOR_DOWNLOAD
if (mRecorder) if (mRecorder)
{ {
// missed chance to properly shut down recorder (needs to be done in thread context) // missed chance to properly shut down recorder (needs to be done in thread context)
// probably due to abnormal thread termination // probably due to abnormal thread termination
// so just leak it and remove it from parent // so just leak it and remove it from parent
LLTrace::get_master_thread_recorder()->removeChildRecorder(mRecorder); LLTrace::get_master_thread_recorder()->removeChildRecorder(mRecorder.get());
} }
#endif
} }
void LLThread::start() void LLThread::start()
...@@ -281,6 +281,8 @@ void LLThread::start() ...@@ -281,6 +281,8 @@ void LLThread::start()
try try
{ {
mThreadp = std::make_unique<std::thread>(std::bind(&LLThread::threadRun, this)); mThreadp = std::make_unique<std::thread>(std::bind(&LLThread::threadRun, this));
mNativeHandle = mThreadp->native_handle();
mThreadp->detach();
} }
catch (const std::system_error& err) catch (const std::system_error& err)
{ {
...@@ -302,7 +304,7 @@ LLThread::id_t LLThread::getID() const ...@@ -302,7 +304,7 @@ LLThread::id_t LLThread::getID() const
bool LLThread::setPriority(EThreadPriority thread_priority) bool LLThread::setPriority(EThreadPriority thread_priority)
{ {
if(!mThreadp) return false; if(!mThreadp) return false;
#if LL_WINDOWS #if 0
int thread_prio = 0; int thread_prio = 0;
switch (thread_priority) switch (thread_priority)
{ {
......
...@@ -108,9 +108,8 @@ class LL_COMMON_API LLThread ...@@ -108,9 +108,8 @@ class LL_COMMON_API LLThread
std::unique_ptr<LLMutex> mDataLock; std::unique_ptr<LLMutex> mDataLock;
std::unique_ptr<std::thread> mThreadp; std::unique_ptr<std::thread> mThreadp;
std::atomic_int mStatus; std::atomic_int mStatus;
#ifndef LL_RELEASE_FOR_DOWNLOAD std::thread::native_handle_type mNativeHandle;
LLTrace::ThreadRecorder* mRecorder; std::unique_ptr<LLTrace::ThreadRecorder> mRecorder;
#endif
//a local apr_pool for APRFile operations in this thread. If it exists, LLAPRFile::sAPRFilePoolp should not be used. //a local apr_pool for APRFile operations in this thread. If it exists, LLAPRFile::sAPRFilePoolp should not be used.
//Note: this pool is used by APRFile ONLY, do NOT use it for any other purposes. //Note: this pool is used by APRFile ONLY, do NOT use it for any other purposes.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment