Skip to content
Snippets Groups Projects
Commit 7a09a539 authored by Nat Goodspeed's avatar Nat Goodspeed
Browse files

DRTVWR-494: Add on_main_thread(), sibling to assert_main_thread().

parent b22f89c9
No related branches found
No related tags found
No related merge requests found
...@@ -97,14 +97,34 @@ U32 LL_THREAD_LOCAL sThreadID = 0; ...@@ -97,14 +97,34 @@ U32 LL_THREAD_LOCAL sThreadID = 0;
U32 LLThread::sIDIter = 0; U32 LLThread::sIDIter = 0;
namespace
{
U32 main_thread()
{
// Using a function-static variable to identify the main thread
// requires that control reach here from the main thread before it
// reaches here from any other thread. We simply trust that whichever
// thread gets here first is the main thread.
static U32 s_thread_id = LLThread::currentID();
return s_thread_id;
}
} // anonymous namespace
LL_COMMON_API bool on_main_thread()
{
return (LLThread::currentID() == main_thread());
}
LL_COMMON_API void assert_main_thread() LL_COMMON_API void assert_main_thread()
{ {
static U32 s_thread_id = LLThread::currentID(); auto curr = LLThread::currentID();
if (LLThread::currentID() != s_thread_id) auto main = main_thread();
if (curr != main)
{ {
LL_WARNS() << "Illegal execution from thread id " << (S32) LLThread::currentID() LL_WARNS() << "Illegal execution from thread id " << curr
<< " outside main thread " << (S32) s_thread_id << LL_ENDL; << " outside main thread " << main << LL_ENDL;
} }
} }
......
...@@ -34,8 +34,6 @@ ...@@ -34,8 +34,6 @@
#include "llrefcount.h" #include "llrefcount.h"
#include <thread> #include <thread>
LL_COMMON_API void assert_main_thread();
namespace LLTrace namespace LLTrace
{ {
class ThreadRecorder; class ThreadRecorder;
...@@ -168,5 +166,6 @@ class LL_COMMON_API LLResponder : public LLThreadSafeRefCount ...@@ -168,5 +166,6 @@ class LL_COMMON_API LLResponder : public LLThreadSafeRefCount
//============================================================================ //============================================================================
extern LL_COMMON_API void assert_main_thread(); extern LL_COMMON_API void assert_main_thread();
extern LL_COMMON_API bool on_main_thread();
#endif // LL_LLTHREAD_H #endif // LL_LLTHREAD_H
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