Standardize on just one mutex implementation.

This commit is contained in:
Unknown W. Brackets 2016-03-06 13:30:31 -08:00
parent 955b0fb9db
commit da03b80c97
8 changed files with 42 additions and 40 deletions

View file

@ -187,7 +187,7 @@ void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const
if (level > log->GetLevel() || !log->IsEnabled() || !log->HasListeners()) if (level > log->GetLevel() || !log->IsEnabled() || !log->HasListeners())
return; return;
std::lock_guard<std::mutex> lk(log_lock_); lock_guard lk(log_lock_);
static const char level_to_char[8] = "-NEWIDV"; static const char level_to_char[8] = "-NEWIDV";
char formattedTime[13]; char formattedTime[13];
Common::Timer::GetTimeFormatted(formattedTime); Common::Timer::GetTimeFormatted(formattedTime);
@ -266,13 +266,13 @@ LogChannel::LogChannel(const char* shortName, const char* fullName, bool enable)
// LogContainer // LogContainer
void LogChannel::AddListener(LogListener *listener) { void LogChannel::AddListener(LogListener *listener) {
std::lock_guard<std::mutex> lk(m_listeners_lock); lock_guard lk(m_listeners_lock);
m_listeners.insert(listener); m_listeners.insert(listener);
m_hasListeners = true; m_hasListeners = true;
} }
void LogChannel::RemoveListener(LogListener *listener) { void LogChannel::RemoveListener(LogListener *listener) {
std::lock_guard<std::mutex> lk(m_listeners_lock); lock_guard lk(m_listeners_lock);
m_listeners.erase(listener); m_listeners.erase(listener);
m_hasListeners = !m_listeners.empty(); m_hasListeners = !m_listeners.empty();
} }
@ -281,7 +281,7 @@ void LogChannel::Trigger(LogTypes::LOG_LEVELS level, const char *msg) {
#ifdef __SYMBIAN32__ #ifdef __SYMBIAN32__
RDebug::Printf("%s",msg); RDebug::Printf("%s",msg);
#else #else
std::lock_guard<std::mutex> lk(m_listeners_lock); lock_guard lk(m_listeners_lock);
std::set<LogListener*>::const_iterator i; std::set<LogListener*>::const_iterator i;
for (i = m_listeners.begin(); i != m_listeners.end(); ++i) { for (i = m_listeners.begin(); i != m_listeners.end(); ++i) {
@ -303,7 +303,7 @@ void FileLogListener::Log(LogTypes::LOG_LEVELS, const char *msg) {
if (!IsEnabled() || !IsValid()) if (!IsEnabled() || !IsValid())
return; return;
std::lock_guard<std::mutex> lk(m_log_lock); lock_guard lk(m_log_lock);
m_logfile << msg << std::flush; m_logfile << msg << std::flush;
} }

View file

@ -17,13 +17,12 @@
#pragma once #pragma once
#include <set>
#include "base/mutex.h"
#include "file/ini_file.h"
#include "Log.h" #include "Log.h"
#include "StringUtils.h" #include "StringUtils.h"
#include "FileUtil.h" #include "FileUtil.h"
#include "file/ini_file.h"
#include <set>
#include "StdMutex.h"
#define MAX_MESSAGES 8000 #define MAX_MESSAGES 8000
#define MAX_MSGLEN 1024 #define MAX_MSGLEN 1024
@ -51,7 +50,7 @@ public:
const char* GetName() const { return "file"; } const char* GetName() const { return "file"; }
private: private:
std::mutex m_log_lock; recursive_mutex m_log_lock;
std::ofstream m_logfile; std::ofstream m_logfile;
bool m_enable; bool m_enable;
}; };
@ -113,7 +112,7 @@ public:
private: private:
char m_fullName[128]; char m_fullName[128];
char m_shortName[32]; char m_shortName[32];
std::mutex m_listeners_lock; recursive_mutex m_listeners_lock;
std::set<LogListener*> m_listeners; std::set<LogListener*> m_listeners;
bool m_hasListeners; bool m_hasListeners;
}; };
@ -128,7 +127,7 @@ private:
DebuggerLogListener *debuggerLog_; DebuggerLogListener *debuggerLog_;
RingbufferLogListener *ringLog_; RingbufferLogListener *ringLog_;
static LogManager *logManager_; // Singleton. Ugh. static LogManager *logManager_; // Singleton. Ugh.
std::mutex log_lock_; recursive_mutex log_lock_;
LogManager(); LogManager();
~LogManager(); ~LogManager();

View file

@ -20,10 +20,10 @@
#include <cstdio> #include <cstdio>
#include "base/logging.h" #include "base/logging.h"
#include "base/mutex.h"
#include "profiler/profiler.h" #include "profiler/profiler.h"
#include "Common/MsgHandler.h" #include "Common/MsgHandler.h"
#include "Common/StdMutex.h"
#include "Common/Atomics.h" #include "Common/Atomics.h"
#include "Core/CoreTiming.h" #include "Core/CoreTiming.h"
#include "Core/Core.h" #include "Core/Core.h"
@ -86,7 +86,7 @@ s64 idledCycles;
s64 lastGlobalTimeTicks; s64 lastGlobalTimeTicks;
s64 lastGlobalTimeUs; s64 lastGlobalTimeUs;
static std::recursive_mutex externalEventSection; static recursive_mutex externalEventSection;
// Warning: not included in save state. // Warning: not included in save state.
void (*advanceCallback)(int cyclesExecuted) = NULL; void (*advanceCallback)(int cyclesExecuted) = NULL;
@ -228,7 +228,7 @@ void Shutdown()
delete ev; delete ev;
} }
std::lock_guard<std::recursive_mutex> lk(externalEventSection); lock_guard lk(externalEventSection);
while(eventTsPool) while(eventTsPool)
{ {
Event *ev = eventTsPool; Event *ev = eventTsPool;
@ -252,7 +252,7 @@ u64 GetIdleTicks()
// schedule things to be executed on the main thread. // schedule things to be executed on the main thread.
void ScheduleEvent_Threadsafe(s64 cyclesIntoFuture, int event_type, u64 userdata) void ScheduleEvent_Threadsafe(s64 cyclesIntoFuture, int event_type, u64 userdata)
{ {
std::lock_guard<std::recursive_mutex> lk(externalEventSection); lock_guard lk(externalEventSection);
Event *ne = GetNewTsEvent(); Event *ne = GetNewTsEvent();
ne->time = GetTicks() + cyclesIntoFuture; ne->time = GetTicks() + cyclesIntoFuture;
ne->type = event_type; ne->type = event_type;
@ -273,7 +273,7 @@ void ScheduleEvent_Threadsafe_Immediate(int event_type, u64 userdata)
{ {
if(false) //Core::IsCPUThread()) if(false) //Core::IsCPUThread())
{ {
std::lock_guard<std::recursive_mutex> lk(externalEventSection); lock_guard lk(externalEventSection);
event_types[event_type].callback(userdata, 0); event_types[event_type].callback(userdata, 0);
} }
else else
@ -368,7 +368,7 @@ s64 UnscheduleEvent(int event_type, u64 userdata)
s64 UnscheduleThreadsafeEvent(int event_type, u64 userdata) s64 UnscheduleThreadsafeEvent(int event_type, u64 userdata)
{ {
s64 result = 0; s64 result = 0;
std::lock_guard<std::recursive_mutex> lk(externalEventSection); lock_guard lk(externalEventSection);
if (!tsFirst) if (!tsFirst)
return result; return result;
while(tsFirst) while(tsFirst)
@ -478,7 +478,7 @@ void RemoveEvent(int event_type)
void RemoveThreadsafeEvent(int event_type) void RemoveThreadsafeEvent(int event_type)
{ {
std::lock_guard<std::recursive_mutex> lk(externalEventSection); lock_guard lk(externalEventSection);
if (!tsFirst) if (!tsFirst)
{ {
return; return;
@ -552,7 +552,7 @@ void MoveEvents()
{ {
Common::AtomicStoreRelease(hasTsEvents, 0); Common::AtomicStoreRelease(hasTsEvents, 0);
std::lock_guard<std::recursive_mutex> lk(externalEventSection); lock_guard lk(externalEventSection);
// Move events from async queue into main queue // Move events from async queue into main queue
while (tsFirst) while (tsFirst)
{ {
@ -692,7 +692,7 @@ void Event_DoStateOld(PointerWrap &p, BaseEvent *ev)
void DoState(PointerWrap &p) void DoState(PointerWrap &p)
{ {
std::lock_guard<std::recursive_mutex> lk(externalEventSection); lock_guard lk(externalEventSection);
auto s = p.Section("CoreTiming", 1, 3); auto s = p.Section("CoreTiming", 1, 3);
if (!s) if (!s)

View file

@ -17,6 +17,7 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <math.h> #include <math.h>
#include "base/mutex.h"
#include "Globals.h" #include "Globals.h"
#include "Core/HLE/HLE.h" #include "Core/HLE/HLE.h"
#include "Core/HLE/FunctionWrappers.h" #include "Core/HLE/FunctionWrappers.h"
@ -24,7 +25,6 @@
#include "Core/CoreTiming.h" #include "Core/CoreTiming.h"
#include "Core/MemMapHelpers.h" #include "Core/MemMapHelpers.h"
#include "Common/ChunkFile.h" #include "Common/ChunkFile.h"
#include "Common/StdMutex.h"
#include "Core/HLE/sceCtrl.h" #include "Core/HLE/sceCtrl.h"
#include "Core/HLE/sceDisplay.h" #include "Core/HLE/sceDisplay.h"
#include "Core/HLE/sceKernel.h" #include "Core/HLE/sceKernel.h"
@ -84,7 +84,7 @@ static int ctrlIdleBack = -1;
static int ctrlCycle = 0; static int ctrlCycle = 0;
static std::vector<SceUID> waitingThreads; static std::vector<SceUID> waitingThreads;
static std::recursive_mutex ctrlMutex; static recursive_mutex ctrlMutex;
static int ctrlTimer = -1; static int ctrlTimer = -1;
@ -101,7 +101,7 @@ const u32 CTRL_EMU_RAPIDFIRE_MASK = CTRL_UP | CTRL_DOWN | CTRL_LEFT | CTRL_RIGHT
static void __CtrlUpdateLatch() static void __CtrlUpdateLatch()
{ {
std::lock_guard<std::recursive_mutex> guard(ctrlMutex); lock_guard guard(ctrlMutex);
// Copy in the current data to the current buffer. // Copy in the current data to the current buffer.
ctrlBufs[ctrlBuf] = ctrlCurrent; ctrlBufs[ctrlBuf] = ctrlCurrent;
@ -144,14 +144,14 @@ static int __CtrlResetLatch()
u32 __CtrlPeekButtons() u32 __CtrlPeekButtons()
{ {
std::lock_guard<std::recursive_mutex> guard(ctrlMutex); lock_guard guard(ctrlMutex);
return ctrlCurrent.buttons; return ctrlCurrent.buttons;
} }
void __CtrlPeekAnalog(int stick, float *x, float *y) void __CtrlPeekAnalog(int stick, float *x, float *y)
{ {
std::lock_guard<std::recursive_mutex> guard(ctrlMutex); lock_guard guard(ctrlMutex);
*x = (ctrlCurrent.analog[stick][CTRL_ANALOG_X] - 127.5f) / 127.5f; *x = (ctrlCurrent.analog[stick][CTRL_ANALOG_X] - 127.5f) / 127.5f;
*y = -(ctrlCurrent.analog[stick][CTRL_ANALOG_Y] - 127.5f) / 127.5f; *y = -(ctrlCurrent.analog[stick][CTRL_ANALOG_Y] - 127.5f) / 127.5f;
@ -170,27 +170,27 @@ u32 __CtrlReadLatch()
void __CtrlButtonDown(u32 buttonBit) void __CtrlButtonDown(u32 buttonBit)
{ {
std::lock_guard<std::recursive_mutex> guard(ctrlMutex); lock_guard guard(ctrlMutex);
ctrlCurrent.buttons |= buttonBit; ctrlCurrent.buttons |= buttonBit;
} }
void __CtrlButtonUp(u32 buttonBit) void __CtrlButtonUp(u32 buttonBit)
{ {
std::lock_guard<std::recursive_mutex> guard(ctrlMutex); lock_guard guard(ctrlMutex);
ctrlCurrent.buttons &= ~buttonBit; ctrlCurrent.buttons &= ~buttonBit;
} }
void __CtrlSetAnalogX(float x, int stick) void __CtrlSetAnalogX(float x, int stick)
{ {
u8 scaled = clamp_u8((int)ceilf(x * 127.5f + 127.5f)); u8 scaled = clamp_u8((int)ceilf(x * 127.5f + 127.5f));
std::lock_guard<std::recursive_mutex> guard(ctrlMutex); lock_guard guard(ctrlMutex);
ctrlCurrent.analog[stick][CTRL_ANALOG_X] = scaled; ctrlCurrent.analog[stick][CTRL_ANALOG_X] = scaled;
} }
void __CtrlSetAnalogY(float y, int stick) void __CtrlSetAnalogY(float y, int stick)
{ {
u8 scaled = clamp_u8((int)ceilf(-y * 127.5f + 127.5f)); u8 scaled = clamp_u8((int)ceilf(-y * 127.5f + 127.5f));
std::lock_guard<std::recursive_mutex> guard(ctrlMutex); lock_guard guard(ctrlMutex);
ctrlCurrent.analog[stick][CTRL_ANALOG_Y] = scaled; ctrlCurrent.analog[stick][CTRL_ANALOG_Y] = scaled;
} }
@ -304,7 +304,7 @@ void __CtrlInit()
ctrlIdleBack = -1; ctrlIdleBack = -1;
ctrlCycle = 0; ctrlCycle = 0;
std::lock_guard<std::recursive_mutex> guard(ctrlMutex); lock_guard guard(ctrlMutex);
ctrlBuf = 1; ctrlBuf = 1;
ctrlBufRead = 0; ctrlBufRead = 0;
@ -326,7 +326,7 @@ void __CtrlInit()
void __CtrlDoState(PointerWrap &p) void __CtrlDoState(PointerWrap &p)
{ {
std::lock_guard<std::recursive_mutex> guard(ctrlMutex); lock_guard guard(ctrlMutex);
auto s = p.Section("sceCtrl", 1, 3); auto s = p.Section("sceCtrl", 1, 3);
if (!s) if (!s)

View file

@ -15,13 +15,14 @@
// Official git repository and contact information can be found at // Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <algorithm>
#include <vector> #include <vector>
#include "base/mutex.h"
#include "base/timeutil.h" #include "base/timeutil.h"
#include "base/NativeApp.h" #include "base/NativeApp.h"
#include "i18n/i18n.h" #include "i18n/i18n.h"
#include "Common/StdMutex.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/ChunkFile.h" #include "Common/ChunkFile.h"
@ -206,7 +207,7 @@ namespace SaveState
static bool needsProcess = false; static bool needsProcess = false;
static std::vector<Operation> pending; static std::vector<Operation> pending;
static std::recursive_mutex mutex; static recursive_mutex mutex;
static bool hasLoadedState = false; static bool hasLoadedState = false;
// TODO: Should this be configurable? // TODO: Should this be configurable?
@ -250,7 +251,7 @@ namespace SaveState
void Enqueue(SaveState::Operation op) void Enqueue(SaveState::Operation op)
{ {
std::lock_guard<std::recursive_mutex> guard(mutex); lock_guard guard(mutex);
pending.push_back(op); pending.push_back(op);
// Don't actually run it until next frame. // Don't actually run it until next frame.
@ -486,7 +487,7 @@ namespace SaveState
std::vector<Operation> Flush() std::vector<Operation> Flush()
{ {
std::lock_guard<std::recursive_mutex> guard(mutex); lock_guard guard(mutex);
std::vector<Operation> copy = pending; std::vector<Operation> copy = pending;
pending.clear(); pending.clear();
@ -670,7 +671,7 @@ namespace SaveState
// Make sure there's a directory for save slots // Make sure there's a directory for save slots
pspFileSystem.MkDir("ms0:/PSP/PPSSPP_STATE"); pspFileSystem.MkDir("ms0:/PSP/PPSSPP_STATE");
std::lock_guard<std::recursive_mutex> guard(mutex); lock_guard guard(mutex);
rewindStates.Clear(); rewindStates.Clear();
hasLoadedState = false; hasLoadedState = false;

View file

@ -55,7 +55,7 @@ restart:
void OnScreenMessages::Show(const std::string &text, float duration_s, uint32_t color, int icon, bool checkUnique, const char *id) { void OnScreenMessages::Show(const std::string &text, float duration_s, uint32_t color, int icon, bool checkUnique, const char *id) {
double now = time_now_d(); double now = time_now_d();
std::lock_guard<std::recursive_mutex> guard(mutex_); lock_guard guard(mutex_);
if (checkUnique) { if (checkUnique) {
for (auto iter = messages_.begin(); iter != messages_.end(); ++iter) { for (auto iter = messages_.begin(); iter != messages_.end(); ++iter) {
if (iter->text == text || (id && iter->id && !strcmp(iter->id, id))) { if (iter->text == text || (id && iter->id && !strcmp(iter->id, id))) {

View file

@ -3,9 +3,9 @@
#include <string> #include <string>
#include <list> #include <list>
#include "base/mutex.h"
#include "base/basictypes.h" #include "base/basictypes.h"
#include "math/geom2d.h" #include "math/geom2d.h"
#include "Common/StdMutex.h"
#include "ui/view.h" #include "ui/view.h"
@ -39,7 +39,7 @@ public:
private: private:
std::list<Message> messages_; std::list<Message> messages_;
std::recursive_mutex mutex_; recursive_mutex mutex_;
}; };
class OnScreenMessagesView : public UI::InertView { class OnScreenMessagesView : public UI::InertView {

View file

@ -19,6 +19,8 @@
#undef p #undef p
#undef DrawText #undef DrawText
#undef itoa #undef itoa
#undef min
#undef max
#else #else
#include <pthread.h> #include <pthread.h>