Big mutex overhaul - remove our custom ones, make them non-recursive where possible

This commit is contained in:
Henrik Rydgard authored and Henrik Rydgård committed 2017-02-28 11:40:29 +01:00
1 parent 54f862cda6
commit 26a2d42731
75 files changed
+561 -882

No files matched your search

+9 -8
View File
@@ -18,7 +18,8 @@
#include <list>
#include <thread>
#include <memory>
#include "base/mutex.h"
#include <mutex>
#include "input/input_state.h"
#include "thread/threadutil.h"
#include "Core/Config.h"
@@ -32,8 +33,8 @@
static volatile bool inputThreadStatus = false;
static volatile bool inputThreadEnabled = false;
static std::thread *inputThread = NULL;
static recursive_mutex inputMutex;
static condition_variable inputEndCond;
static std::mutex inputMutex;
static std::condition_variable inputEndCond;
static bool focused = true;
extern InputState input_state;
@@ -42,7 +43,7 @@ inline static void ExecuteInputPoll() {
// Hm, we may hold the input_state lock for quite a while (time it takes to poll all devices)...
// If that becomes an issue, maybe should poll to a copy of inputstate and only hold the lock while
// copying that one to the real one?
lock_guard guard(input_state.lock);
std::lock_guard<std::mutex> guard(input_state.lock);
input_state.pad_buttons = 0;
input_state.pad_lstick_x = 0;
input_state.pad_lstick_y = 0;
@@ -67,13 +68,13 @@ static void RunInputThread() {
Sleep(4);
}
lock_guard guard(inputMutex);
std::lock_guard<std::mutex> guard(inputMutex);
inputThreadStatus = false;
inputEndCond.notify_one();
}
void InputDevice::BeginPolling() {
lock_guard guard(inputMutex);
std::lock_guard<std::mutex> guard(inputMutex);
inputThreadEnabled = true;
inputThread = new std::thread(&RunInputThread);
inputThread->detach();
@@ -82,9 +83,9 @@ void InputDevice::BeginPolling() {
void InputDevice::StopPolling() {
inputThreadEnabled = false;
lock_guard guard(inputMutex);
std::unique_lock<std::mutex> guard(inputMutex);
if (inputThreadStatus) {
inputEndCond.wait(inputMutex);
inputEndCond.wait(guard);
}
delete inputThread;
inputThread = NULL;