Ver Fonte

Update thread.cpp

fix linux thread tests.
marauder2k7 há 2 anos atrás
pai
commit
2e91837f6a
1 ficheiros alterados com 24 adições e 16 exclusões
  1. 24 16
      Engine/source/platformSDL/threads/thread.cpp

+ 24 - 16
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 <stdlib.h>
 #include <SDL.h>
 #include <SDL_thread.h>
@@ -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<PlatformThreadData*>(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;
 }