Switch back to std:: muteces. mutices. mutexen.

This commit is contained in:
Ben Vanik
2015-09-06 13:34:08 -07:00
parent cb3dbcccbc
commit 790ce8aee1
17 changed files with 49 additions and 58 deletions

View File

@@ -11,8 +11,8 @@
namespace xe {
xe::recursive_mutex& global_critical_region::mutex() {
static xe::recursive_mutex global_mutex;
std::recursive_mutex& global_critical_region::mutex() {
static std::recursive_mutex global_mutex;
return global_mutex;
}

View File

@@ -14,13 +14,6 @@
namespace xe {
// 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.
using mutex = std::mutex;
using recursive_mutex = std::recursive_mutex;
// The global critical region mutex singleton.
// This must guard any operation that may suspend threads or be sensitive to
// being suspended such as global table locks and such.
@@ -44,7 +37,7 @@ using recursive_mutex = std::recursive_mutex;
// [thread 0]:
// DoKernelStuff():
// auto global_lock = global_critical_region_.Acquire();
// std::lock_guard<xe::mutex> table_lock(table_mutex_);
// std::lock_guard<std::mutex> table_lock(table_mutex_);
// table_->InsertStuff();
// [thread 1]:
// MySuspendThread():
@@ -61,25 +54,25 @@ using recursive_mutex = std::recursive_mutex;
// };
class global_critical_region {
public:
static xe::recursive_mutex& mutex();
static std::recursive_mutex& mutex();
// Acquires a lock on the global critical section.
// Use this when keeping an instance is not possible. Otherwise, prefer
// to keep an instance of global_critical_region near the members requiring
// it to keep things readable.
static std::unique_lock<xe::recursive_mutex> AcquireDirect() {
return std::unique_lock<xe::recursive_mutex>(mutex());
static std::unique_lock<std::recursive_mutex> AcquireDirect() {
return std::unique_lock<std::recursive_mutex>(mutex());
}
// Acquires a lock on the global critical section.
inline std::unique_lock<xe::recursive_mutex> Acquire() {
return std::unique_lock<xe::recursive_mutex>(mutex());
inline std::unique_lock<std::recursive_mutex> Acquire() {
return std::unique_lock<std::recursive_mutex>(mutex());
}
// Tries to acquire a lock on the glboal critical section.
// Check owns_lock() to see if the lock was successfully acquired.
inline std::unique_lock<xe::recursive_mutex> TryAcquire() {
return std::unique_lock<xe::recursive_mutex>(mutex(), std::try_to_lock);
inline std::unique_lock<std::recursive_mutex> TryAcquire() {
return std::unique_lock<std::recursive_mutex>(mutex(), std::try_to_lock);
}
};

View File

@@ -13,8 +13,6 @@
#include <mutex>
#include <vector>
#include "xenia/base/mutex.h"
namespace xe {
template <class T, typename A>
@@ -23,7 +21,7 @@ class TypePool {
~TypePool() { Reset(); }
void Reset() {
std::lock_guard<xe::mutex> guard(lock_);
std::lock_guard<std::mutex> guard(lock_);
for (auto it = list_.begin(); it != list_.end(); ++it) {
T* value = *it;
delete value;
@@ -34,7 +32,7 @@ class TypePool {
T* Allocate(A arg0) {
T* result = 0;
{
std::lock_guard<xe::mutex> guard(lock_);
std::lock_guard<std::mutex> guard(lock_);
if (list_.size()) {
result = list_.back();
list_.pop_back();
@@ -47,12 +45,12 @@ class TypePool {
}
void Release(T* value) {
std::lock_guard<xe::mutex> guard(lock_);
std::lock_guard<std::mutex> guard(lock_);
list_.push_back(value);
}
private:
xe::mutex lock_;
std::mutex lock_;
std::vector<T*> list_;
};