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.
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
|
||||
#include <apr_portable.h> // apr_os_thread_t, apr_os_thread_current(), apr_os_thread_equal().
|
||||
#include <iosfwd> // 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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user