Cleanup and add SetThreadPrecedence().

This commit is contained in:
Steve Checkoway
2005-10-24 11:18:28 +00:00
parent 2e84aba3a4
commit a1e97116b5
2 changed files with 25 additions and 12 deletions
@@ -1,16 +1,18 @@
#include <mach/mach_types.h> #include <mach/mach_types.h>
#include <mach/thread_act.h> #include <mach/thread_act.h>
#include <mach/mach_init.h> #include <mach/mach_init.h>
#include <mach/mach_error.h>
#include "Backtrace.h" #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() uint64_t GetCurrentThreadId()
@@ -18,27 +20,37 @@ uint64_t GetCurrentThreadId()
return mach_thread_self(); return mach_thread_self();
} }
bool GetThreadBacktraceContext(uint64_t iID, BacktraceContext *ctx) bool GetThreadBacktraceContext( uint64_t iID, BacktraceContext *ctx )
{ {
/* Can't GetThreadBacktraceContext the current thread. */ /* Can't GetThreadBacktraceContext the current thread. */
ASSERT(iID != GetCurrentThreadId()); ASSERT(iID != GetCurrentThreadId());
SuspendThread( iID ); SuspendThread( iID );
thread_act_t thread = thread_act_t(iID); thread_act_t thread = thread_act_t( iID );
ppc_thread_state state; ppc_thread_state state;
mach_msg_type_number_t count = PPC_THREAD_STATE_COUNT; mach_msg_type_number_t count = PPC_THREAD_STATE_COUNT;
if (thread_get_state(thread, PPC_THREAD_STATE, thread_state_t(&state), if( thread_get_state(thread, PPC_THREAD_STATE, thread_state_t(&state), &count) )
&count))
return false; return false;
ctx->FramePtr = (void *)state.r1; ctx->FramePtr = (void *)state.r1;
ctx->PC = (void *)state.srr0; ctx->PC = (void *)state.srr0;
return true; 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. * All rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
@@ -1,14 +1,15 @@
#ifndef DARWIN_THREAD_HELPERS_H #ifndef DARWIN_THREAD_HELPERS_H
#define DARWIN_THREAD_HELPERS_H #define DARWIN_THREAD_HELPERS_H
bool SuspendThread(uint64_t threadHandle); bool SuspendThread( uint64_t threadHandle );
bool ResumeThread(uint64_t threadHandle); bool ResumeThread( uint64_t threadHandle );
uint64_t GetCurrentThreadId(); uint64_t GetCurrentThreadId();
void SetThreadPrecedence( int prec );
#endif #endif
/* /*
* (c) 2004 Steve Checkoway * (c) 2004, 2005 Steve Checkoway
* All rights reserved. * All rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a