Move audio system onto XHostThread
This commit is contained in:
parent
ffe3b4bf04
commit
b1920f4a87
|
@ -14,6 +14,7 @@
|
||||||
#include "xenia/base/math.h"
|
#include "xenia/base/math.h"
|
||||||
#include "xenia/cpu/processor.h"
|
#include "xenia/cpu/processor.h"
|
||||||
#include "xenia/cpu/thread_state.h"
|
#include "xenia/cpu/thread_state.h"
|
||||||
|
#include "xenia/kernel/objects/xthread.h"
|
||||||
#include "xenia/emulator.h"
|
#include "xenia/emulator.h"
|
||||||
#include "xenia/profiling.h"
|
#include "xenia/profiling.h"
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ namespace xe {
|
||||||
namespace apu {
|
namespace apu {
|
||||||
|
|
||||||
using namespace xe::cpu;
|
using namespace xe::cpu;
|
||||||
|
using namespace xe::kernel;
|
||||||
|
|
||||||
// Size of a hardware XMA context.
|
// Size of a hardware XMA context.
|
||||||
const uint32_t kXmaContextSize = 64;
|
const uint32_t kXmaContextSize = 64;
|
||||||
|
@ -89,30 +91,23 @@ X_STATUS AudioSystem::Setup() {
|
||||||
}
|
}
|
||||||
registers_.next_context = 1;
|
registers_.next_context = 1;
|
||||||
|
|
||||||
// Setup worker thread state. This lets us make calls into guest code.
|
// Setup our worker thread
|
||||||
thread_state_ =
|
std::function<int()> thread_fn = [this]() {
|
||||||
new ThreadState(emulator_->processor(), 0, ThreadStackType::kKernelStack,
|
this->ThreadStart();
|
||||||
0, 128 * 1024, 0);
|
return 0;
|
||||||
thread_state_->set_name("Audio Worker");
|
};
|
||||||
thread_block_ = memory()->SystemHeapAlloc(2048);
|
|
||||||
thread_state_->context()->r[13] = thread_block_;
|
|
||||||
XELOGI("Audio Worker Thread %X Stack: %.8X-%.8X", thread_state_->thread_id(),
|
|
||||||
thread_state_->stack_address(),
|
|
||||||
thread_state_->stack_address() + thread_state_->stack_size());
|
|
||||||
|
|
||||||
// Create worker thread.
|
|
||||||
// This will initialize the audio system.
|
|
||||||
// Init needs to happen there so that any thread-local stuff
|
|
||||||
// is created on the right thread.
|
|
||||||
running_ = true;
|
running_ = true;
|
||||||
thread_ = std::thread(std::bind(&AudioSystem::ThreadStart, this));
|
|
||||||
|
thread_ = std::make_unique<XHostThread>(emulator()->kernel_state(),
|
||||||
|
128 * 1024, 0, thread_fn);
|
||||||
|
thread_->Create();
|
||||||
|
|
||||||
return X_STATUS_SUCCESS;
|
return X_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioSystem::ThreadStart() {
|
void AudioSystem::ThreadStart() {
|
||||||
xe::threading::set_name("Audio Worker");
|
xe::threading::set_name("Audio Worker");
|
||||||
xe::Profiler::ThreadEnter("Audio Worker");
|
|
||||||
|
|
||||||
// Initialize driver and ringbuffer.
|
// Initialize driver and ringbuffer.
|
||||||
Initialize();
|
Initialize();
|
||||||
|
@ -140,7 +135,7 @@ void AudioSystem::ThreadStart() {
|
||||||
lock_.unlock();
|
lock_.unlock();
|
||||||
if (client_callback) {
|
if (client_callback) {
|
||||||
uint64_t args[] = {client_callback_arg};
|
uint64_t args[] = {client_callback_arg};
|
||||||
processor->Execute(thread_state_, client_callback, args,
|
processor->Execute(thread_->thread_state(), client_callback, args,
|
||||||
xe::countof(args));
|
xe::countof(args));
|
||||||
}
|
}
|
||||||
pumped++;
|
pumped++;
|
||||||
|
@ -162,8 +157,6 @@ void AudioSystem::ThreadStart() {
|
||||||
running_ = false;
|
running_ = false;
|
||||||
|
|
||||||
// TODO(benvanik): call module API to kill?
|
// TODO(benvanik): call module API to kill?
|
||||||
|
|
||||||
xe::Profiler::ThreadExit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioSystem::Initialize() {}
|
void AudioSystem::Initialize() {}
|
||||||
|
@ -171,10 +164,7 @@ void AudioSystem::Initialize() {}
|
||||||
void AudioSystem::Shutdown() {
|
void AudioSystem::Shutdown() {
|
||||||
running_ = false;
|
running_ = false;
|
||||||
ResetEvent(client_wait_handles_[maximum_client_count_]);
|
ResetEvent(client_wait_handles_[maximum_client_count_]);
|
||||||
thread_.join();
|
thread_->Wait(0, 0, 0, NULL);
|
||||||
|
|
||||||
delete thread_state_;
|
|
||||||
memory()->SystemHeapFree(thread_block_);
|
|
||||||
|
|
||||||
memory()->SystemHeapFree(registers_.xma_context_array_ptr);
|
memory()->SystemHeapFree(registers_.xma_context_array_ptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
#include "xenia/xbox.h"
|
#include "xenia/xbox.h"
|
||||||
|
|
||||||
namespace xe {
|
namespace xe {
|
||||||
|
|
||||||
|
namespace kernel { class XHostThread; }
|
||||||
|
|
||||||
namespace apu {
|
namespace apu {
|
||||||
|
|
||||||
class AudioDriver;
|
class AudioDriver;
|
||||||
|
@ -73,9 +76,7 @@ class AudioSystem {
|
||||||
Memory* memory_;
|
Memory* memory_;
|
||||||
cpu::Processor* processor_;
|
cpu::Processor* processor_;
|
||||||
|
|
||||||
std::thread thread_;
|
std::unique_ptr<kernel::XHostThread> thread_;
|
||||||
cpu::ThreadState* thread_state_;
|
|
||||||
uint32_t thread_block_;
|
|
||||||
std::atomic<bool> running_;
|
std::atomic<bool> running_;
|
||||||
|
|
||||||
std::mutex lock_;
|
std::mutex lock_;
|
||||||
|
|
Loading…
Reference in New Issue