From 2a9c48d8d3bca634867ab6360af6627da4027ca8 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Tue, 30 Apr 2013 20:19:38 +0200 Subject: [PATCH] Add debug function 'is_single_threaded' Usage: AIThreadID foo(AIThreadID::none); ... llassert(is_single_threaded(foo)); ... llassert(is_single_threaded(foo)); ... etc The first call to is_single_threaded(foo) remembers the thread, and after that it is enforced that any call from anywhere that uses foo is done by the same thread. If AIThreadID::none is omitted then the thread is enforced to the thread that creates the AIThreadID. --- indra/llcommon/aithreadid.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/indra/llcommon/aithreadid.h b/indra/llcommon/aithreadid.h index cc7197b21..6b2c08516 100644 --- a/indra/llcommon/aithreadid.h +++ b/indra/llcommon/aithreadid.h @@ -33,7 +33,7 @@ #include // apr_os_thread_t, apr_os_thread_current(), apr_os_thread_equal(). #include // std::ostream. -#include "llpreprocessor.h" // LL_COMMON_API, LL_COMMON_API_TLS +#include "llpreprocessor.h" // LL_COMMON_API, LL_COMMON_API_TLS, LL_UNLIKELY // Lightweight wrapper around apr_os_thread_t. // This class introduces no extra assembly code after optimization; it's only intend is to provide type-safety. @@ -87,6 +87,16 @@ public: #endif }; +// Debugging function. +inline bool is_single_threaded(AIThreadID& thread_id) +{ + if (LL_UNLIKELY(thread_id.is_no_thread())) + { + thread_id.reset(); + } + return thread_id.equals_current_thread(); +} + // Legacy function. inline bool is_main_thread(void) {