summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2019-12-03 11:33:55 -0500
committerNat Goodspeed <nat@lindenlab.com>2020-03-25 15:28:17 -0400
commit7a09a5391ac5172470eb6597f08b24cd5965e9ac (patch)
treecc42f0f2452214ac06d9c9863138045cd2e18311 /indra
parentb22f89c9fa9e6ee95b552b27808df77f710caad6 (diff)
DRTVWR-494: Add on_main_thread(), sibling to assert_main_thread().
Diffstat (limited to 'indra')
-rw-r--r--indra/llcommon/llthread.cpp28
-rw-r--r--indra/llcommon/llthread.h3
2 files changed, 25 insertions, 6 deletions
diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp
index a4171729db..f875e4e0dc 100644
--- a/indra/llcommon/llthread.cpp
+++ b/indra/llcommon/llthread.cpp
@@ -97,14 +97,34 @@ U32 LL_THREAD_LOCAL sThreadID = 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()
{
- static U32 s_thread_id = LLThread::currentID();
- if (LLThread::currentID() != s_thread_id)
+ auto curr = LLThread::currentID();
+ auto main = main_thread();
+ if (curr != main)
{
- LL_WARNS() << "Illegal execution from thread id " << (S32) LLThread::currentID()
- << " outside main thread " << (S32) s_thread_id << LL_ENDL;
+ LL_WARNS() << "Illegal execution from thread id " << curr
+ << " outside main thread " << main << LL_ENDL;
}
}
diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h
index 863c9051f3..37f6e66bbb 100644
--- a/indra/llcommon/llthread.h
+++ b/indra/llcommon/llthread.h
@@ -34,8 +34,6 @@
#include "llrefcount.h"
#include <thread>
-LL_COMMON_API void assert_main_thread();
-
namespace LLTrace
{
class ThreadRecorder;
@@ -168,5 +166,6 @@ public:
//============================================================================
extern LL_COMMON_API void assert_main_thread();
+extern LL_COMMON_API bool on_main_thread();
#endif // LL_LLTHREAD_H