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_
#define XENIA_BASE_MUTEX_H_
#include <atomic>
#include <mutex>
#include <type_traits>
#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

View File

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

View File

@ -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 <beaengine/BeaEngine.h>

View File

@ -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 {

View File

@ -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 {

View File

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

View File

@ -15,7 +15,7 @@
#include <thread>
#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"

View File

@ -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"

View File

@ -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 {

View File

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