Add a function to test whether the current thread is the main thread.
This commit is contained in:
@@ -63,6 +63,7 @@
|
|||||||
#include "subsidy_func.h"
|
#include "subsidy_func.h"
|
||||||
#include "gfx_layout.h"
|
#include "gfx_layout.h"
|
||||||
#include "viewport_sprite_sorter.h"
|
#include "viewport_sprite_sorter.h"
|
||||||
|
#include "thread/thread.h"
|
||||||
|
|
||||||
#include "linkgraph/linkgraphschedule.h"
|
#include "linkgraph/linkgraphschedule.h"
|
||||||
|
|
||||||
@@ -553,6 +554,7 @@ static const OptionData _options[] = {
|
|||||||
*/
|
*/
|
||||||
int openttd_main(int argc, char *argv[])
|
int openttd_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
SetSelfAsMainThread();
|
||||||
char *musicdriver = NULL;
|
char *musicdriver = NULL;
|
||||||
char *sounddriver = NULL;
|
char *sounddriver = NULL;
|
||||||
char *videodriver = NULL;
|
char *videodriver = NULL;
|
||||||
|
@@ -122,4 +122,14 @@ private:
|
|||||||
*/
|
*/
|
||||||
uint GetCPUCoreCount();
|
uint GetCPUCoreCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the current thread as the "main" thread
|
||||||
|
*/
|
||||||
|
void SetSelfAsMainThread();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the current thread definitely the "main" thread. If in doubt returns false.
|
||||||
|
*/
|
||||||
|
bool IsMainThread();
|
||||||
|
|
||||||
#endif /* THREAD_H */
|
#endif /* THREAD_H */
|
||||||
|
@@ -199,3 +199,7 @@ private:
|
|||||||
if (thread != NULL) *thread = to;
|
if (thread != NULL) *thread = to;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetSelfAsMainThread() { }
|
||||||
|
|
||||||
|
bool IsMainThread() { return false; }
|
||||||
|
@@ -33,3 +33,7 @@ public:
|
|||||||
{
|
{
|
||||||
return new ThreadMutex_None();
|
return new ThreadMutex_None();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetSelfAsMainThread() { }
|
||||||
|
|
||||||
|
bool IsMainThread() { return true; }
|
||||||
|
@@ -145,3 +145,7 @@ public:
|
|||||||
{
|
{
|
||||||
return new ThreadMutex_OS2();
|
return new ThreadMutex_OS2();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetSelfAsMainThread() { }
|
||||||
|
|
||||||
|
bool IsMainThread() { return false; }
|
||||||
|
@@ -172,3 +172,15 @@ public:
|
|||||||
{
|
{
|
||||||
return new ThreadMutex_pthread();
|
return new ThreadMutex_pthread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static pthread_t main_thread;
|
||||||
|
|
||||||
|
void SetSelfAsMainThread()
|
||||||
|
{
|
||||||
|
main_thread = pthread_self();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsMainThread()
|
||||||
|
{
|
||||||
|
return main_thread == pthread_self();
|
||||||
|
}
|
||||||
|
@@ -158,3 +158,15 @@ public:
|
|||||||
{
|
{
|
||||||
return new ThreadMutex_Win32();
|
return new ThreadMutex_Win32();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint main_thread_id;
|
||||||
|
|
||||||
|
void SetSelfAsMainThread()
|
||||||
|
{
|
||||||
|
main_thread_id = GetCurrentThreadId();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsMainThread()
|
||||||
|
{
|
||||||
|
return main_thread_id == GetCurrentThreadId();
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user