From f5a2b85d42a9846d3144278f70b39556a29751cc Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sun, 24 May 2015 23:16:43 -0700 Subject: [PATCH] Switching to xe::mutex. --- src/xenia/apu/audio_system.cc | 30 +++++++----- src/xenia/apu/audio_system.h | 50 ++++++++++---------- src/xenia/base/type_pool.h | 10 ++-- src/xenia/cpu/backend/x64/x64_code_cache.cc | 2 +- src/xenia/cpu/backend/x64/x64_code_cache.h | 4 +- src/xenia/cpu/entry_table.cc | 6 +-- src/xenia/cpu/entry_table.h | 4 +- src/xenia/cpu/frontend/ppc_frontend.cc | 2 +- src/xenia/cpu/frontend/ppc_frontend.h | 3 +- src/xenia/cpu/function.cc | 6 +-- src/xenia/cpu/function.h | 3 +- src/xenia/cpu/mmio_handler.h | 4 +- src/xenia/cpu/module.cc | 4 +- src/xenia/cpu/module.h | 5 +- src/xenia/cpu/processor.cc | 12 ++--- src/xenia/cpu/processor.h | 5 +- src/xenia/gpu/gl4/texture_cache.cc | 2 +- src/xenia/gpu/gl4/texture_cache.h | 3 +- src/xenia/kernel/apps/xmp_app.cc | 6 +-- src/xenia/kernel/apps/xmp_app.h | 3 +- src/xenia/kernel/content_manager.cc | 14 +++--- src/xenia/kernel/content_manager.h | 3 +- src/xenia/kernel/dispatcher.h | 3 +- src/xenia/kernel/objects/xnotify_listener.cc | 6 +-- src/xenia/kernel/objects/xnotify_listener.h | 3 +- src/xenia/kernel/objects/xthread.cc | 3 +- src/xenia/kernel/objects/xthread.h | 2 +- src/xenia/kernel/xboxkrnl_ob.cc | 1 + src/xenia/kernel/xboxkrnl_threading.cc | 5 +- src/xenia/memory.cc | 34 +++++++------ src/xenia/memory.h | 3 +- 31 files changed, 133 insertions(+), 108 deletions(-) diff --git a/src/xenia/apu/audio_system.cc b/src/xenia/apu/audio_system.cc index 4e6f82604..abd627012 100644 --- a/src/xenia/apu/audio_system.cc +++ b/src/xenia/apu/audio_system.cc @@ -56,8 +56,10 @@ const uint32_t kXmaContextSize = 64; const uint32_t kXmaContextCount = 320; AudioSystem::AudioSystem(Emulator* emulator) - : emulator_(emulator), memory_(emulator->memory()), worker_running_(false), - decoder_running_(false) { + : emulator_(emulator), + memory_(emulator->memory()), + worker_running_(false), + decoder_running_(false) { memset(clients_, 0, sizeof(clients_)); for (size_t i = 0; i < maximum_client_count_; ++i) { unused_clients_.push(i); @@ -249,7 +251,8 @@ void AudioSystem::DecoderThreadMain() { // TODO - Probably need to move this, I think it might skip the very // last packet (see the call to PreparePacket) size_t input_size = (data.input_buffer_0_block_count + - data.input_buffer_1_block_count) * 2048; + data.input_buffer_1_block_count) * + 2048; size_t input_offset = (data.input_buffer_read_offset / 8 - 4); size_t input_remaining = input_size - input_offset; if (input_offset > input_size) { @@ -339,7 +342,7 @@ void AudioSystem::Shutdown() { } uint32_t AudioSystem::AllocateXmaContext() { - std::lock_guard lock(lock_); + std::lock_guard lock(lock_); for (uint32_t n = 0; n < kXmaContextCount; n++) { XMAContext& context = xma_context_array_[n]; @@ -353,7 +356,7 @@ uint32_t AudioSystem::AllocateXmaContext() { } void AudioSystem::ReleaseXmaContext(uint32_t guest_ptr) { - std::lock_guard lock(lock_); + std::lock_guard lock(lock_); // Find it in the list. for (uint32_t n = 0; n < kXmaContextCount; n++) { @@ -365,9 +368,9 @@ void AudioSystem::ReleaseXmaContext(uint32_t guest_ptr) { context.in_use = false; auto context_ptr = memory()->TranslateVirtual(guest_ptr); - std::memset(context_ptr, 0, kXmaContextSize); // Zero it. + std::memset(context_ptr, 0, kXmaContextSize); // Zero it. context.decoder->DiscardPacket(); - + context.lock.unlock(); } } @@ -376,7 +379,7 @@ void AudioSystem::ReleaseXmaContext(uint32_t guest_ptr) { X_STATUS AudioSystem::RegisterClient(uint32_t callback, uint32_t callback_arg, size_t* out_index) { assert_true(unused_clients_.size()); - std::lock_guard lock(lock_); + std::lock_guard lock(lock_); auto index = unused_clients_.front(); @@ -406,7 +409,7 @@ X_STATUS AudioSystem::RegisterClient(uint32_t callback, uint32_t callback_arg, void AudioSystem::SubmitFrame(size_t index, uint32_t samples_ptr) { SCOPE_profile_cpu_f("apu"); - std::lock_guard lock(lock_); + std::lock_guard lock(lock_); assert_true(index < maximum_client_count_); assert_true(clients_[index].driver != NULL); (clients_[index].driver)->SubmitFrame(samples_ptr); @@ -416,7 +419,7 @@ void AudioSystem::SubmitFrame(size_t index, uint32_t samples_ptr) { void AudioSystem::UnregisterClient(size_t index) { SCOPE_profile_cpu_f("apu"); - std::lock_guard lock(lock_); + std::lock_guard lock(lock_); assert_true(index < maximum_client_count_); DestroyDriver(clients_[index].driver); clients_[index] = {0}; @@ -478,9 +481,10 @@ void AudioSystem::WriteRegister(uint32_t addr, uint64_t value) { auto context_ptr = memory()->TranslateVirtual(context.guest_ptr); XMAContextData data(context_ptr); - XELOGAPU("AudioSystem: kicking context %d (%d/%d bytes)", context_id, - data.input_buffer_read_offset, data.input_buffer_0_block_count - * XMAContextData::kBytesPerBlock); + XELOGAPU( + "AudioSystem: kicking context %d (%d/%d bytes)", context_id, + data.input_buffer_read_offset, + data.input_buffer_0_block_count * XMAContextData::kBytesPerBlock); // Reset valid flags so our audio decoder knows to process this one data.input_buffer_0_valid = data.input_buffer_0_ptr != 0; diff --git a/src/xenia/apu/audio_system.h b/src/xenia/apu/audio_system.h index f27abb043..80c084410 100644 --- a/src/xenia/apu/audio_system.h +++ b/src/xenia/apu/audio_system.h @@ -51,25 +51,27 @@ struct XMAContextData { uint32_t input_buffer_0_valid : 1; // +20bit, XMAIsInputBuffer0Valid uint32_t input_buffer_1_valid : 1; // +21bit, XMAIsInputBuffer1Valid uint32_t output_buffer_block_count : 5; // +22bit SizeWrite 256byte blocks - uint32_t output_buffer_write_offset : 5; // +27bit, XMAGetOutputBufferWriteOffset - // AKA OffsetWrite + uint32_t + output_buffer_write_offset : 5; // +27bit, XMAGetOutputBufferWriteOffset + // AKA OffsetWrite // DWORD 1 uint32_t input_buffer_1_block_count : 12; // XMASetInputBuffer1, number of // 2KB blocks. uint32_t loop_subframe_end : 2; // +12bit, XMASetLoopData uint32_t unk_dword_1_a : 3; // ? might be loop_subframe_skip - uint32_t loop_subframe_skip : 3; // +17bit, XMASetLoopData might be subframe_decode_count - uint32_t subframe_decode_count : 4; // +20bit might be subframe_skip_count - uint32_t unk_dword_1_b : 3; // ? NumSubframesToSkip/NumChannels(?) - uint32_t sample_rate : 2; // +27bit enum of sample rates - uint32_t is_stereo : 1; // +29bit might be NumChannels - uint32_t unk_dword_1_c : 1; // ? part of NumChannels? - uint32_t output_buffer_valid : 1; // +31bit, XMAIsOutputBufferValid + uint32_t loop_subframe_skip : 3; // +17bit, XMASetLoopData might be + // subframe_decode_count + uint32_t subframe_decode_count : 4; // +20bit might be subframe_skip_count + uint32_t unk_dword_1_b : 3; // ? NumSubframesToSkip/NumChannels(?) + uint32_t sample_rate : 2; // +27bit enum of sample rates + uint32_t is_stereo : 1; // +29bit might be NumChannels + uint32_t unk_dword_1_c : 1; // ? part of NumChannels? + uint32_t output_buffer_valid : 1; // +31bit, XMAIsOutputBufferValid // DWORD 2 - uint32_t input_buffer_read_offset : 30; // XMAGetInputBufferReadOffset - uint32_t unk_dword_2 : 2; // ErrorStatus/ErrorSet (?) + uint32_t input_buffer_read_offset : 30; // XMAGetInputBufferReadOffset + uint32_t unk_dword_2 : 2; // ErrorStatus/ErrorSet (?) // DWORD 3 uint32_t loop_start : 26; // XMASetLoopData LoopStartOffset @@ -85,25 +87,25 @@ struct XMAContextData { // DWORD 6 uint32_t input_buffer_1_ptr; // physical address // DWORD 7 - uint32_t output_buffer_ptr; // physical address + uint32_t output_buffer_ptr; // physical address // DWORD 8 - uint32_t overlap_add_ptr; // PtrOverlapAdd(?) + uint32_t overlap_add_ptr; // PtrOverlapAdd(?) // DWORD 9 // +0bit, XMAGetOutputBufferReadOffset AKA WriteBufferOffsetRead - uint32_t output_buffer_read_offset : 5; - uint32_t unk_dword_9 : 27; // StopWhenDone/InterruptWhenDone(?) + uint32_t output_buffer_read_offset : 5; + uint32_t unk_dword_9 : 27; // StopWhenDone/InterruptWhenDone(?) XMAContextData(const void* ptr) { xe::copy_and_swap_32_aligned(reinterpret_cast(this), - reinterpret_cast(ptr), - sizeof(XMAContextData) / 4); + reinterpret_cast(ptr), + sizeof(XMAContextData) / 4); } void Store(void* ptr) { xe::copy_and_swap_32_aligned(reinterpret_cast(ptr), - reinterpret_cast(this), - sizeof(XMAContextData) / 4); + reinterpret_cast(this), + sizeof(XMAContextData) / 4); } }; static_assert(sizeof(XMAContextData) == 4 * 10, "Must be packed"); @@ -166,7 +168,7 @@ class AudioSystem { kernel::object_ref decoder_thread_; xe::threading::Fence decoder_fence_; - std::mutex lock_; + xe::mutex lock_; // Stored little endian, accessed through 0x7FEA.... union { @@ -189,16 +191,16 @@ class AudioSystem { uint32_t register_file_[0xFFFF / 4]; }; struct XMAContext { - uint32_t guest_ptr; - std::mutex lock; - bool in_use; + uint32_t guest_ptr; + xe::mutex lock; + bool in_use; AudioDecoder* decoder; }; XMAContext xma_context_array_[320]; std::vector xma_context_free_list_; - std::vector xma_context_used_list_; // XMA contexts in use + std::vector xma_context_used_list_; // XMA contexts in use static const size_t maximum_client_count_ = 8; diff --git a/src/xenia/base/type_pool.h b/src/xenia/base/type_pool.h index 81f0ba77f..55ded9812 100644 --- a/src/xenia/base/type_pool.h +++ b/src/xenia/base/type_pool.h @@ -13,6 +13,8 @@ #include #include +#include "xenia/base/mutex.h" + namespace xe { template @@ -21,7 +23,7 @@ class TypePool { ~TypePool() { Reset(); } void Reset() { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); for (auto it = list_.begin(); it != list_.end(); ++it) { T* value = *it; delete value; @@ -32,7 +34,7 @@ class TypePool { T* Allocate(A arg0) { T* result = 0; { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); if (list_.size()) { result = list_.back(); list_.pop_back(); @@ -45,12 +47,12 @@ class TypePool { } void Release(T* value) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); list_.push_back(value); } private: - std::mutex lock_; + xe::mutex lock_; std::vector list_; }; diff --git a/src/xenia/cpu/backend/x64/x64_code_cache.cc b/src/xenia/cpu/backend/x64/x64_code_cache.cc index 539d3f359..6ae976a72 100644 --- a/src/xenia/cpu/backend/x64/x64_code_cache.cc +++ b/src/xenia/cpu/backend/x64/x64_code_cache.cc @@ -122,7 +122,7 @@ void* X64CodeCache::PlaceCode(uint32_t guest_address, void* machine_code, uint8_t* unwind_entry_address = nullptr; size_t unwind_table_slot = 0; { - std::lock_guard allocation_lock(allocation_mutex_); + std::lock_guard allocation_lock(allocation_mutex_); low_mark = generated_code_offset_; diff --git a/src/xenia/cpu/backend/x64/x64_code_cache.h b/src/xenia/cpu/backend/x64/x64_code_cache.h index 13234abd6..466a3b536 100644 --- a/src/xenia/cpu/backend/x64/x64_code_cache.h +++ b/src/xenia/cpu/backend/x64/x64_code_cache.h @@ -17,6 +17,8 @@ #include #include +#include "xenia/base/mutex.h" + namespace xe { namespace cpu { namespace backend { @@ -54,7 +56,7 @@ class X64CodeCache { // Must be held when manipulating the offsets or counts of anything, to keep // the tables consistent and ordered. - std::mutex allocation_mutex_; + xe::mutex allocation_mutex_; // Value that the indirection table will be initialized with upon commit. uint32_t indirection_default_value_; diff --git a/src/xenia/cpu/entry_table.cc b/src/xenia/cpu/entry_table.cc index 618c48d64..da438ba7f 100644 --- a/src/xenia/cpu/entry_table.cc +++ b/src/xenia/cpu/entry_table.cc @@ -18,7 +18,7 @@ namespace cpu { EntryTable::EntryTable() = default; EntryTable::~EntryTable() { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); for (auto it : map_) { Entry* entry = it.second; delete entry; @@ -26,7 +26,7 @@ EntryTable::~EntryTable() { } Entry* EntryTable::Get(uint32_t address) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); const auto& it = map_.find(address); Entry* entry = it != map_.end() ? it->second : nullptr; if (entry) { @@ -74,7 +74,7 @@ Entry::Status EntryTable::GetOrCreate(uint32_t address, Entry** out_entry) { } std::vector EntryTable::FindWithAddress(uint32_t address) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); std::vector fns; for (auto& it : map_) { Entry* entry = it.second; diff --git a/src/xenia/cpu/entry_table.h b/src/xenia/cpu/entry_table.h index 48c8b59f1..3e5a9548f 100644 --- a/src/xenia/cpu/entry_table.h +++ b/src/xenia/cpu/entry_table.h @@ -14,6 +14,8 @@ #include #include +#include "xenia/base/mutex.h" + namespace xe { namespace cpu { @@ -45,7 +47,7 @@ class EntryTable { private: // TODO(benvanik): replace with a better data structure. - std::mutex lock_; + xe::mutex lock_; std::unordered_map map_; }; diff --git a/src/xenia/cpu/frontend/ppc_frontend.cc b/src/xenia/cpu/frontend/ppc_frontend.cc index fe7f01205..990da1b76 100644 --- a/src/xenia/cpu/frontend/ppc_frontend.cc +++ b/src/xenia/cpu/frontend/ppc_frontend.cc @@ -61,7 +61,7 @@ void CheckGlobalLock(PPCContext* ppc_state, void* arg0, void* arg1) { ppc_state->scratch = 0x8000; } void HandleGlobalLock(PPCContext* ppc_state, void* arg0, void* arg1) { - std::mutex* global_lock = reinterpret_cast(arg0); + auto global_lock = reinterpret_cast(arg0); volatile bool* global_lock_taken = reinterpret_cast(arg1); uint64_t value = ppc_state->scratch; if (value == 0x8000) { diff --git a/src/xenia/cpu/frontend/ppc_frontend.h b/src/xenia/cpu/frontend/ppc_frontend.h index 1905517f4..05718caa8 100644 --- a/src/xenia/cpu/frontend/ppc_frontend.h +++ b/src/xenia/cpu/frontend/ppc_frontend.h @@ -13,6 +13,7 @@ #include #include +#include "xenia/base/mutex.h" #include "xenia/base/type_pool.h" #include "xenia/cpu/frontend/context_info.h" #include "xenia/cpu/function.h" @@ -32,7 +33,7 @@ namespace frontend { class PPCTranslator; struct PPCBuiltins { - std::mutex global_lock; + xe::mutex global_lock; bool global_lock_taken; FunctionInfo* check_global_lock; FunctionInfo* handle_global_lock; diff --git a/src/xenia/cpu/function.cc b/src/xenia/cpu/function.cc index 50327b18f..5e5bd7ee0 100644 --- a/src/xenia/cpu/function.cc +++ b/src/xenia/cpu/function.cc @@ -24,7 +24,7 @@ Function::Function(FunctionInfo* symbol_info) Function::~Function() = default; bool Function::AddBreakpoint(Breakpoint* breakpoint) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); bool found = false; for (auto other : breakpoints_) { if (other == breakpoint) { @@ -41,7 +41,7 @@ bool Function::AddBreakpoint(Breakpoint* breakpoint) { } bool Function::RemoveBreakpoint(Breakpoint* breakpoint) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); for (auto it = breakpoints_.begin(); it != breakpoints_.end(); ++it) { if (*it == breakpoint) { if (!RemoveBreakpointImpl(breakpoint)) { @@ -54,7 +54,7 @@ bool Function::RemoveBreakpoint(Breakpoint* breakpoint) { } Breakpoint* Function::FindBreakpoint(uint32_t address) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); Breakpoint* result = nullptr; for (auto breakpoint : breakpoints_) { if (breakpoint->address() == address) { diff --git a/src/xenia/cpu/function.h b/src/xenia/cpu/function.h index 614f87038..17a4744da 100644 --- a/src/xenia/cpu/function.h +++ b/src/xenia/cpu/function.h @@ -14,6 +14,7 @@ #include #include +#include "xenia/base/mutex.h" #include "xenia/cpu/debug_info.h" #include "xenia/cpu/thread_state.h" #include "xenia/debug/breakpoint.h" @@ -53,7 +54,7 @@ class Function { std::unique_ptr debug_info_; // TODO(benvanik): move elsewhere? DebugData? - std::mutex lock_; + xe::mutex lock_; std::vector breakpoints_; }; diff --git a/src/xenia/cpu/mmio_handler.h b/src/xenia/cpu/mmio_handler.h index 70646b85b..11765f007 100644 --- a/src/xenia/cpu/mmio_handler.h +++ b/src/xenia/cpu/mmio_handler.h @@ -15,6 +15,8 @@ #include #include +#include "xenia/base/mutex.h" + namespace xe { namespace cpu { @@ -85,7 +87,7 @@ class MMIOHandler { std::vector mapped_ranges_; // TODO(benvanik): data structure magic. - std::mutex write_watch_mutex_; + xe::mutex write_watch_mutex_; std::list write_watches_; static MMIOHandler* global_handler_; diff --git a/src/xenia/cpu/module.cc b/src/xenia/cpu/module.cc index 932b08d3e..49f4764bf 100644 --- a/src/xenia/cpu/module.cc +++ b/src/xenia/cpu/module.cc @@ -151,7 +151,7 @@ SymbolInfo::Status Module::DefineVariable(VariableInfo* symbol_info) { void Module::ForEachFunction(std::function callback) { SCOPE_profile_cpu_f("cpu"); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); for (auto& symbol_info : list_) { if (symbol_info->type() == SymbolInfo::TYPE_FUNCTION) { FunctionInfo* info = static_cast(symbol_info.get()); @@ -163,7 +163,7 @@ void Module::ForEachFunction(std::function callback) { void Module::ForEachFunction(size_t since, size_t& version, std::function callback) { SCOPE_profile_cpu_f("cpu"); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); size_t count = list_.size(); version = count; for (size_t n = since; n < count; n++) { diff --git a/src/xenia/cpu/module.h b/src/xenia/cpu/module.h index 47ce881ce..b5a15b1df 100644 --- a/src/xenia/cpu/module.h +++ b/src/xenia/cpu/module.h @@ -16,8 +16,9 @@ #include #include -#include "xenia/memory.h" +#include "xenia/base/mutex.h" #include "xenia/cpu/symbol_info.h" +#include "xenia/memory.h" namespace xe { namespace cpu { @@ -62,7 +63,7 @@ class Module { private: // TODO(benvanik): replace with a better data structure. - std::mutex lock_; + xe::mutex lock_; std::unordered_map map_; std::vector> list_; }; diff --git a/src/xenia/cpu/processor.cc b/src/xenia/cpu/processor.cc index e1f8d9a9d..b96cbd6f2 100644 --- a/src/xenia/cpu/processor.cc +++ b/src/xenia/cpu/processor.cc @@ -89,7 +89,7 @@ Processor::~Processor() { } { - std::lock_guard guard(modules_lock_); + std::lock_guard guard(modules_lock_); modules_.clear(); } @@ -159,13 +159,13 @@ bool Processor::Setup() { } bool Processor::AddModule(std::unique_ptr module) { - std::lock_guard guard(modules_lock_); + std::lock_guard guard(modules_lock_); modules_.push_back(std::move(module)); return true; } Module* Processor::GetModule(const char* name) { - std::lock_guard guard(modules_lock_); + std::lock_guard guard(modules_lock_); for (const auto& module : modules_) { if (module->name() == name) { return module.get(); @@ -175,7 +175,7 @@ Module* Processor::GetModule(const char* name) { } std::vector Processor::GetModules() { - std::lock_guard guard(modules_lock_); + std::lock_guard guard(modules_lock_); std::vector clone(modules_.size()); for (const auto& module : modules_) { clone.push_back(module.get()); @@ -242,7 +242,7 @@ bool Processor::LookupFunctionInfo(uint32_t address, // Find the module that contains the address. Module* code_module = nullptr; { - std::lock_guard guard(modules_lock_); + std::lock_guard guard(modules_lock_); // TODO(benvanik): sort by code address (if contiguous) so can bsearch. // TODO(benvanik): cache last module low/high, as likely to be in there. for (const auto& module : modules_) { @@ -378,7 +378,7 @@ uint64_t Processor::ExecuteInterrupt(uint32_t cpu, uint32_t address, SCOPE_profile_cpu_f("cpu"); // Acquire lock on interrupt thread (we can only dispatch one at a time). - std::lock_guard lock(interrupt_thread_lock_); + std::lock_guard lock(interrupt_thread_lock_); // Set 0x10C(r13) to the current CPU ID. xe::store_and_swap( diff --git a/src/xenia/cpu/processor.h b/src/xenia/cpu/processor.h index 6b6496328..f0860ba5f 100644 --- a/src/xenia/cpu/processor.h +++ b/src/xenia/cpu/processor.h @@ -13,6 +13,7 @@ #include #include +#include "xenia/base/mutex.h" #include "xenia/cpu/backend/backend.h" #include "xenia/cpu/entry_table.h" #include "xenia/cpu/export_resolver.h" @@ -90,13 +91,13 @@ class Processor { ExportResolver* export_resolver_; EntryTable entry_table_; - std::mutex modules_lock_; + xe::mutex modules_lock_; std::vector> modules_; Module* builtin_module_; uint32_t next_builtin_address_; Irql irql_; - std::mutex interrupt_thread_lock_; + xe::mutex interrupt_thread_lock_; ThreadState* interrupt_thread_state_; uint32_t interrupt_thread_block_; }; diff --git a/src/xenia/gpu/gl4/texture_cache.cc b/src/xenia/gpu/gl4/texture_cache.cc index e34839590..fe63f3fe7 100644 --- a/src/xenia/gpu/gl4/texture_cache.cc +++ b/src/xenia/gpu/gl4/texture_cache.cc @@ -196,7 +196,7 @@ void TextureCache::EvictAllTextures() { } { - std::lock_guard lock(invalidated_textures_mutex_); + std::lock_guard lock(invalidated_textures_mutex_); invalidated_textures_sets_[0].clear(); invalidated_textures_sets_[1].clear(); } diff --git a/src/xenia/gpu/gl4/texture_cache.h b/src/xenia/gpu/gl4/texture_cache.h index 55fcd4313..5e78fee9e 100644 --- a/src/xenia/gpu/gl4/texture_cache.h +++ b/src/xenia/gpu/gl4/texture_cache.h @@ -14,6 +14,7 @@ #include #include +#include "xenia/base/mutex.h" #include "xenia/gpu/gl4/blitter.h" #include "xenia/gpu/gl4/circular_buffer.h" #include "xenia/gpu/gl4/gl_context.h" @@ -100,7 +101,7 @@ class TextureCache { std::vector read_buffer_textures_; - std::mutex invalidated_textures_mutex_; + xe::mutex invalidated_textures_mutex_; std::vector* invalidated_textures_; std::vector invalidated_textures_sets_[2]; }; diff --git a/src/xenia/kernel/apps/xmp_app.cc b/src/xenia/kernel/apps/xmp_app.cc index a09a6bf56..d0d13c0f0 100644 --- a/src/xenia/kernel/apps/xmp_app.cc +++ b/src/xenia/kernel/apps/xmp_app.cc @@ -81,7 +81,7 @@ X_RESULT XXMPApp::XMPCreateTitlePlaylist( xe::store_and_swap(memory_->TranslateVirtual(out_playlist_handle), playlist->handle); - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); playlists_.insert({playlist->handle, playlist.get()}); playlist.release(); return X_ERROR_SUCCESS; @@ -89,7 +89,7 @@ X_RESULT XXMPApp::XMPCreateTitlePlaylist( X_RESULT XXMPApp::XMPDeleteTitlePlaylist(uint32_t playlist_handle) { XELOGD("XMPDeleteTitlePlaylist(%.8X)", playlist_handle); - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); auto it = playlists_.find(playlist_handle); if (it == playlists_.end()) { XELOGE("Playlist %.8X not found", playlist_handle); @@ -109,7 +109,7 @@ X_RESULT XXMPApp::XMPPlayTitlePlaylist(uint32_t playlist_handle, XELOGD("XMPPlayTitlePlaylist(%.8X, %.8X)", playlist_handle, song_handle); Playlist* playlist = nullptr; { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); auto it = playlists_.find(playlist_handle); if (it == playlists_.end()) { XELOGE("Playlist %.8X not found", playlist_handle); diff --git a/src/xenia/kernel/apps/xmp_app.h b/src/xenia/kernel/apps/xmp_app.h index 66a1a00b7..800781889 100644 --- a/src/xenia/kernel/apps/xmp_app.h +++ b/src/xenia/kernel/apps/xmp_app.h @@ -16,6 +16,7 @@ #include #include +#include "xenia/base/mutex.h" #include "xenia/kernel/app.h" #include "xenia/kernel/kernel_state.h" @@ -101,7 +102,7 @@ class XXMPApp : public XApp { Playlist* active_playlist_; int active_song_index_; - std::mutex mutex_; + xe::mutex mutex_; std::unordered_map playlists_; uint32_t next_playlist_handle_; uint32_t next_song_handle_; diff --git a/src/xenia/kernel/content_manager.cc b/src/xenia/kernel/content_manager.cc index bfe00c8a8..f422652b3 100644 --- a/src/xenia/kernel/content_manager.cc +++ b/src/xenia/kernel/content_manager.cc @@ -120,7 +120,7 @@ std::unique_ptr ContentManager::ResolvePackage( return nullptr; } - std::lock_guard lock(content_mutex_); + std::lock_guard lock(content_mutex_); auto package = std::make_unique(kernel_state_, root_name, data, package_path); @@ -134,7 +134,7 @@ bool ContentManager::ContentExists(const XCONTENT_DATA& data) { X_RESULT ContentManager::CreateContent(std::string root_name, const XCONTENT_DATA& data) { - std::lock_guard lock(content_mutex_); + std::lock_guard lock(content_mutex_); if (open_packages_.count(root_name)) { // Already content open with this root name. @@ -161,7 +161,7 @@ X_RESULT ContentManager::CreateContent(std::string root_name, X_RESULT ContentManager::OpenContent(std::string root_name, const XCONTENT_DATA& data) { - std::lock_guard lock(content_mutex_); + std::lock_guard lock(content_mutex_); if (open_packages_.count(root_name)) { // Already content open with this root name. @@ -184,7 +184,7 @@ X_RESULT ContentManager::OpenContent(std::string root_name, } X_RESULT ContentManager::CloseContent(std::string root_name) { - std::lock_guard lock(content_mutex_); + std::lock_guard lock(content_mutex_); auto it = open_packages_.find(root_name); if (it == open_packages_.end()) { @@ -200,7 +200,7 @@ X_RESULT ContentManager::CloseContent(std::string root_name) { X_RESULT ContentManager::GetContentThumbnail(const XCONTENT_DATA& data, std::vector* buffer) { - std::lock_guard lock(content_mutex_); + std::lock_guard lock(content_mutex_); auto package_path = ResolvePackagePath(data); auto thumb_path = xe::join_paths(package_path, kThumbnailFileName); if (xe::fs::PathExists(thumb_path)) { @@ -219,7 +219,7 @@ X_RESULT ContentManager::GetContentThumbnail(const XCONTENT_DATA& data, X_RESULT ContentManager::SetContentThumbnail(const XCONTENT_DATA& data, std::vector buffer) { - std::lock_guard lock(content_mutex_); + std::lock_guard lock(content_mutex_); auto package_path = ResolvePackagePath(data); if (xe::fs::PathExists(package_path)) { auto thumb_path = xe::join_paths(package_path, kThumbnailFileName); @@ -233,7 +233,7 @@ X_RESULT ContentManager::SetContentThumbnail(const XCONTENT_DATA& data, } X_RESULT ContentManager::DeleteContent(const XCONTENT_DATA& data) { - std::lock_guard lock(content_mutex_); + std::lock_guard lock(content_mutex_); auto package_path = ResolvePackagePath(data); if (xe::fs::PathExists(package_path)) { diff --git a/src/xenia/kernel/content_manager.h b/src/xenia/kernel/content_manager.h index e305843a1..80bd74f98 100644 --- a/src/xenia/kernel/content_manager.h +++ b/src/xenia/kernel/content_manager.h @@ -17,6 +17,7 @@ #include #include "xenia/base/memory.h" +#include "xenia/base/mutex.h" #include "xenia/xbox.h" namespace xe { @@ -87,7 +88,7 @@ class ContentManager { KernelState* kernel_state_; std::wstring root_path_; - std::recursive_mutex content_mutex_; + xe::recursive_mutex content_mutex_; std::unordered_map open_packages_; }; diff --git a/src/xenia/kernel/dispatcher.h b/src/xenia/kernel/dispatcher.h index 0c165ca07..b8af9ea31 100644 --- a/src/xenia/kernel/dispatcher.h +++ b/src/xenia/kernel/dispatcher.h @@ -12,6 +12,7 @@ #include +#include "xenia/base/mutex.h" #include "xenia/xbox.h" namespace xe { @@ -36,7 +37,7 @@ class Dispatcher { private: KernelState* kernel_state_; - std::mutex lock_; + xe::mutex lock_; NativeList* dpc_list_; }; diff --git a/src/xenia/kernel/objects/xnotify_listener.cc b/src/xenia/kernel/objects/xnotify_listener.cc index 650fe5de4..b9f1e8da8 100644 --- a/src/xenia/kernel/objects/xnotify_listener.cc +++ b/src/xenia/kernel/objects/xnotify_listener.cc @@ -42,7 +42,7 @@ void XNotifyListener::EnqueueNotification(XNotificationID id, uint32_t data) { return; } - std::lock_guard lock(lock_); + std::lock_guard lock(lock_); if (notifications_.count(id)) { // Already exists. Overwrite. notifications_[id] = data; @@ -56,7 +56,7 @@ void XNotifyListener::EnqueueNotification(XNotificationID id, uint32_t data) { bool XNotifyListener::DequeueNotification(XNotificationID* out_id, uint32_t* out_data) { - std::lock_guard lock(lock_); + std::lock_guard lock(lock_); bool dequeued = false; if (notification_count_) { dequeued = true; @@ -74,7 +74,7 @@ bool XNotifyListener::DequeueNotification(XNotificationID* out_id, bool XNotifyListener::DequeueNotification(XNotificationID id, uint32_t* out_data) { - std::lock_guard lock(lock_); + std::lock_guard lock(lock_); bool dequeued = false; if (notification_count_) { dequeued = true; diff --git a/src/xenia/kernel/objects/xnotify_listener.h b/src/xenia/kernel/objects/xnotify_listener.h index 581580dbc..53372b42f 100644 --- a/src/xenia/kernel/objects/xnotify_listener.h +++ b/src/xenia/kernel/objects/xnotify_listener.h @@ -13,6 +13,7 @@ #include #include +#include "xenia/base/mutex.h" #include "xenia/kernel/xobject.h" #include "xenia/xbox.h" @@ -36,7 +37,7 @@ class XNotifyListener : public XObject { private: HANDLE wait_handle_; - std::mutex lock_; + xe::mutex lock_; std::unordered_map notifications_; size_t notification_count_; uint64_t mask_; diff --git a/src/xenia/kernel/objects/xthread.cc b/src/xenia/kernel/objects/xthread.cc index fe3b3efc4..561637136 100644 --- a/src/xenia/kernel/objects/xthread.cc +++ b/src/xenia/kernel/objects/xthread.cc @@ -13,6 +13,7 @@ #include "xenia/base/logging.h" #include "xenia/base/math.h" +#include "xenia/base/mutex.h" #include "xenia/base/threading.h" #include "xenia/cpu/cpu.h" #include "xenia/kernel/kernel_state.h" @@ -33,7 +34,7 @@ using namespace xe::cpu; uint32_t next_xthread_id = 0; thread_local XThread* current_thread_tls; -std::mutex critical_region_; +xe::mutex critical_region_; XThread* shared_kernel_thread_ = 0; XThread::XThread(KernelState* kernel_state, uint32_t stack_size, diff --git a/src/xenia/kernel/objects/xthread.h b/src/xenia/kernel/objects/xthread.h index bc7c2a701..7dceb697a 100644 --- a/src/xenia/kernel/objects/xthread.h +++ b/src/xenia/kernel/objects/xthread.h @@ -97,7 +97,7 @@ class XThread : public XObject { std::string name_; std::atomic irql_; - std::mutex apc_lock_; + xe::mutex apc_lock_; NativeList* apc_list_; object_ref event_; diff --git a/src/xenia/kernel/xboxkrnl_ob.cc b/src/xenia/kernel/xboxkrnl_ob.cc index b74a4b676..4893b54a6 100644 --- a/src/xenia/kernel/xboxkrnl_ob.cc +++ b/src/xenia/kernel/xboxkrnl_ob.cc @@ -150,6 +150,7 @@ SHIM_CALL NtDuplicateObject_shim(PPCContext* ppc_state, KernelState* state) { auto object = state->object_table()->LookupObject(handle); if (object) { + object->Retain(); object->RetainHandle(); uint32_t new_handle = object->handle(); if (new_handle_ptr) { diff --git a/src/xenia/kernel/xboxkrnl_threading.cc b/src/xenia/kernel/xboxkrnl_threading.cc index f755ef4e6..b25035952 100644 --- a/src/xenia/kernel/xboxkrnl_threading.cc +++ b/src/xenia/kernel/xboxkrnl_threading.cc @@ -9,6 +9,7 @@ #include "xenia/base/atomic.h" #include "xenia/base/logging.h" +#include "xenia/base/mutex.h" #include "xenia/cpu/processor.h" #include "xenia/kernel/dispatcher.h" #include "xenia/kernel/kernel_state.h" @@ -1290,7 +1291,7 @@ SHIM_CALL KeRemoveQueueDpc_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_64(result ? 1 : 0); } -std::mutex global_list_mutex_; +xe::mutex global_list_mutex_; // http://www.nirsoft.net/kernel_struct/vista/SLIST_HEADER.html SHIM_CALL InterlockedPopEntrySList_shim(PPCContext* ppc_state, @@ -1299,7 +1300,7 @@ SHIM_CALL InterlockedPopEntrySList_shim(PPCContext* ppc_state, XELOGD("InterlockedPopEntrySList(%.8X)", plist_ptr); - std::lock_guard lock(global_list_mutex_); + std::lock_guard lock(global_list_mutex_); uint8_t* p = state->memory()->TranslateVirtual(plist_ptr); auto first = xe::load_and_swap(p); diff --git a/src/xenia/memory.cc b/src/xenia/memory.cc index 7d8be1c55..3eb176e31 100644 --- a/src/xenia/memory.cc +++ b/src/xenia/memory.cc @@ -69,9 +69,7 @@ uint32_t get_page_count(uint32_t value, uint32_t page_size) { static Memory* active_memory_ = nullptr; -void CrashDump() { - active_memory_->DumpMap(); -} +void CrashDump() { active_memory_->DumpMap(); } Memory::Memory() : virtual_membase_(nullptr), @@ -491,7 +489,7 @@ void BaseHeap::Dispose() { } void BaseHeap::DumpMap() { - std::lock_guard lock(heap_mutex_); + std::lock_guard lock(heap_mutex_); XELOGE("------------------------------------------------------------------"); XELOGE("Heap: %.8X-%.8X", heap_base_, heap_base_ + heap_size_); XELOGE("------------------------------------------------------------------"); @@ -565,7 +563,7 @@ bool BaseHeap::AllocFixed(uint32_t base_address, uint32_t size, return false; } - std::lock_guard lock(heap_mutex_); + std::lock_guard lock(heap_mutex_); // - If we are reserving the entire range requested must not be already // reserved. @@ -643,7 +641,7 @@ bool BaseHeap::AllocRange(uint32_t low_address, uint32_t high_address, high_page_number = std::min(uint32_t(page_table_.size()) - 1, high_page_number); - std::lock_guard lock(heap_mutex_); + std::lock_guard lock(heap_mutex_); // Find a free page range. // The base page must match the requested alignment, so we first scan for @@ -765,7 +763,7 @@ bool BaseHeap::Decommit(uint32_t address, uint32_t size) { std::min(uint32_t(page_table_.size()) - 1, start_page_number); end_page_number = std::min(uint32_t(page_table_.size()) - 1, end_page_number); - std::lock_guard lock(heap_mutex_); + std::lock_guard lock(heap_mutex_); // Release from host. // TODO(benvanik): find a way to actually decommit memory; @@ -789,7 +787,7 @@ bool BaseHeap::Decommit(uint32_t address, uint32_t size) { } bool BaseHeap::Release(uint32_t base_address, uint32_t* out_region_size) { - std::lock_guard lock(heap_mutex_); + std::lock_guard lock(heap_mutex_); // Given address must be a region base address. uint32_t base_page_number = (base_address - heap_base_) / page_size_; @@ -844,7 +842,7 @@ bool BaseHeap::Protect(uint32_t address, uint32_t size, uint32_t protect) { std::min(uint32_t(page_table_.size()) - 1, start_page_number); end_page_number = std::min(uint32_t(page_table_.size()) - 1, end_page_number); - std::lock_guard lock(heap_mutex_); + std::lock_guard lock(heap_mutex_); // Ensure all pages are in the same reserved region and all are committed. uint32_t first_base_address = UINT_MAX; @@ -897,7 +895,7 @@ bool BaseHeap::QueryRegionInfo(uint32_t base_address, return false; } - std::lock_guard lock(heap_mutex_); + std::lock_guard lock(heap_mutex_); auto start_page_entry = page_table_[start_page_number]; out_info->base_address = base_address; @@ -948,7 +946,7 @@ bool BaseHeap::QuerySize(uint32_t address, uint32_t* out_size) { *out_size = 0; return false; } - std::lock_guard lock(heap_mutex_); + std::lock_guard lock(heap_mutex_); auto page_entry = page_table_[page_number]; *out_size = page_entry.region_page_count * page_size_; return true; @@ -961,7 +959,7 @@ bool BaseHeap::QueryProtect(uint32_t address, uint32_t* out_protect) { *out_protect = 0; return false; } - std::lock_guard lock(heap_mutex_); + std::lock_guard lock(heap_mutex_); auto page_entry = page_table_[page_number]; *out_protect = page_entry.current_protect; return true; @@ -1009,7 +1007,7 @@ bool PhysicalHeap::Alloc(uint32_t size, uint32_t alignment, size = xe::round_up(size, page_size_); alignment = xe::round_up(alignment, page_size_); - std::lock_guard lock(heap_mutex_); + std::lock_guard lock(heap_mutex_); // Allocate from parent heap (gets our physical address in 0-512mb). uint32_t parent_low_address = GetPhysicalAddress(heap_base_); @@ -1047,7 +1045,7 @@ bool PhysicalHeap::AllocFixed(uint32_t base_address, uint32_t size, size = xe::round_up(size, page_size_); alignment = xe::round_up(alignment, page_size_); - std::lock_guard lock(heap_mutex_); + std::lock_guard lock(heap_mutex_); // Allocate from parent heap (gets our physical address in 0-512mb). // NOTE: this can potentially overwrite heap contents if there are already @@ -1088,7 +1086,7 @@ bool PhysicalHeap::AllocRange(uint32_t low_address, uint32_t high_address, size = xe::round_up(size, page_size_); alignment = xe::round_up(alignment, page_size_); - std::lock_guard lock(heap_mutex_); + std::lock_guard lock(heap_mutex_); // Allocate from parent heap (gets our physical address in 0-512mb). low_address = std::max(heap_base_, low_address); @@ -1122,7 +1120,7 @@ bool PhysicalHeap::AllocRange(uint32_t low_address, uint32_t high_address, } bool PhysicalHeap::Decommit(uint32_t address, uint32_t size) { - std::lock_guard lock(heap_mutex_); + std::lock_guard lock(heap_mutex_); uint32_t parent_address = GetPhysicalAddress(address); if (!parent_heap_->Decommit(parent_address, size)) { XELOGE("PhysicalHeap::Decommit failed due to parent heap failure"); @@ -1132,7 +1130,7 @@ bool PhysicalHeap::Decommit(uint32_t address, uint32_t size) { } bool PhysicalHeap::Release(uint32_t base_address, uint32_t* out_region_size) { - std::lock_guard lock(heap_mutex_); + std::lock_guard lock(heap_mutex_); uint32_t parent_base_address = GetPhysicalAddress(base_address); if (!parent_heap_->Release(parent_base_address, out_region_size)) { XELOGE("PhysicalHeap::Release failed due to parent heap failure"); @@ -1142,7 +1140,7 @@ bool PhysicalHeap::Release(uint32_t base_address, uint32_t* out_region_size) { } bool PhysicalHeap::Protect(uint32_t address, uint32_t size, uint32_t protect) { - std::lock_guard lock(heap_mutex_); + std::lock_guard lock(heap_mutex_); uint32_t parent_address = GetPhysicalAddress(address); bool parent_result = parent_heap_->Protect(parent_address, size, protect); if (!parent_result) { diff --git a/src/xenia/memory.h b/src/xenia/memory.h index f892e5818..47a1a7d37 100644 --- a/src/xenia/memory.h +++ b/src/xenia/memory.h @@ -16,6 +16,7 @@ #include #include +#include "xenia/base/mutex.h" #include "xenia/base/platform.h" #include "xenia/cpu/mmio_handler.h" @@ -115,7 +116,7 @@ class BaseHeap { uint32_t heap_size_; uint32_t page_size_; std::vector page_table_; - std::recursive_mutex heap_mutex_; + xe::recursive_mutex heap_mutex_; }; class VirtualHeap : public BaseHeap {