Removing xe_mutex_t.

This commit is contained in:
Ben Vanik
2014-08-16 00:56:50 -07:00
parent 96fb484dd9
commit bca49bed4b
23 changed files with 101 additions and 276 deletions

View File

@@ -23,7 +23,6 @@ using namespace xe::cpu;
AudioSystem::AudioSystem(Emulator* emulator) :
emulator_(emulator), memory_(emulator->memory()),
thread_(0), running_(false) {
lock_ = xe_mutex_alloc();
memset(clients_, 0, sizeof(clients_));
for (size_t i = 0; i < maximum_client_count_; ++i) {
client_wait_handles_[i] = CreateEvent(NULL, TRUE, FALSE, NULL);
@@ -35,7 +34,6 @@ AudioSystem::~AudioSystem() {
for (size_t i = 0; i < maximum_client_count_; ++i) {
CloseHandle(client_wait_handles_[i]);
}
xe_mutex_free(lock_);
}
X_STATUS AudioSystem::Setup() {
@@ -90,10 +88,10 @@ void AudioSystem::ThreadStart() {
if (result >= WAIT_OBJECT_0 && result <= WAIT_OBJECT_0 + (maximum_client_count_ - 1)) {
size_t index = result - WAIT_OBJECT_0;
do {
xe_mutex_lock(lock_);
lock_.lock();
uint32_t client_callback = clients_[index].callback;
uint32_t client_callback_arg = clients_[index].wrapped_callback_arg;
xe_mutex_unlock(lock_);
lock_.unlock();
if (client_callback) {
uint64_t args[] = { client_callback_arg };
processor->Execute(thread_state_, client_callback, args, XECOUNT(args));
@@ -132,7 +130,7 @@ void AudioSystem::Shutdown() {
X_STATUS AudioSystem::RegisterClient(
uint32_t callback, uint32_t callback_arg, size_t* out_index) {
assert_true(unused_clients_.size());
xe_mutex_lock(lock_);
std::lock_guard<std::mutex> lock(lock_);
auto index = unused_clients_.front();
@@ -157,30 +155,27 @@ X_STATUS AudioSystem::RegisterClient(
*out_index = index;
}
xe_mutex_unlock(lock_);
return X_STATUS_SUCCESS;
}
void AudioSystem::SubmitFrame(size_t index, uint32_t samples_ptr) {
SCOPE_profile_cpu_f("apu");
xe_mutex_lock(lock_);
std::lock_guard<std::mutex> lock(lock_);
assert_true(index < maximum_client_count_);
assert_true(clients_[index].driver != NULL);
(clients_[index].driver)->SubmitFrame(samples_ptr);
ResetEvent(client_wait_handles_[index]);
xe_mutex_unlock(lock_);
}
void AudioSystem::UnregisterClient(size_t index) {
SCOPE_profile_cpu_f("apu");
xe_mutex_lock(lock_);
std::lock_guard<std::mutex> lock(lock_);
assert_true(index < maximum_client_count_);
DestroyDriver(clients_[index].driver);
clients_[index] = { 0 };
unused_clients_.push(index);
xe_mutex_unlock(lock_);
}
// free60 may be useful here, however it looks like it's using a different

View File

@@ -10,11 +10,12 @@
#ifndef XENIA_APU_AUDIO_SYSTEM_H_
#define XENIA_APU_AUDIO_SYSTEM_H_
#include <mutex>
#include <queue>
#include <xenia/core.h>
#include <xenia/xbox.h>
#include <queue>
XEDECLARECLASS1(xe, Emulator);
XEDECLARECLASS2(xe, cpu, Processor);
XEDECLARECLASS2(xe, cpu, XenonThreadState);
@@ -74,7 +75,7 @@ protected:
uint32_t thread_block_;
bool running_;
xe_mutex_t* lock_;
std::mutex lock_;
static const size_t maximum_client_count_ = 8;