Update thread ids for 64bit support.

This commit is contained in:
Jeff Hutchinson 2021-08-29 20:34:57 -04:00
parent 0287f7717b
commit 633bc040d0
5 changed files with 26 additions and 26 deletions

View file

@ -110,7 +110,7 @@ public:
bool isAlive(); bool isAlive();
/// Returns the platform specific thread id for this thread. /// Returns the platform specific thread id for this thread.
U32 getId(); dsize_t getId();
}; };
@ -122,12 +122,12 @@ class ThreadManager
struct MainThreadId struct MainThreadId
{ {
U32 mId; dsize_t mId;
MainThreadId() MainThreadId()
{ {
mId = ThreadManager::getCurrentThreadId(); mId = ThreadManager::getCurrentThreadId();
} }
U32 get() dsize_t get()
{ {
// Okay, this is a bit soso. The main thread ID may get queried during // Okay, this is a bit soso. The main thread ID may get queried during
// global ctor phase before MainThreadId's ctor ran. Since global // global ctor phase before MainThreadId's ctor ran. Since global
@ -152,21 +152,21 @@ public:
static bool isMainThread(); static bool isMainThread();
/// Returns true if threadId is the same as the calling thread's id. /// Returns true if threadId is the same as the calling thread's id.
static bool isCurrentThread(U32 threadId); static bool isCurrentThread(dsize_t threadId);
/// Returns true if the 2 thread ids represent the same thread. Some thread /// Returns true if the 2 thread ids represent the same thread. Some thread
/// APIs return an opaque object as a thread id, so the == operator cannot /// APIs return an opaque object as a thread id, so the == operator cannot
/// reliably compare thread ids. /// reliably compare thread ids.
// this comparator is needed by pthreads and ThreadManager. // this comparator is needed by pthreads and ThreadManager.
static bool compare(U32 threadId_1, U32 threadId_2); static bool compare(dsize_t threadId_1, dsize_t threadId_2);
/// Returns the platform specific thread id of the calling thread. Some /// Returns the platform specific thread id of the calling thread. Some
/// platforms do not guarantee that this ID stays the same over the life of /// platforms do not guarantee that this ID stays the same over the life of
/// the thread, so use ThreadManager::compare() to compare thread ids. /// the thread, so use ThreadManager::compare() to compare thread ids.
static U32 getCurrentThreadId(); static dsize_t getCurrentThreadId();
/// Returns the platform specific thread id ot the main thread. /// Returns the platform specific thread id ot the main thread.
static U32 getMainThreadId() { return smMainThreadId.get(); } static dsize_t getMainThreadId() { return smMainThreadId.get(); }
/// Each thread should add itself to the thread pool the first time it runs. /// Each thread should add itself to the thread pool the first time it runs.
static void addThread(Thread* thread) static void addThread(Thread* thread)
@ -184,7 +184,7 @@ public:
ThreadManager &manager = *ManagedSingleton< ThreadManager >::instance(); ThreadManager &manager = *ManagedSingleton< ThreadManager >::instance();
manager.poolLock.lock(); manager.poolLock.lock();
U32 threadID = thread->getId(); dsize_t threadID = thread->getId();
for(U32 i = 0;i < manager.threadPool.size();++i) for(U32 i = 0;i < manager.threadPool.size();++i)
{ {
if( compare( manager.threadPool[i]->getId(), threadID ) ) if( compare( manager.threadPool[i]->getId(), threadID ) )
@ -199,7 +199,7 @@ public:
/// Searches the pool of known threads for a thread whose id is equivalent to /// Searches the pool of known threads for a thread whose id is equivalent to
/// the given threadid. Compares thread ids with ThreadManager::compare(). /// the given threadid. Compares thread ids with ThreadManager::compare().
static Thread* getThreadById(U32 threadid) static Thread* getThreadById(dsize_t threadid)
{ {
AssertFatal(threadid != 0, "ThreadManager::getThreadById() Searching for a bad thread id."); AssertFatal(threadid != 0, "ThreadManager::getThreadById() Searching for a bad thread id.");
Thread* ret = NULL; Thread* ret = NULL;
@ -236,9 +236,9 @@ inline bool ThreadManager::isMainThread()
return compare( ThreadManager::getCurrentThreadId(), smMainThreadId.get() ); return compare( ThreadManager::getCurrentThreadId(), smMainThreadId.get() );
} }
inline bool ThreadManager::isCurrentThread(U32 threadId) inline bool ThreadManager::isCurrentThread(dsize_t threadId)
{ {
U32 current = getCurrentThreadId(); dsize_t current = getCurrentThreadId();
return compare(current, threadId); return compare(current, threadId);
} }

View file

@ -134,9 +134,9 @@ bool Thread::isAlive()
return ( !mData->mDead ); return ( !mData->mDead );
} }
U32 Thread::getId() dsize_t Thread::getId()
{ {
return (U32)mData->mThreadID; return (dsize_t)mData->mThreadID;
} }
void Thread::_setName( const char* ) void Thread::_setName( const char* )
@ -145,12 +145,12 @@ void Thread::_setName( const char* )
// that one thread you are looking for is just so much fun. // that one thread you are looking for is just so much fun.
} }
U32 ThreadManager::getCurrentThreadId() dsize_t ThreadManager::getCurrentThreadId()
{ {
return (U32)SDL_ThreadID(); return (dsize_t)SDL_ThreadID();
} }
bool ThreadManager::compare(U32 threadId_1, U32 threadId_2) bool ThreadManager::compare(dsize_t threadId_1, dsize_t threadId_2)
{ {
return (threadId_1 == threadId_2); return (threadId_1 == threadId_2);
} }

View file

@ -43,7 +43,7 @@ public:
Thread* mThread; Thread* mThread;
HANDLE mThreadHnd; HANDLE mThreadHnd;
Semaphore mGateway; Semaphore mGateway;
U32 mThreadID; dsize_t mThreadID;
U32 mDead; U32 mDead;
PlatformThreadData() PlatformThreadData()
@ -157,7 +157,7 @@ bool Thread::isAlive()
return ( !mData->mDead ); return ( !mData->mDead );
} }
U32 Thread::getId() dsize_t Thread::getId()
{ {
return mData->mThreadID; return mData->mThreadID;
} }
@ -197,12 +197,12 @@ void Thread::_setName( const char* name )
#endif #endif
} }
U32 ThreadManager::getCurrentThreadId() dsize_t ThreadManager::getCurrentThreadId()
{ {
return GetCurrentThreadId(); return GetCurrentThreadId();
} }
bool ThreadManager::compare(U32 threadId_1, U32 threadId_2) bool ThreadManager::compare(dsize_t threadId_1, dsize_t threadId_2)
{ {
return (threadId_1 == threadId_2); return (threadId_1 == threadId_2);
} }

View file

@ -137,9 +137,9 @@ bool Thread::isAlive()
return ( !mData->mDead ); return ( !mData->mDead );
} }
U32 Thread::getId() dsize_t Thread::getId()
{ {
return (U32)mData->mThreadID; return (dsize_t)mData->mThreadID;
} }
void Thread::_setName( const char* ) void Thread::_setName( const char* )
@ -148,12 +148,12 @@ void Thread::_setName( const char* )
// that one thread you are looking for is just so much fun. // that one thread you are looking for is just so much fun.
} }
U32 ThreadManager::getCurrentThreadId() dsize_t ThreadManager::getCurrentThreadId()
{ {
return (U32)pthread_self(); return (dsize_t)pthread_self();
} }
bool ThreadManager::compare(U32 threadId_1, U32 threadId_2) bool ThreadManager::compare(dsize_t threadId_1, dsize_t threadId_2)
{ {
return pthread_equal((pthread_t)threadId_1, (pthread_t)threadId_2); return pthread_equal((pthread_t)threadId_1, (pthread_t)threadId_2);
} }

View file

@ -442,7 +442,7 @@ inline bool isSFXThread()
{ {
ThreadSafeRef< SFXUpdateThread > sfxThread = UPDATE_THREAD(); ThreadSafeRef< SFXUpdateThread > sfxThread = UPDATE_THREAD();
U32 threadId; dsize_t threadId;
if( sfxThread != NULL ) if( sfxThread != NULL )
threadId = sfxThread->getId(); threadId = sfxThread->getId();
else else