Removing xe_mutex_t.

This commit is contained in:
Ben Vanik
2014-08-16 00:56:50 -07:00
parent 96fb484dd9
commit bca49bed4b
23 changed files with 101 additions and 276 deletions

View File

@@ -16,12 +16,11 @@ using namespace xe::kernel;
XNotifyListener::XNotifyListener(KernelState* kernel_state) :
XObject(kernel_state, kTypeNotifyListener),
wait_handle_(NULL), lock_(0), mask_(0), notification_count_(0) {
wait_handle_(NULL), mask_(0), notification_count_(0) {
}
XNotifyListener::~XNotifyListener() {
kernel_state_->UnregisterNotifyListener(this);
xe_mutex_free(lock_);
if (wait_handle_) {
CloseHandle(wait_handle_);
}
@@ -30,7 +29,6 @@ XNotifyListener::~XNotifyListener() {
void XNotifyListener::Initialize(uint64_t mask) {
assert_null(wait_handle_);
lock_ = xe_mutex_alloc();
wait_handle_ = CreateEvent(NULL, TRUE, FALSE, NULL);
mask_ = mask;
@@ -43,7 +41,7 @@ void XNotifyListener::EnqueueNotification(XNotificationID id, uint32_t data) {
return;
}
xe_mutex_lock(lock_);
std::lock_guard<std::mutex> lock(lock_);
if (notifications_.count(id)) {
// Already exists. Overwrite.
notifications_[id] = data;
@@ -53,13 +51,12 @@ void XNotifyListener::EnqueueNotification(XNotificationID id, uint32_t data) {
notifications_.insert({ id, data });
}
SetEvent(wait_handle_);
xe_mutex_unlock(lock_);
}
bool XNotifyListener::DequeueNotification(
XNotificationID* out_id, uint32_t* out_data) {
std::lock_guard<std::mutex> lock(lock_);
bool dequeued = false;
xe_mutex_lock(lock_);
if (notification_count_) {
dequeued = true;
auto it = notifications_.begin();
@@ -71,14 +68,13 @@ bool XNotifyListener::DequeueNotification(
ResetEvent(wait_handle_);
}
}
xe_mutex_unlock(lock_);
return dequeued;
}
bool XNotifyListener::DequeueNotification(
XNotificationID id, uint32_t* out_data) {
std::lock_guard<std::mutex> lock(lock_);
bool dequeued = false;
xe_mutex_lock(lock_);
if (notification_count_) {
dequeued = true;
auto it = notifications_.find(id);
@@ -91,6 +87,5 @@ bool XNotifyListener::DequeueNotification(
}
}
}
xe_mutex_unlock(lock_);
return dequeued;
}

View File

@@ -13,6 +13,8 @@
#ifndef XENIA_KERNEL_XBOXKRNL_XNOTIFY_LISTENER_H_
#define XENIA_KERNEL_XBOXKRNL_XNOTIFY_LISTENER_H_
#include <mutex>
#include <xenia/kernel/xobject.h>
#include <xenia/xbox.h>
@@ -37,7 +39,7 @@ public:
private:
HANDLE wait_handle_;
xe_mutex_t* lock_;
std::mutex lock_;
std::unordered_map<XNotificationID, uint32_t> notifications_;
size_t notification_count_;
uint64_t mask_;

View File

@@ -26,7 +26,7 @@ using namespace xe::kernel;
namespace {
static uint32_t next_xthread_id = 0;
static thread_local XThread* current_thread_tls;
static xe_mutex_t* critical_region_ = xe_mutex_alloc(10000);
static std::mutex critical_region_;
static XThread* shared_kernel_thread_ = 0;
}
@@ -58,7 +58,6 @@ XThread::XThread(KernelState* kernel_state,
creation_params_.stack_size = 16 * 1024;
}
apc_lock_ = xe_mutex_alloc();
apc_list_ = new NativeList(kernel_state->memory());
event_ = new XEvent(kernel_state);
@@ -79,7 +78,6 @@ XThread::~XThread() {
kernel_state_->UnregisterThread(this);
delete apc_list_;
xe_mutex_free(apc_lock_);
event_->Release();
@@ -421,11 +419,11 @@ void XThread::Execute() {
void XThread::EnterCriticalRegion() {
// Global critical region. This isn't right, but is easy.
xe_mutex_lock(critical_region_);
critical_region_.lock();
}
void XThread::LeaveCriticalRegion() {
xe_mutex_unlock(critical_region_);
critical_region_.unlock();
}
uint32_t XThread::RaiseIrql(uint32_t new_irql) {
@@ -437,12 +435,12 @@ void XThread::LowerIrql(uint32_t new_irql) {
}
void XThread::LockApc() {
xe_mutex_lock(apc_lock_);
apc_lock_.lock();
}
void XThread::UnlockApc() {
bool needs_apc = apc_list_->HasPending();
xe_mutex_unlock(apc_lock_);
apc_lock_.unlock();
if (needs_apc) {
QueueUserAPC(reinterpret_cast<PAPCFUNC>(DeliverAPCs),
thread_handle_,

View File

@@ -11,6 +11,7 @@
#define XENIA_KERNEL_XBOXKRNL_XTHREAD_H_
#include <atomic>
#include <mutex>
#include <xenia/kernel/xobject.h>
@@ -98,7 +99,7 @@ private:
char* name_;
std::atomic<uint32_t> irql_;
xe_mutex_t* apc_lock_;
std::mutex apc_lock_;
NativeList* apc_list_;
XEvent* event_;