Switching to standard mutex for now (but keeping xe::mutex).

This commit is contained in:
Ben Vanik 2015-07-13 21:49:32 -07:00
parent 72ad899e9e
commit 40621a90bd
10 changed files with 16 additions and 73 deletions

View File

@ -10,82 +10,16 @@
#ifndef XENIA_BASE_MUTEX_H_ #ifndef XENIA_BASE_MUTEX_H_
#define XENIA_BASE_MUTEX_H_ #define XENIA_BASE_MUTEX_H_
#include <atomic>
#include <mutex> #include <mutex>
#include <type_traits>
#include "xenia/base/platform_win.h"
namespace xe { namespace xe {
// This type should be interchangable with std::mutex, only it provides the // This exists to allow us to swap the mutex implementation with one that
// ability to resume threads that hold the lock when the debugger needs it. // we can mess with in the debugger (such as allowing the debugger to ignore
class mutex { // locks while all threads are suspended). std::mutex should not be used.
public:
mutex(int _Flags = 0) noexcept {
_Mtx_init_in_situ(_Mymtx(), _Flags | _Mtx_try);
}
~mutex() noexcept { _Mtx_destroy_in_situ(_Mymtx()); } using mutex = std::mutex;
using recursive_mutex = std::recursive_mutex;
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;
};
} // namespace xe } // namespace xe

View File

@ -9,6 +9,7 @@
#include "xenia/cpu/hir/hir_builder.h" #include "xenia/cpu/hir/hir_builder.h"
#include <cstdarg>
#include <cstring> #include <cstring>
#include "xenia/base/assert.h" #include "xenia/base/assert.h"

View File

@ -13,6 +13,7 @@
#include "xenia/base/byte_order.h" #include "xenia/base/byte_order.h"
#include "xenia/base/math.h" #include "xenia/base/math.h"
#include "xenia/base/memory.h" #include "xenia/base/memory.h"
#include "xenia/base/platform_win.h"
namespace BE { namespace BE {
#include <beaengine/BeaEngine.h> #include <beaengine/BeaEngine.h>

View File

@ -9,7 +9,7 @@
#include "xenia/cpu/mmio_handler.h" #include "xenia/cpu/mmio_handler.h"
#include "xenia/base/platform.h" #include "xenia/base/platform_win.h"
#include "xenia/profiling.h" #include "xenia/profiling.h"
namespace xe { namespace xe {

View File

@ -9,6 +9,7 @@
#include "xenia/kernel/objects/xnotify_listener.h" #include "xenia/kernel/objects/xnotify_listener.h"
#include "xenia/base/platform_win.h"
#include "xenia/kernel/kernel_state.h" #include "xenia/kernel/kernel_state.h"
namespace xe { namespace xe {

View File

@ -17,6 +17,8 @@
#include "xenia/kernel/xobject.h" #include "xenia/kernel/xobject.h"
#include "xenia/xbox.h" #include "xenia/xbox.h"
typedef void* HANDLE;
namespace xe { namespace xe {
namespace kernel { namespace kernel {

View File

@ -15,7 +15,7 @@
#include <thread> #include <thread>
#include "xenia/base/mutex.h" #include "xenia/base/mutex.h"
#include "xenia/base/platform.h" #include "xenia/base/platform_win.h"
#include "xenia/base/threading.h" #include "xenia/base/threading.h"
#include "xenia/ui/loop.h" #include "xenia/ui/loop.h"

View File

@ -12,6 +12,7 @@
#include "xenia/base/logging.h" #include "xenia/base/logging.h"
#include "xenia/base/mapped_memory.h" #include "xenia/base/mapped_memory.h"
#include "xenia/base/math.h" #include "xenia/base/math.h"
#include "xenia/base/platform_win.h"
#include "xenia/base/string.h" #include "xenia/base/string.h"
#include "xenia/vfs/devices/host_path_file.h" #include "xenia/vfs/devices/host_path_file.h"

View File

@ -9,6 +9,7 @@
#include "xenia/vfs/devices/host_path_file.h" #include "xenia/vfs/devices/host_path_file.h"
#include "xenia/base/platform_win.h"
#include "xenia/vfs/devices/host_path_entry.h" #include "xenia/vfs/devices/host_path_entry.h"
namespace xe { namespace xe {

View File

@ -14,6 +14,8 @@
#include "xenia/kernel/objects/xfile.h" #include "xenia/kernel/objects/xfile.h"
typedef void* HANDLE;
namespace xe { namespace xe {
namespace vfs { namespace vfs {