Skip to content

Commit

Permalink
Standardize on just one mutex implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Mar 6, 2016
1 parent 955b0fb commit da03b80
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 40 deletions.
10 changes: 5 additions & 5 deletions Common/LogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const
if (level > log->GetLevel() || !log->IsEnabled() || !log->HasListeners())
return;

std::lock_guard<std::mutex> lk(log_lock_);
lock_guard lk(log_lock_);
static const char level_to_char[8] = "-NEWIDV";
char formattedTime[13];
Common::Timer::GetTimeFormatted(formattedTime);
Expand Down Expand Up @@ -266,13 +266,13 @@ LogChannel::LogChannel(const char* shortName, const char* fullName, bool enable)

// LogContainer
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_hasListeners = true;
}

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_hasListeners = !m_listeners.empty();
}
Expand All @@ -281,7 +281,7 @@ void LogChannel::Trigger(LogTypes::LOG_LEVELS level, const char *msg) {
#ifdef __SYMBIAN32__
RDebug::Printf("%s",msg);
#else
std::lock_guard<std::mutex> lk(m_listeners_lock);
lock_guard lk(m_listeners_lock);

std::set<LogListener*>::const_iterator i;
for (i = m_listeners.begin(); i != m_listeners.end(); ++i) {
Expand All @@ -303,7 +303,7 @@ void FileLogListener::Log(LogTypes::LOG_LEVELS, const char *msg) {
if (!IsEnabled() || !IsValid())
return;

std::lock_guard<std::mutex> lk(m_log_lock);
lock_guard lk(m_log_lock);
m_logfile << msg << std::flush;
}

Expand Down
13 changes: 6 additions & 7 deletions Common/LogManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@

#pragma once

#include <set>
#include "base/mutex.h"
#include "file/ini_file.h"
#include "Log.h"
#include "StringUtils.h"
#include "FileUtil.h"
#include "file/ini_file.h"

#include <set>
#include "StdMutex.h"

#define MAX_MESSAGES 8000
#define MAX_MSGLEN 1024
Expand Down Expand Up @@ -51,7 +50,7 @@ class FileLogListener : public LogListener {
const char* GetName() const { return "file"; }

private:
std::mutex m_log_lock;
recursive_mutex m_log_lock;
std::ofstream m_logfile;
bool m_enable;
};
Expand Down Expand Up @@ -113,7 +112,7 @@ class LogChannel {
private:
char m_fullName[128];
char m_shortName[32];
std::mutex m_listeners_lock;
recursive_mutex m_listeners_lock;
std::set<LogListener*> m_listeners;
bool m_hasListeners;
};
Expand All @@ -128,7 +127,7 @@ class LogManager : NonCopyable {
DebuggerLogListener *debuggerLog_;
RingbufferLogListener *ringLog_;
static LogManager *logManager_; // Singleton. Ugh.
std::mutex log_lock_;
recursive_mutex log_lock_;

LogManager();
~LogManager();
Expand Down
18 changes: 9 additions & 9 deletions Core/CoreTiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#include <cstdio>

#include "base/logging.h"
#include "base/mutex.h"
#include "profiler/profiler.h"

#include "Common/MsgHandler.h"
#include "Common/StdMutex.h"
#include "Common/Atomics.h"
#include "Core/CoreTiming.h"
#include "Core/Core.h"
Expand Down Expand Up @@ -86,7 +86,7 @@ s64 idledCycles;
s64 lastGlobalTimeTicks;
s64 lastGlobalTimeUs;

static std::recursive_mutex externalEventSection;
static recursive_mutex externalEventSection;

// Warning: not included in save state.
void (*advanceCallback)(int cyclesExecuted) = NULL;
Expand Down Expand Up @@ -228,7 +228,7 @@ void Shutdown()
delete ev;
}

std::lock_guard<std::recursive_mutex> lk(externalEventSection);
lock_guard lk(externalEventSection);
while(eventTsPool)
{
Event *ev = eventTsPool;
Expand All @@ -252,7 +252,7 @@ u64 GetIdleTicks()
// schedule things to be executed on the main thread.
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();
ne->time = GetTicks() + cyclesIntoFuture;
ne->type = event_type;
Expand All @@ -273,7 +273,7 @@ void ScheduleEvent_Threadsafe_Immediate(int event_type, u64 userdata)
{
if(false) //Core::IsCPUThread())
{
std::lock_guard<std::recursive_mutex> lk(externalEventSection);
lock_guard lk(externalEventSection);
event_types[event_type].callback(userdata, 0);
}
else
Expand Down Expand Up @@ -368,7 +368,7 @@ s64 UnscheduleEvent(int event_type, u64 userdata)
s64 UnscheduleThreadsafeEvent(int event_type, u64 userdata)
{
s64 result = 0;
std::lock_guard<std::recursive_mutex> lk(externalEventSection);
lock_guard lk(externalEventSection);
if (!tsFirst)
return result;
while(tsFirst)
Expand Down Expand Up @@ -478,7 +478,7 @@ void RemoveEvent(int event_type)

void RemoveThreadsafeEvent(int event_type)
{
std::lock_guard<std::recursive_mutex> lk(externalEventSection);
lock_guard lk(externalEventSection);
if (!tsFirst)
{
return;
Expand Down Expand Up @@ -552,7 +552,7 @@ void MoveEvents()
{
Common::AtomicStoreRelease(hasTsEvents, 0);

std::lock_guard<std::recursive_mutex> lk(externalEventSection);
lock_guard lk(externalEventSection);
// Move events from async queue into main queue
while (tsFirst)
{
Expand Down Expand Up @@ -692,7 +692,7 @@ void Event_DoStateOld(PointerWrap &p, BaseEvent *ev)

void DoState(PointerWrap &p)
{
std::lock_guard<std::recursive_mutex> lk(externalEventSection);
lock_guard lk(externalEventSection);

auto s = p.Section("CoreTiming", 1, 3);
if (!s)
Expand Down
22 changes: 11 additions & 11 deletions Core/HLE/sceCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#include <math.h>
#include "base/mutex.h"
#include "Globals.h"
#include "Core/HLE/HLE.h"
#include "Core/HLE/FunctionWrappers.h"
#include "Core/MIPS/MIPS.h"
#include "Core/CoreTiming.h"
#include "Core/MemMapHelpers.h"
#include "Common/ChunkFile.h"
#include "Common/StdMutex.h"
#include "Core/HLE/sceCtrl.h"
#include "Core/HLE/sceDisplay.h"
#include "Core/HLE/sceKernel.h"
Expand Down Expand Up @@ -84,7 +84,7 @@ static int ctrlIdleBack = -1;
static int ctrlCycle = 0;

static std::vector<SceUID> waitingThreads;
static std::recursive_mutex ctrlMutex;
static recursive_mutex ctrlMutex;

static int ctrlTimer = -1;

Expand All @@ -101,7 +101,7 @@ const u32 CTRL_EMU_RAPIDFIRE_MASK = CTRL_UP | CTRL_DOWN | CTRL_LEFT | CTRL_RIGHT

static void __CtrlUpdateLatch()
{
std::lock_guard<std::recursive_mutex> guard(ctrlMutex);
lock_guard guard(ctrlMutex);

// Copy in the current data to the current buffer.
ctrlBufs[ctrlBuf] = ctrlCurrent;
Expand Down Expand Up @@ -144,14 +144,14 @@ static int __CtrlResetLatch()

u32 __CtrlPeekButtons()
{
std::lock_guard<std::recursive_mutex> guard(ctrlMutex);
lock_guard guard(ctrlMutex);

return ctrlCurrent.buttons;
}

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;
*y = -(ctrlCurrent.analog[stick][CTRL_ANALOG_Y] - 127.5f) / 127.5f;
Expand All @@ -170,27 +170,27 @@ u32 __CtrlReadLatch()

void __CtrlButtonDown(u32 buttonBit)
{
std::lock_guard<std::recursive_mutex> guard(ctrlMutex);
lock_guard guard(ctrlMutex);
ctrlCurrent.buttons |= buttonBit;
}

void __CtrlButtonUp(u32 buttonBit)
{
std::lock_guard<std::recursive_mutex> guard(ctrlMutex);
lock_guard guard(ctrlMutex);
ctrlCurrent.buttons &= ~buttonBit;
}

void __CtrlSetAnalogX(float x, int stick)
{
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;
}

void __CtrlSetAnalogY(float y, int stick)
{
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;
}

Expand Down Expand Up @@ -304,7 +304,7 @@ void __CtrlInit()
ctrlIdleBack = -1;
ctrlCycle = 0;

std::lock_guard<std::recursive_mutex> guard(ctrlMutex);
lock_guard guard(ctrlMutex);

ctrlBuf = 1;
ctrlBufRead = 0;
Expand All @@ -326,7 +326,7 @@ void __CtrlInit()

void __CtrlDoState(PointerWrap &p)
{
std::lock_guard<std::recursive_mutex> guard(ctrlMutex);
lock_guard guard(ctrlMutex);

auto s = p.Section("sceCtrl", 1, 3);
if (!s)
Expand Down
11 changes: 6 additions & 5 deletions Core/SaveState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#include <algorithm>
#include <vector>

#include "base/mutex.h"
#include "base/timeutil.h"
#include "base/NativeApp.h"
#include "i18n/i18n.h"

#include "Common/StdMutex.h"
#include "Common/FileUtil.h"
#include "Common/ChunkFile.h"

Expand Down Expand Up @@ -206,7 +207,7 @@ namespace SaveState

static bool needsProcess = false;
static std::vector<Operation> pending;
static std::recursive_mutex mutex;
static recursive_mutex mutex;
static bool hasLoadedState = false;

// TODO: Should this be configurable?
Expand Down Expand Up @@ -250,7 +251,7 @@ namespace SaveState

void Enqueue(SaveState::Operation op)
{
std::lock_guard<std::recursive_mutex> guard(mutex);
lock_guard guard(mutex);
pending.push_back(op);

// Don't actually run it until next frame.
Expand Down Expand Up @@ -486,7 +487,7 @@ namespace SaveState

std::vector<Operation> Flush()
{
std::lock_guard<std::recursive_mutex> guard(mutex);
lock_guard guard(mutex);
std::vector<Operation> copy = pending;
pending.clear();

Expand Down Expand Up @@ -670,7 +671,7 @@ namespace SaveState
// Make sure there's a directory for save slots
pspFileSystem.MkDir("ms0:/PSP/PPSSPP_STATE");

std::lock_guard<std::recursive_mutex> guard(mutex);
lock_guard guard(mutex);
rewindStates.Clear();

hasLoadedState = false;
Expand Down
2 changes: 1 addition & 1 deletion UI/OnScreenDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void OnScreenMessages::Clean() {

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();
std::lock_guard<std::recursive_mutex> guard(mutex_);
lock_guard guard(mutex_);
if (checkUnique) {
for (auto iter = messages_.begin(); iter != messages_.end(); ++iter) {
if (iter->text == text || (id && iter->id && !strcmp(iter->id, id))) {
Expand Down
4 changes: 2 additions & 2 deletions UI/OnScreenDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <string>
#include <list>

#include "base/mutex.h"
#include "base/basictypes.h"
#include "math/geom2d.h"
#include "Common/StdMutex.h"

#include "ui/view.h"

Expand Down Expand Up @@ -39,7 +39,7 @@ class OnScreenMessages {
private:

std::list<Message> messages_;
std::recursive_mutex mutex_;
recursive_mutex mutex_;
};

class OnScreenMessagesView : public UI::InertView {
Expand Down
2 changes: 2 additions & 0 deletions ext/native/base/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#undef p
#undef DrawText
#undef itoa
#undef min
#undef max

#else
#include <pthread.h>
Expand Down

0 comments on commit da03b80

Please sign in to comment.