From 7e7d68bd94fb0723c5462c08d1f18ec36a5465d7 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 28 Mar 2004 06:04:37 +0000 Subject: [PATCH] implement HaltAllThreads on DARWIN --- stepmania/src/RageThreads.cpp | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/stepmania/src/RageThreads.cpp b/stepmania/src/RageThreads.cpp index 02db79cf28..3c4551f598 100644 --- a/stepmania/src/RageThreads.cpp +++ b/stepmania/src/RageThreads.cpp @@ -40,6 +40,11 @@ #include "archutils/Win32/crash.h" #endif +#if defined(DARWIN) +#include +#include +#endif + /* XXX: char*GetLockedMutexesForThisThread? */ #define MAX_THREADS 128 static vector *g_MutexList = NULL; /* watch out for static initialization order problems */ @@ -66,6 +71,10 @@ struct ThreadSlot HANDLE ThreadHandle; #endif +#if defined(DARWIN) + thread_act_t ThreadHandle; +#endif + #undef CHECKPOINT_COUNT #define CHECKPOINT_COUNT 5 struct ThreadCheckpoint @@ -215,6 +224,10 @@ void ThreadSlot::SetupThisThread() CurProc, GetCurrentThread() ) ); #endif +#if defined(DARWIN) + ThreadHandle = mach_thread_self(); +#endif + threadid = SDL_ThreadID(); sprintf(ThreadFormattedOutput, "Thread %08x (%s)", threadid, name); @@ -319,6 +332,25 @@ int RageThread::Wait() return ret; } +/* XXX: consolidate thread ID type, etc, use ArchHooks */ +#if defined(DARWIN) +thread_act_t GetCurrentThreadId() +{ + return mach_thread_self(); +} + +void SuspendThread( thread_act_t t ) +{ + thread_suspend( t ); +} + +void ResumeThread( thread_act_t t ) +{ + thread_resume( t ); +} +#endif + + void RageThread::HaltAllThreads( bool Kill ) { #if defined(PID_BASED_THREADS) @@ -354,6 +386,18 @@ void RageThread::HaltAllThreads( bool Kill ) #endif SuspendThread( g_ThreadSlots[entry].ThreadHandle ); } +#elif defined(DARWIN) + const thread_act_t ThisThreadID = GetCurrentThreadId(); + for( int entry = 0; entry < MAX_THREADS; ++entry ) + { + if( !g_ThreadSlots[entry].used ) + continue; + if( g_ThreadSlots[entry].threadid == UnknownThreadID ) + continue; + if( ThisThreadID == g_ThreadSlots[entry].ThreadHandle ) + continue; + SuspendThread( g_ThreadSlots[entry].ThreadHandle ); + } #endif } @@ -382,6 +426,16 @@ void RageThread::ResumeAllThreads() ResumeThread( g_ThreadSlots[entry].ThreadHandle ); } +#elif defined(DARWIN) + const thread_act_t ThisThreadID = GetCurrentThreadId(); + for( int entry = 0; entry < MAX_THREADS; ++entry ) + { + if( !g_ThreadSlots[entry].used ) + continue; + if( ThisThreadID == g_ThreadSlots[entry].threadid ) + continue; + ResumeThread( g_ThreadSlots[entry].ThreadHandle ); + } #endif }