diff --git a/source/src/tools.cpp b/source/src/tools.cpp index 264c4d68..f1c95c76 100644 --- a/source/src/tools.cpp +++ b/source/src/tools.cpp @@ -953,6 +953,10 @@ void sl_detachthread(void *ti) // SDL can't actually detach threads, so this is sem_oldthreads.post(); } } + +static uint32_t mainthreadid = SDL_ThreadID(); +bool ismainthread() { return mainthreadid == SDL_ThreadID(); } + #else struct sl_threadinfo { int (*fn)(void *); void *data; pthread_t handle; int res; volatile char done; }; @@ -997,6 +1001,10 @@ void sl_detachthread(void *ti) sem_oldthreads.post(); } } + +static pthread_t mainthreadid = pthread_self(); +bool ismainthread() { return pthread_equal(mainthreadid, pthread_self()) != 0; } + #endif bool sl_pollthread(void *ti) diff --git a/source/src/tools.h b/source/src/tools.h index 29543fb2..8213f9b2 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -1023,6 +1023,7 @@ extern int sl_waitthread(void *ti); extern bool sl_pollthread(void *ti); extern void sl_detachthread(void *ti); extern void sl_sleep(int duration); +extern bool ismainthread(); #endif