Fix AudioSystem Restore and cleanup some code
This commit is contained in:
parent
b94ab4acbc
commit
ee0a41aa2c
|
@ -109,28 +109,23 @@ void AudioSystem::WorkerThreadMain() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Number of clients pumped
|
// Number of clients pumped
|
||||||
size_t pumped = 0;
|
bool pumped = false;
|
||||||
if (result.first == xe::threading::WaitResult::kSuccess) {
|
if (result.first == xe::threading::WaitResult::kSuccess) {
|
||||||
// Start from the first handle signaled and continue down.
|
auto index = result.second;
|
||||||
size_t index = result.second;
|
|
||||||
do {
|
|
||||||
auto global_lock = global_critical_region_.Acquire();
|
|
||||||
uint32_t client_callback = clients_[index].callback;
|
|
||||||
uint32_t client_callback_arg = clients_[index].wrapped_callback_arg;
|
|
||||||
global_lock.unlock();
|
|
||||||
|
|
||||||
if (client_callback) {
|
auto global_lock = global_critical_region_.Acquire();
|
||||||
SCOPE_profile_cpu_i("apu", "xe::apu::AudioSystem->client_callback");
|
uint32_t client_callback = clients_[index].callback;
|
||||||
uint64_t args[] = {client_callback_arg};
|
uint32_t client_callback_arg = clients_[index].wrapped_callback_arg;
|
||||||
processor_->Execute(worker_thread_->thread_state(), client_callback,
|
global_lock.unlock();
|
||||||
args, xe::countof(args));
|
|
||||||
}
|
if (client_callback) {
|
||||||
pumped++;
|
SCOPE_profile_cpu_i("apu", "xe::apu::AudioSystem->client_callback");
|
||||||
index++;
|
uint64_t args[] = {client_callback_arg};
|
||||||
} while (index < kMaximumClientCount &&
|
processor_->Execute(worker_thread_->thread_state(), client_callback,
|
||||||
xe::threading::Wait(client_semaphores_[index].get(), false,
|
args, xe::countof(args));
|
||||||
std::chrono::milliseconds(0)) ==
|
}
|
||||||
xe::threading::WaitResult::kSuccess);
|
|
||||||
|
pumped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!worker_running_) {
|
if (!worker_running_) {
|
||||||
|
@ -212,6 +207,7 @@ void AudioSystem::UnregisterClient(size_t index) {
|
||||||
auto global_lock = global_critical_region_.Acquire();
|
auto global_lock = global_critical_region_.Acquire();
|
||||||
assert_true(index < kMaximumClientCount);
|
assert_true(index < kMaximumClientCount);
|
||||||
DestroyDriver(clients_[index].driver);
|
DestroyDriver(clients_[index].driver);
|
||||||
|
memory()->SystemHeapFree(clients_[index].wrapped_callback_arg);
|
||||||
clients_[index] = {0};
|
clients_[index] = {0};
|
||||||
|
|
||||||
// Drain the semaphore of its count.
|
// Drain the semaphore of its count.
|
||||||
|
@ -264,17 +260,18 @@ bool AudioSystem::Restore(ByteStream* stream) {
|
||||||
assert_true(id < kMaximumClientCount);
|
assert_true(id < kMaximumClientCount);
|
||||||
|
|
||||||
auto& client = clients_[id];
|
auto& client = clients_[id];
|
||||||
client.callback = stream->Read<uint32_t>();
|
|
||||||
client.callback_arg = stream->Read<uint32_t>();
|
|
||||||
client.wrapped_callback_arg = stream->Read<uint32_t>();
|
|
||||||
|
|
||||||
client.in_use = true;
|
|
||||||
|
|
||||||
// Reset the semaphore and recreate the driver ourselves.
|
// Reset the semaphore and recreate the driver ourselves.
|
||||||
if (client.driver) {
|
if (client.driver) {
|
||||||
UnregisterClient(id);
|
UnregisterClient(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client.callback = stream->Read<uint32_t>();
|
||||||
|
client.callback_arg = stream->Read<uint32_t>();
|
||||||
|
client.wrapped_callback_arg = stream->Read<uint32_t>();
|
||||||
|
|
||||||
|
client.in_use = true;
|
||||||
|
|
||||||
auto client_semaphore = client_semaphores_[id].get();
|
auto client_semaphore = client_semaphores_[id].get();
|
||||||
auto ret = client_semaphore->Release(kMaximumQueuedFrames, nullptr);
|
auto ret = client_semaphore->Release(kMaximumQueuedFrames, nullptr);
|
||||||
assert_true(ret);
|
assert_true(ret);
|
||||||
|
|
Loading…
Reference in New Issue