Update thread.cpp

fix linux thread tests.
This commit is contained in:
marauder2k7 2023-07-27 19:46:04 +01:00
parent 7c37b38f03
commit 2e91837f6a

View file

@ -23,6 +23,7 @@
#include "platform/threads/thread.h" #include "platform/threads/thread.h"
#include "platform/threads/semaphore.h" #include "platform/threads/semaphore.h"
#include "platform/threads/mutex.h" #include "platform/threads/mutex.h"
#include "platform/platformIntrinsics.h"
#include <stdlib.h> #include <stdlib.h>
#include <SDL.h> #include <SDL.h>
#include <SDL_thread.h> #include <SDL_thread.h>
@ -30,13 +31,23 @@
class PlatformThreadData class PlatformThreadData
{ {
public: public:
ThreadRunFunction mRunFunc = NULL; ThreadRunFunction mRunFunc;
void* mRunArg = NULL; void* mRunArg;
Thread* mThread = NULL; Thread* mThread;
Semaphore mGateway; // default count is 1 Semaphore mGateway;
SDL_threadID mThreadID = 0; SDL_threadID mThreadID;
SDL_Thread* mSdlThread = NULL; SDL_Thread* mSdlThread;
bool mDead = true; U32 mDead;
PlatformThreadData()
{
mRunFunc = NULL;
mRunArg = 0;
mThread = 0;
mThreadID = 0;
mSdlThread = NULL;
mDead = false;
}
}; };
ThreadManager::MainThreadId ThreadManager::smMainThreadId; ThreadManager::MainThreadId ThreadManager::smMainThreadId;
@ -50,22 +61,19 @@ ThreadManager::MainThreadId ThreadManager::smMainThreadId;
static int ThreadRunHandler(void * arg) static int ThreadRunHandler(void * arg)
{ {
PlatformThreadData *mData = reinterpret_cast<PlatformThreadData*>(arg); PlatformThreadData *mData = reinterpret_cast<PlatformThreadData*>(arg);
Thread *thread = mData->mThread;
mData->mThreadID = SDL_ThreadID(); mData->mThreadID = SDL_ThreadID();
ThreadManager::addThread(thread); ThreadManager::addThread(mData->mThread);
thread->run(mData->mRunArg); mData->mThread->run(mData->mRunArg);
ThreadManager::removeThread(thread); ThreadManager::removeThread(mData->mThread);
bool autoDelete = thread->autoDelete; bool autoDelete = mData->mThread->autoDelete;
mData->mThreadID = 0; dCompareAndSwap(mData->mDead, false, true);
mData->mDead = true;
mData->mGateway.release(); mData->mGateway.release();
if( autoDelete ) if( autoDelete )
delete thread; delete mData->mThread;
return 0; return 0;
} }