From 2e91837f6abff8ee01bab934c47ea7854b2378c8 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Thu, 27 Jul 2023 19:46:04 +0100 Subject: [PATCH] Update thread.cpp fix linux thread tests. --- Engine/source/platformSDL/threads/thread.cpp | 40 ++++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/Engine/source/platformSDL/threads/thread.cpp b/Engine/source/platformSDL/threads/thread.cpp index bef141c8a..ec3dbbd2f 100644 --- a/Engine/source/platformSDL/threads/thread.cpp +++ b/Engine/source/platformSDL/threads/thread.cpp @@ -23,6 +23,7 @@ #include "platform/threads/thread.h" #include "platform/threads/semaphore.h" #include "platform/threads/mutex.h" +#include "platform/platformIntrinsics.h" #include #include #include @@ -30,13 +31,23 @@ class PlatformThreadData { public: - ThreadRunFunction mRunFunc = NULL; - void* mRunArg = NULL; - Thread* mThread = NULL; - Semaphore mGateway; // default count is 1 - SDL_threadID mThreadID = 0; - SDL_Thread* mSdlThread = NULL; - bool mDead = true; + ThreadRunFunction mRunFunc; + void* mRunArg; + Thread* mThread; + Semaphore mGateway; + SDL_threadID mThreadID; + SDL_Thread* mSdlThread; + U32 mDead; + + PlatformThreadData() + { + mRunFunc = NULL; + mRunArg = 0; + mThread = 0; + mThreadID = 0; + mSdlThread = NULL; + mDead = false; + } }; ThreadManager::MainThreadId ThreadManager::smMainThreadId; @@ -50,22 +61,19 @@ ThreadManager::MainThreadId ThreadManager::smMainThreadId; static int ThreadRunHandler(void * arg) { PlatformThreadData *mData = reinterpret_cast(arg); - Thread *thread = mData->mThread; - mData->mThreadID = SDL_ThreadID(); - ThreadManager::addThread(thread); - thread->run(mData->mRunArg); - ThreadManager::removeThread(thread); + ThreadManager::addThread(mData->mThread); + mData->mThread->run(mData->mRunArg); + ThreadManager::removeThread(mData->mThread); - bool autoDelete = thread->autoDelete; + bool autoDelete = mData->mThread->autoDelete; - mData->mThreadID = 0; - mData->mDead = true; + dCompareAndSwap(mData->mDead, false, true); mData->mGateway.release(); if( autoDelete ) - delete thread; + delete mData->mThread; return 0; }