From ca27a7d350499bf2f06fc7e09575f2f66e01152a Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Sat, 21 Jan 2006 11:13:53 +0000 Subject: [PATCH] Change the API a bit. Use values between 0 and 1. --- .../src/archutils/Darwin/DarwinThreadHelpers.cpp | 12 ++++++++---- stepmania/src/archutils/Darwin/DarwinThreadHelpers.h | 5 +++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/stepmania/src/archutils/Darwin/DarwinThreadHelpers.cpp b/stepmania/src/archutils/Darwin/DarwinThreadHelpers.cpp index 545802dc3f..a4faeef8d3 100644 --- a/stepmania/src/archutils/Darwin/DarwinThreadHelpers.cpp +++ b/stepmania/src/archutils/Darwin/DarwinThreadHelpers.cpp @@ -4,6 +4,7 @@ #include #include "Backtrace.h" #include "RageLog.h" +#include "RageUtil.h" bool SuspendThread( uint64_t threadHandle ) { @@ -42,11 +43,14 @@ bool GetThreadBacktraceContext( uint64_t iID, BacktraceContext *ctx ) #endif } -void SetThreadPrecedence( int prec ) +void SetThreadPrecedence( float prec ) { - thread_precedence_policy po = { prec }; + // Real values are between 0 and 63. + if( CLAMP(prec, 0.0f, 1.0f) ) + LOG->Warn( "Thread precedence clamped to %f.", prec ); + thread_precedence_policy po = { integer_t( roundf(prec * 63) ) }; kern_return_t ret = thread_policy_set( mach_thread_self(), THREAD_PRECEDENCE_POLICY, - (int *)&po, THREAD_PRECEDENCE_POLICY_COUNT ); + (thread_policy_t)&po, THREAD_PRECEDENCE_POLICY_COUNT ); if( ret != KERN_SUCCESS ) LOG->Warn( "Couldn't set the precedence for the input thread: %s", @@ -54,7 +58,7 @@ void SetThreadPrecedence( int prec ) } /* - * (c) 2004, 2005 Steve Checkoway + * (c) 2004-2006 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 7b82bd393c..4adc999614 100644 --- a/stepmania/src/archutils/Darwin/DarwinThreadHelpers.h +++ b/stepmania/src/archutils/Darwin/DarwinThreadHelpers.h @@ -4,12 +4,13 @@ bool SuspendThread( uint64_t threadHandle ); bool ResumeThread( uint64_t threadHandle ); uint64_t GetCurrentThreadId(); -void SetThreadPrecedence( int prec ); +// Valid values are from 0.0f to 1.0f. 0.5f is default. +void SetThreadPrecedence( float prec ); #endif /* - * (c) 2004, 2005 Steve Checkoway + * (c) 2004-2006 Steve Checkoway * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a