Removing uses of Sleep/SwitchToThread/etc.

This commit is contained in:
Ben Vanik 2015-07-13 21:54:24 -07:00
parent 40621a90bd
commit d89bad7380
8 changed files with 23 additions and 13 deletions

View File

@ -15,6 +15,7 @@
#include "xenia/base/math.h"
#include "xenia/base/ring_buffer.h"
#include "xenia/base/string_buffer.h"
#include "xenia/base/threading.h"
#include "xenia/cpu/processor.h"
#include "xenia/cpu/thread_state.h"
#include "xenia/emulator.h"
@ -147,7 +148,7 @@ void AudioSystem::WorkerThreadMain() {
if (!pumped) {
SCOPE_profile_cpu_i("apu", "Sleep");
Sleep(500);
xe::threading::Sleep(std::chrono::milliseconds::duration(500));
}
}
worker_running_ = false;

View File

@ -57,6 +57,9 @@ void set_name(std::thread::native_handle_type handle, const std::string& name);
// Yields the current thread to the scheduler. Maybe.
void MaybeYield();
// Memory barrier (request - may be ignored).
void SyncMemory();
// Sleeps the current thread for at least as long as the given duration.
void Sleep(std::chrono::microseconds duration);
template <typename Rep, typename Period>

View File

@ -52,11 +52,16 @@ void set_name(std::thread::native_handle_type handle, const std::string& name) {
set_name(GetThreadId(handle), name);
}
void MaybeYield() { SwitchToThread(); }
void MaybeYield() {
SwitchToThread();
MemoryBarrier();
}
void SyncMemory() { MemoryBarrier(); }
void Sleep(std::chrono::microseconds duration) {
if (duration.count() < 100) {
SwitchToThread();
MaybeYield();
} else {
::Sleep(static_cast<DWORD>(duration.count() / 1000));
}

View File

@ -201,8 +201,7 @@ void CommandProcessor::WorkerThreadMain() {
// It'll keep us from burning power.
// const int wait_time_ms = 5;
// WaitForSingleObject(write_ptr_index_event_, wait_time_ms);
SwitchToThread();
MemoryBarrier();
xe::threading::MaybeYield();
write_ptr_index = write_ptr_index_.load();
} while (worker_running_ && pending_fns_.empty() &&
(write_ptr_index == 0xBAADF00D ||
@ -1104,14 +1103,15 @@ bool CommandProcessor::ExecutePacketType3_WAIT_REG_MEM(RingbufferReader* reader,
PrepareForWait();
if (!FLAGS_vsync) {
// User wants it fast and dangerous.
SwitchToThread();
xe::threading::MaybeYield();
} else {
Sleep(wait / 0x100);
xe::threading::Sleep(
std::chrono::milliseconds::duration(wait / 0x100));
}
MemoryBarrier();
xe::threading::SyncMemory();
ReturnFromWait();
} else {
SwitchToThread();
xe::threading::MaybeYield();
}
}
} while (!matched);

View File

@ -125,7 +125,7 @@ X_STATUS GL4GraphicsSystem::Setup(cpu::Processor* processor,
MarkVblank();
last_frame_time = current_time;
}
Sleep(1);
xe::threading::Sleep(std::chrono::milliseconds::duration(1));
}
return 0;
}));

View File

@ -32,7 +32,7 @@ XXMPApp::XXMPApp(KernelState* kernel_state)
X_RESULT XXMPApp::XMPGetStatus(uint32_t state_ptr) {
// Some stupid games will hammer this on a thread - induce a delay
// here to keep from starving real threads.
Sleep(1);
xe::threading::Sleep(std::chrono::milliseconds::duration(1));
XELOGD("XMPGetStatus(%.8X)", state_ptr);
xe::store_and_swap<uint32_t>(memory_->TranslateVirtual(state_ptr),

View File

@ -345,7 +345,7 @@ SHIM_CALL XMABlockWhileInUse_shim(PPCContext* ppc_context,
if (!context.input_buffer_0_valid && !context.input_buffer_1_valid) {
break;
}
Sleep(1);
xe::threading::Sleep(std::chrono::milliseconds::duration(1));
} while (true);
SHIM_SET_RETURN_32(0);

View File

@ -14,6 +14,7 @@
#include "xenia/base/atomic.h"
#include "xenia/base/logging.h"
#include "xenia/base/string.h"
#include "xenia/base/threading.h"
#include "xenia/kernel/kernel_state.h"
#include "xenia/kernel/xboxkrnl_private.h"
#include "xenia/kernel/objects/xthread.h"
@ -398,7 +399,7 @@ spin:
// TODO(benvanik): contention - do a real wait!
// XELOGE("RtlEnterCriticalSection tried to really lock!");
spin_wait_remaining = 0; // HACK: spin forever
SwitchToThread();
xe::threading::MaybeYield();
goto spin;
}