void CAPThread::SetPriority(UInt32 inPriority, bool inFixedPriority) { mPriority = inPriority; mTimeConstraintSet = false; mFixedPriority = inFixedPriority; #if TARGET_OS_MAC if(mPThread != 0) { kern_return_t theError = 0; // set whether or not this is a fixed priority thread if (mFixedPriority) { thread_extended_policy_data_t theFixedPolicy = { false }; theError = thread_policy_set(pthread_mach_thread_np(mPThread), THREAD_EXTENDED_POLICY, (thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT); AssertNoKernelError(theError, "CAPThread::SetPriority: failed to set the fixed-priority policy"); } // set the thread's absolute priority which is relative to the priority on which thread_policy_set() is called UInt32 theCurrentThreadPriority = getScheduledPriority(pthread_self(), CAPTHREAD_SET_PRIORITY); thread_precedence_policy_data_t thePrecedencePolicy = { static_cast<integer_t>(mPriority - theCurrentThreadPriority) }; theError = thread_policy_set(pthread_mach_thread_np(mPThread), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&thePrecedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT); AssertNoKernelError(theError, "CAPThread::SetPriority: failed to set the precedence policy"); #if Log_SetPriority DebugMessageN4("CAPThread::SetPriority: requsted: %lu spawning: %lu current: %lu assigned: %d", mPriority, mSpawningThreadPriority, theCurrentThreadPriority, thePrecedencePolicy.importance); #endif } #elif TARGET_OS_WIN32 if(mThreadHandle != NULL) { SetThreadPriority(mThreadHandle, mPriority); } #endif }
CAPThread::CAPThread(ThreadRoutine inThreadRoutine, void* inParameter, UInt32 inPriority, bool inFixedPriority, bool inAutoDelete, const char* inThreadName) : #if TARGET_OS_MAC mPThread(0), mSpawningThreadPriority(getScheduledPriority(pthread_self(), CAPTHREAD_SET_PRIORITY)), #elif TARGET_OS_WIN32 mThreadHandle(NULL), mThreadID(0), #endif mThreadRoutine(inThreadRoutine), mThreadParameter(inParameter), mPriority(inPriority), mPeriod(0), mComputation(0), mConstraint(0), mIsPreemptible(true), mTimeConstraintSet(false), mFixedPriority(inFixedPriority), mAutoDelete(inAutoDelete) { if(inThreadName != NULL) { strlcpy(mThreadName, inThreadName, kMaxThreadNameLength); } else { memset(mThreadName, 0, kMaxThreadNameLength); } }
OpenALThread(ThreadRoutine inThreadRoutine, void* inParameter) : mPThread(0), mSpawningThreadPriority(getScheduledPriority(pthread_self(), OpenALThread_SET_PRIORITY)), mThreadRoutine(inThreadRoutine), mThreadParameter(inParameter), mPriority(kDefaultThreadPriority), mFixedPriority(false), mAutoDelete(true) { }
UInt32 CAPThread::GetScheduledPriority(NativeThread thread) { #if TARGET_OS_MAC return getScheduledPriority( thread, CAPTHREAD_SCHEDULED_PRIORITY ); #elif TARGET_OS_WIN32 return 0; // ??? #endif }
ZKMORHP_ForeignThread::ZKMORHP_ForeignThread(ThreadRoutine inThreadRoutine, ZKMORHP_ForeignThreadSource* inParameter) : #if TARGET_OS_MAC mPThread(0), mSpawningThreadPriority(getScheduledPriority(pthread_self(), CAPTHREAD_SET_PRIORITY)), #endif mThreadRoutine(inThreadRoutine), mThreadParameter(inParameter), mPriority(kDefaultThreadPriority), mPeriod(0), mComputation(0), mConstraint(0), mIsPreemptible(true), mTimeConstraintSet(false), mFixedPriority(false), mAutoDelete(false), mIsInitialized(false) { }