Thread IDs in critical sections.

This commit is contained in:
Ben Vanik 2013-01-31 03:01:57 -08:00
parent 56912aa2bd
commit 9cfc01940e
3 changed files with 11 additions and 4 deletions

View File

@ -58,6 +58,10 @@ XThread::~XThread() {
}
}
uint32_t XThread::GetCurrentThreadId(const uint8_t* thread_state_block) {
return XEGETUINT32BE(thread_state_block + 0x14C);
}
uint32_t XThread::thread_id() {
return thread_id_;
}

View File

@ -29,6 +29,8 @@ public:
uint32_t creation_flags);
virtual ~XThread();
static uint32_t GetCurrentThreadId(const uint8_t* thread_state_block);
uint32_t thread_id();
uint32_t last_error();
void set_last_error(uint32_t error_code);

View File

@ -13,6 +13,7 @@
#include <xenia/kernel/xex2.h>
#include "kernel/shim_utils.h"
#include "kernel/modules/xboxkrnl/objects/xthread.h"
using namespace xe;
@ -395,8 +396,8 @@ void RtlEnterCriticalSection_shim(
X_RTL_CRITICAL_SECTION* cs = (X_RTL_CRITICAL_SECTION*)SHIM_MEM_ADDR(cs_ptr);
// TODO(benvanik): get current thread ID.
uint32_t thread_id = 0;
const uint8_t* thread_state_block = ppc_state->membase + ppc_state->r[13];
uint32_t thread_id = XThread::GetCurrentThreadId(thread_state_block);
uint32_t spin_wait_remaining = cs->spin_count_div_256 * 256;
spin:
@ -434,8 +435,8 @@ void RtlTryEnterCriticalSection_shim(
X_RTL_CRITICAL_SECTION* cs = (X_RTL_CRITICAL_SECTION*)SHIM_MEM_ADDR(cs_ptr);
// TODO(benvanik): get current thread ID.
uint32_t thread_id = 0;
const uint8_t* thread_state_block = ppc_state->membase + ppc_state->r[13];
uint32_t thread_id = XThread::GetCurrentThreadId(thread_state_block);
if (xe_atomic_cas_32(-1, 0, &cs->lock_count)) {
// Able to steal the lock right away.