Thread IDs in critical sections.
This commit is contained in:
parent
56912aa2bd
commit
9cfc01940e
|
@ -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() {
|
uint32_t XThread::thread_id() {
|
||||||
return thread_id_;
|
return thread_id_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ public:
|
||||||
uint32_t creation_flags);
|
uint32_t creation_flags);
|
||||||
virtual ~XThread();
|
virtual ~XThread();
|
||||||
|
|
||||||
|
static uint32_t GetCurrentThreadId(const uint8_t* thread_state_block);
|
||||||
|
|
||||||
uint32_t thread_id();
|
uint32_t thread_id();
|
||||||
uint32_t last_error();
|
uint32_t last_error();
|
||||||
void set_last_error(uint32_t error_code);
|
void set_last_error(uint32_t error_code);
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <xenia/kernel/xex2.h>
|
#include <xenia/kernel/xex2.h>
|
||||||
|
|
||||||
#include "kernel/shim_utils.h"
|
#include "kernel/shim_utils.h"
|
||||||
|
#include "kernel/modules/xboxkrnl/objects/xthread.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace xe;
|
using namespace xe;
|
||||||
|
@ -395,8 +396,8 @@ void RtlEnterCriticalSection_shim(
|
||||||
|
|
||||||
X_RTL_CRITICAL_SECTION* cs = (X_RTL_CRITICAL_SECTION*)SHIM_MEM_ADDR(cs_ptr);
|
X_RTL_CRITICAL_SECTION* cs = (X_RTL_CRITICAL_SECTION*)SHIM_MEM_ADDR(cs_ptr);
|
||||||
|
|
||||||
// TODO(benvanik): get current thread ID.
|
const uint8_t* thread_state_block = ppc_state->membase + ppc_state->r[13];
|
||||||
uint32_t thread_id = 0;
|
uint32_t thread_id = XThread::GetCurrentThreadId(thread_state_block);
|
||||||
uint32_t spin_wait_remaining = cs->spin_count_div_256 * 256;
|
uint32_t spin_wait_remaining = cs->spin_count_div_256 * 256;
|
||||||
|
|
||||||
spin:
|
spin:
|
||||||
|
@ -434,8 +435,8 @@ void RtlTryEnterCriticalSection_shim(
|
||||||
|
|
||||||
X_RTL_CRITICAL_SECTION* cs = (X_RTL_CRITICAL_SECTION*)SHIM_MEM_ADDR(cs_ptr);
|
X_RTL_CRITICAL_SECTION* cs = (X_RTL_CRITICAL_SECTION*)SHIM_MEM_ADDR(cs_ptr);
|
||||||
|
|
||||||
// TODO(benvanik): get current thread ID.
|
const uint8_t* thread_state_block = ppc_state->membase + ppc_state->r[13];
|
||||||
uint32_t thread_id = 0;
|
uint32_t thread_id = XThread::GetCurrentThreadId(thread_state_block);
|
||||||
|
|
||||||
if (xe_atomic_cas_32(-1, 0, &cs->lock_count)) {
|
if (xe_atomic_cas_32(-1, 0, &cs->lock_count)) {
|
||||||
// Able to steal the lock right away.
|
// Able to steal the lock right away.
|
||||||
|
|
Loading…
Reference in New Issue