diff --git a/stepmania/src/archutils/Darwin/DarwinThreadHelpers.cpp b/stepmania/src/archutils/Darwin/DarwinThreadHelpers.cpp index cb04665cf9..6c7529b2e8 100644 --- a/stepmania/src/archutils/Darwin/DarwinThreadHelpers.cpp +++ b/stepmania/src/archutils/Darwin/DarwinThreadHelpers.cpp @@ -1,16 +1,18 @@ #include #include #include +#include #include "Backtrace.h" +#include "RageLog.h" -bool SuspendThread(uint64_t threadHandle) +bool SuspendThread( uint64_t threadHandle ) { - return !thread_suspend(thread_act_t(threadHandle)); + return !thread_suspend( thread_act_t(threadHandle) ); } -bool ResumeThread(uint64_t threadHandle) +bool ResumeThread( uint64_t threadHandle ) { - return !thread_resume(thread_act_t(threadHandle)); + return !thread_resume( thread_act_t(threadHandle) ); } uint64_t GetCurrentThreadId() @@ -18,27 +20,37 @@ uint64_t GetCurrentThreadId() return mach_thread_self(); } -bool GetThreadBacktraceContext(uint64_t iID, BacktraceContext *ctx) +bool GetThreadBacktraceContext( uint64_t iID, BacktraceContext *ctx ) { /* Can't GetThreadBacktraceContext the current thread. */ ASSERT(iID != GetCurrentThreadId()); SuspendThread( iID ); - thread_act_t thread = thread_act_t(iID); + thread_act_t thread = thread_act_t( iID ); ppc_thread_state state; mach_msg_type_number_t count = PPC_THREAD_STATE_COUNT; - if (thread_get_state(thread, PPC_THREAD_STATE, thread_state_t(&state), - &count)) + if( thread_get_state(thread, PPC_THREAD_STATE, thread_state_t(&state), &count) ) return false; ctx->FramePtr = (void *)state.r1; ctx->PC = (void *)state.srr0; return true; } + +void SetThreadPrecedence( int prec ) +{ + thread_precedence_policy po = { prec }; + kern_return_t ret = thread_policy_set( mach_thread_self(), THREAD_PRECEDENCE_POLICY, + (int *)&po, THREAD_PRECEDENCE_POLICY_COUNT ); + + if( ret != KERN_SUCCESS ) + LOG->Warn( "Couldn't set the precedence for the input thread: %s", + mach_error_string(ret) ); +} /* - * (c) 2004 Steve Checkoway + * (c) 2004, 2005 Steve Checkoway * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a diff --git a/stepmania/src/archutils/Darwin/DarwinThreadHelpers.h b/stepmania/src/archutils/Darwin/DarwinThreadHelpers.h index e837254fa6..7b82bd393c 100644 --- a/stepmania/src/archutils/Darwin/DarwinThreadHelpers.h +++ b/stepmania/src/archutils/Darwin/DarwinThreadHelpers.h @@ -1,14 +1,15 @@ #ifndef DARWIN_THREAD_HELPERS_H #define DARWIN_THREAD_HELPERS_H -bool SuspendThread(uint64_t threadHandle); -bool ResumeThread(uint64_t threadHandle); +bool SuspendThread( uint64_t threadHandle ); +bool ResumeThread( uint64_t threadHandle ); uint64_t GetCurrentThreadId(); +void SetThreadPrecedence( int prec ); #endif /* - * (c) 2004 Steve Checkoway + * (c) 2004, 2005 Steve Checkoway * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a