From 40621a90bdcf48ee3a99719c1395a7cc19550d7e Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Mon, 13 Jul 2015 21:49:32 -0700 Subject: [PATCH] Switching to standard mutex for now (but keeping xe::mutex). --- src/xenia/base/mutex.h | 76 ++------------------ src/xenia/cpu/hir/hir_builder.cc | 1 + src/xenia/cpu/mmio_handler.cc | 1 + src/xenia/cpu/mmio_handler_win.cc | 2 +- src/xenia/kernel/objects/xnotify_listener.cc | 1 + src/xenia/kernel/objects/xnotify_listener.h | 2 + src/xenia/ui/loop_win.h | 2 +- src/xenia/vfs/devices/host_path_entry.cc | 1 + src/xenia/vfs/devices/host_path_file.cc | 1 + src/xenia/vfs/devices/host_path_file.h | 2 + 10 files changed, 16 insertions(+), 73 deletions(-) diff --git a/src/xenia/base/mutex.h b/src/xenia/base/mutex.h index 61d7eca74..2b72b97f1 100644 --- a/src/xenia/base/mutex.h +++ b/src/xenia/base/mutex.h @@ -10,82 +10,16 @@ #ifndef XENIA_BASE_MUTEX_H_ #define XENIA_BASE_MUTEX_H_ -#include #include -#include - -#include "xenia/base/platform_win.h" namespace xe { -// This type should be interchangable with std::mutex, only it provides the -// ability to resume threads that hold the lock when the debugger needs it. -class mutex { - public: - mutex(int _Flags = 0) noexcept { - _Mtx_init_in_situ(_Mymtx(), _Flags | _Mtx_try); - } +// This exists to allow us to swap the mutex implementation with one that +// we can mess with in the debugger (such as allowing the debugger to ignore +// locks while all threads are suspended). std::mutex should not be used. - ~mutex() noexcept { _Mtx_destroy_in_situ(_Mymtx()); } - - mutex(const mutex&) = delete; - mutex& operator=(const mutex&) = delete; - - void lock() { - _Mtx_lock(_Mymtx()); - holding_thread_ = ::GetCurrentThread(); - } - - bool try_lock() { - if (_Mtx_trylock(_Mymtx()) == _Thrd_success) { - holding_thread_ = ::GetCurrentThread(); - return true; - } - return false; - } - - void lock_as_debugger() { - if (_Mtx_trylock(_Mymtx()) == _Thrd_success) { - // Nothing holding it. - return; - } - // Resume the thread holding it, which will unlock and suspend itself. - debugger_waiting_ = true; - ResumeThread(holding_thread_); - lock(); - debugger_waiting_ = false; - } - - void unlock() { - bool debugger_waiting = debugger_waiting_; - _Mtx_unlock(_Mymtx()); - if (debugger_waiting) { - SuspendThread(nullptr); - } - } - - typedef void* native_handle_type; - - native_handle_type native_handle() { return (_Mtx_getconcrtcs(_Mymtx())); } - - private: - std::aligned_storage<_Mtx_internal_imp_size, - _Mtx_internal_imp_alignment>::type _Mtx_storage; - HANDLE holding_thread_ = nullptr; - bool debugger_waiting_ = false; - - _Mtx_t _Mymtx() noexcept { return (reinterpret_cast<_Mtx_t>(&_Mtx_storage)); } -}; - -class recursive_mutex : public mutex { - public: - recursive_mutex() : mutex(_Mtx_recursive) {} - - bool try_lock() noexcept { return mutex::try_lock(); } - - recursive_mutex(const recursive_mutex&) = delete; - recursive_mutex& operator=(const recursive_mutex&) = delete; -}; +using mutex = std::mutex; +using recursive_mutex = std::recursive_mutex; } // namespace xe diff --git a/src/xenia/cpu/hir/hir_builder.cc b/src/xenia/cpu/hir/hir_builder.cc index 000a5ce10..1a3c21168 100644 --- a/src/xenia/cpu/hir/hir_builder.cc +++ b/src/xenia/cpu/hir/hir_builder.cc @@ -9,6 +9,7 @@ #include "xenia/cpu/hir/hir_builder.h" +#include #include #include "xenia/base/assert.h" diff --git a/src/xenia/cpu/mmio_handler.cc b/src/xenia/cpu/mmio_handler.cc index 95f5a2e54..1f38be10b 100644 --- a/src/xenia/cpu/mmio_handler.cc +++ b/src/xenia/cpu/mmio_handler.cc @@ -13,6 +13,7 @@ #include "xenia/base/byte_order.h" #include "xenia/base/math.h" #include "xenia/base/memory.h" +#include "xenia/base/platform_win.h" namespace BE { #include diff --git a/src/xenia/cpu/mmio_handler_win.cc b/src/xenia/cpu/mmio_handler_win.cc index cff291977..ebe8f81fe 100644 --- a/src/xenia/cpu/mmio_handler_win.cc +++ b/src/xenia/cpu/mmio_handler_win.cc @@ -9,7 +9,7 @@ #include "xenia/cpu/mmio_handler.h" -#include "xenia/base/platform.h" +#include "xenia/base/platform_win.h" #include "xenia/profiling.h" namespace xe { diff --git a/src/xenia/kernel/objects/xnotify_listener.cc b/src/xenia/kernel/objects/xnotify_listener.cc index 70e8367c9..7700d6793 100644 --- a/src/xenia/kernel/objects/xnotify_listener.cc +++ b/src/xenia/kernel/objects/xnotify_listener.cc @@ -9,6 +9,7 @@ #include "xenia/kernel/objects/xnotify_listener.h" +#include "xenia/base/platform_win.h" #include "xenia/kernel/kernel_state.h" namespace xe { diff --git a/src/xenia/kernel/objects/xnotify_listener.h b/src/xenia/kernel/objects/xnotify_listener.h index 53372b42f..1f18e0048 100644 --- a/src/xenia/kernel/objects/xnotify_listener.h +++ b/src/xenia/kernel/objects/xnotify_listener.h @@ -17,6 +17,8 @@ #include "xenia/kernel/xobject.h" #include "xenia/xbox.h" +typedef void* HANDLE; + namespace xe { namespace kernel { diff --git a/src/xenia/ui/loop_win.h b/src/xenia/ui/loop_win.h index c9732378f..236aaa13a 100644 --- a/src/xenia/ui/loop_win.h +++ b/src/xenia/ui/loop_win.h @@ -15,7 +15,7 @@ #include #include "xenia/base/mutex.h" -#include "xenia/base/platform.h" +#include "xenia/base/platform_win.h" #include "xenia/base/threading.h" #include "xenia/ui/loop.h" diff --git a/src/xenia/vfs/devices/host_path_entry.cc b/src/xenia/vfs/devices/host_path_entry.cc index ec013c40c..1d238187f 100644 --- a/src/xenia/vfs/devices/host_path_entry.cc +++ b/src/xenia/vfs/devices/host_path_entry.cc @@ -12,6 +12,7 @@ #include "xenia/base/logging.h" #include "xenia/base/mapped_memory.h" #include "xenia/base/math.h" +#include "xenia/base/platform_win.h" #include "xenia/base/string.h" #include "xenia/vfs/devices/host_path_file.h" diff --git a/src/xenia/vfs/devices/host_path_file.cc b/src/xenia/vfs/devices/host_path_file.cc index 07fa83f7e..9eef179da 100644 --- a/src/xenia/vfs/devices/host_path_file.cc +++ b/src/xenia/vfs/devices/host_path_file.cc @@ -9,6 +9,7 @@ #include "xenia/vfs/devices/host_path_file.h" +#include "xenia/base/platform_win.h" #include "xenia/vfs/devices/host_path_entry.h" namespace xe { diff --git a/src/xenia/vfs/devices/host_path_file.h b/src/xenia/vfs/devices/host_path_file.h index e26eddb21..5b3374d1c 100644 --- a/src/xenia/vfs/devices/host_path_file.h +++ b/src/xenia/vfs/devices/host_path_file.h @@ -14,6 +14,8 @@ #include "xenia/kernel/objects/xfile.h" +typedef void* HANDLE; + namespace xe { namespace vfs {