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/thread_act.h>
#include <mach/mach_init.h>
#include <mach/mach_error.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()
@@ -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