|
|
|
@ -14,13 +14,6 @@ namespace ThreadUtil { |
|
|
|
|
static std::condition_variable g_queueCondition; |
|
|
|
|
static bool g_initialized = false; |
|
|
|
|
static HANDLE g_workerThread = NULL; |
|
|
|
|
|
|
|
|
|
// Function to initialize the platform thread ID
|
|
|
|
|
void InitializePlatformThreadId() { |
|
|
|
|
g_platformThreadId = GetCurrentThreadId(); |
|
|
|
|
g_initialized = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Worker thread function
|
|
|
|
|
unsigned __stdcall WorkerThreadProc(void* param) { |
|
|
|
|
while (true) { |
|
|
|
@ -39,6 +32,16 @@ namespace ThreadUtil { |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
// Function to initialize the platform thread ID
|
|
|
|
|
void InitializePlatformThreadId() { |
|
|
|
|
g_platformThreadId = GetCurrentThreadId(); |
|
|
|
|
|
|
|
|
|
// Create worker thread
|
|
|
|
|
g_workerThread = (HANDLE)_beginthreadex(NULL, 0, WorkerThreadProc, NULL, 0, NULL); |
|
|
|
|
g_initialized = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Function to ensure code runs on the platform thread
|
|
|
|
|
void RunOnPlatformThread(std::function<void()> callback) { |
|
|
|
@ -46,8 +49,7 @@ namespace ThreadUtil { |
|
|
|
|
if (!g_initialized) { |
|
|
|
|
InitializePlatformThreadId(); |
|
|
|
|
|
|
|
|
|
// Create worker thread
|
|
|
|
|
g_workerThread = (HANDLE)_beginthreadex(NULL, 0, WorkerThreadProc, NULL, 0, NULL); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// If we're already on the platform thread, execute directly
|
|
|
|
|