Add method to get whether current thread is non-main

This commit is contained in:
Jonathan G Rennison
2018-08-26 22:13:20 +01:00
parent dde88887ae
commit 79644493c9
6 changed files with 19 additions and 0 deletions

View File

@@ -133,6 +133,11 @@ void SetSelfAsMainThread();
*/
bool IsMainThread();
/**
* @return true if the current thread definitely a "non-main" thread. If in doubt returns false.
*/
bool IsNonMainThread();
/**
* Get the name of the current thread, if any.
* @param str The start of the buffer.

View File

@@ -199,5 +199,6 @@ private:
void SetSelfAsMainThread() { }
bool IsMainThread() { return false; }
bool IsNonMainThread() { return false; }
int GetThreadName(char *str, const char *last) { return 0; }

View File

@@ -37,5 +37,6 @@ public:
void SetSelfAsMainThread() { }
bool IsMainThread() { return true; }
bool IsNonMainThread() { return false; }
int GetThreadName(char *str, const char *last) { return 0; }

View File

@@ -150,4 +150,6 @@ void SetSelfAsMainThread() { }
bool IsMainThread() { return false; }
bool IsNonMainThread() { return false; }
int GetThreadName(char *str, const char *last) { return 0; }

View File

@@ -203,6 +203,11 @@ bool IsMainThread()
return main_thread == pthread_self();
}
bool IsNonMainThread()
{
return main_thread != pthread_self();
}
int GetThreadName(char *str, const char *last)
{
#if defined(__GLIBC__)

View File

@@ -185,6 +185,11 @@ bool IsMainThread()
return main_thread_id == GetCurrentThreadId();
}
bool IsNonMainThread()
{
return main_thread_id != GetCurrentThreadId();
}
static std::map<uint, std::string> _thread_name_map;
static ThreadMutex_Win32 _thread_name_map_mutex;