Merge pull request #9366 from hrydgard/thread-cleanup-2

Get rid of our custom mutex and condvar implementations too
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2017-02-28 12:24:24 +01:00
commit fb0b82f6e8
76 files changed
+567 -883

No files matched your search

-1
View File
@@ -792,7 +792,6 @@ add_library(native STATIC
ext/native/base/display.h
ext/native/base/linked_ptr.h
ext/native/base/logging.h
ext/native/base/mutex.h
ext/native/base/stringutil.cpp
ext/native/base/stringutil.h
ext/native/base/timeutil.cpp
+5 -5
View File
@@ -184,7 +184,7 @@ void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const
if (level > log->GetLevel() || !log->IsEnabled() || !log->HasListeners())
return;
lock_guard lk(log_lock_);
std::lock_guard<std::mutex> lk(log_lock_);
static const char level_to_char[8] = "-NEWIDV";
char formattedTime[13];
Common::Timer::GetTimeFormatted(formattedTime);
@@ -263,19 +263,19 @@ LogChannel::LogChannel(const char* shortName, const char* fullName, bool enable)
// LogContainer
void LogChannel::AddListener(LogListener *listener) {
lock_guard lk(m_listeners_lock);
std::lock_guard<std::mutex> lk(m_listeners_lock);
m_listeners.insert(listener);
m_hasListeners = true;
}
void LogChannel::RemoveListener(LogListener *listener) {
lock_guard lk(m_listeners_lock);
std::lock_guard<std::mutex> lk(m_listeners_lock);
m_listeners.erase(listener);
m_hasListeners = !m_listeners.empty();
}
void LogChannel::Trigger(LogTypes::LOG_LEVELS level, const char *msg) {
lock_guard lk(m_listeners_lock);
std::lock_guard<std::mutex> lk(m_listeners_lock);
std::set<LogListener*>::const_iterator i;
for (i = m_listeners.begin(); i != m_listeners.end(); ++i) {
@@ -296,7 +296,7 @@ void FileLogListener::Log(LogTypes::LOG_LEVELS, const char *msg) {
if (!IsEnabled() || !IsValid())
return;
lock_guard lk(m_log_lock);
std::lock_guard<std::mutex> lk(m_log_lock);
m_logfile << msg << std::flush;
}
+4 -4
View File
@@ -18,7 +18,7 @@
#pragma once
#include <set>
#include "base/mutex.h"
#include <mutex>
#include "file/ini_file.h"
#include "Log.h"
#include "StringUtils.h"
@@ -50,7 +50,7 @@ public:
const char* GetName() const { return "file"; }
private:
recursive_mutex m_log_lock;
std::mutex m_log_lock;
std::ofstream m_logfile;
bool m_enable;
};
@@ -112,7 +112,7 @@ public:
private:
char m_fullName[128];
char m_shortName[32];
recursive_mutex m_listeners_lock;
std::mutex m_listeners_lock;
std::set<LogListener*> m_listeners;
bool m_hasListeners;
};
@@ -127,7 +127,7 @@ private:
DebuggerLogListener *debuggerLog_;
RingbufferLogListener *ringLog_;
static LogManager *logManager_; // Singleton. Ugh.
recursive_mutex log_lock_;
std::mutex log_lock_;
LogManager();
~LogManager();
+11 -11
View File
@@ -26,7 +26,7 @@ public:
explicit ThreadSafeList(std::size_t n, const T &v = T(), const Alloc &a = Alloc()) : list(n, v, a) {}
ThreadSafeList(const std::list<T, Alloc> &other) : list(other) {}
ThreadSafeList(const ThreadSafeList &other) {
lock_guard guard(other.lock);
std::lock_guard<std::mutex> guard(other.lock);
list.assign(other.list);
}
@@ -34,52 +34,52 @@ public:
ThreadSafeList(Iter first, Iter last, const Alloc &a = Alloc()) : list(first, last, a) {}
inline T front() const {
lock_guard guard(lock);
std::lock_guard<std::mutex> guard(lock);
return list.front();
}
inline void pop_front() {
lock_guard guard(lock);
std::lock_guard<std::mutex> guard(lock);
return list.pop_front();
}
inline void push_front(const T &v) {
lock_guard guard(lock);
std::lock_guard<std::mutex> guard(lock);
return list.push_front(v);
}
inline T back() const {
lock_guard guard(lock);
std::lock_guard<std::mutex> guard(lock);
return list.back();
}
inline void pop_back() {
lock_guard guard(lock);
std::lock_guard<std::mutex> guard(lock);
return list.pop_back();
}
inline void push_back(const T &v) {
lock_guard guard(lock);
std::lock_guard<std::mutex> guard(lock);
return list.push_back(v);
}
bool empty() const {
lock_guard guard(lock);
std::lock_guard<std::mutex> guard(lock);
return list.empty();
}
inline void clear() {
lock_guard guard(lock);
std::lock_guard<std::mutex> guard(lock);
return list.clear();
}
void DoState(PointerWrap &p) {
lock_guard guard(lock);
std::lock_guard<std::mutex> guard(lock);
p.Do(list);
}
private:
mutable recursive_mutex lock;
mutable std::mutex lock;
std::list<T, Alloc> list;
};
+5 -4
View File
@@ -18,12 +18,13 @@
#include "ppsspp_config.h"
#include <set>
#include <mutex>
#include "base/NativeApp.h"
#include "base/display.h"
#include "base/mutex.h"
#include "base/timeutil.h"
#include "input/input_state.h"
#include "thread/threadutil.h"
#include "profiler/profiler.h"
#include "Core/Core.h"
@@ -47,9 +48,9 @@
static const double ACTIVITY_IDLE_TIMEOUT = 2.0 * 3600.0;
static event m_hStepEvent;
static recursive_mutex m_hStepMutex;
static std::mutex m_hStepMutex;
static event m_hInactiveEvent;
static recursive_mutex m_hInactiveMutex;
static std::mutex m_hInactiveMutex;
static bool singleStepPending = false;
static std::set<Core_ShutdownFunc> shutdownFuncs;
static bool windowHidden = false;
@@ -198,7 +199,7 @@ void UpdateRunLoop(InputState *input_state) {
NativeUpdate(*input_state);
{
lock_guard guard(input_state->lock);
std::lock_guard<std::mutex> guard(input_state->lock);
EndInputState(input_state);
}
+9 -9
View File
@@ -18,9 +18,9 @@
#include <vector>
#include <cstdio>
#include <mutex>
#include "base/logging.h"
#include "base/mutex.h"
#include "profiler/profiler.h"
#include "Common/MsgHandler.h"
@@ -86,7 +86,7 @@ s64 idledCycles;
s64 lastGlobalTimeTicks;
s64 lastGlobalTimeUs;
static recursive_mutex externalEventSection;
static std::mutex externalEventLock;
std::vector<MHzChangeCallback> mhzChangeCallbacks;
@@ -226,7 +226,7 @@ void Shutdown()
delete ev;
}
lock_guard lk(externalEventSection);
std::lock_guard<std::mutex> lk(externalEventLock);
while(eventTsPool)
{
Event *ev = eventTsPool;
@@ -250,7 +250,7 @@ u64 GetIdleTicks()
// schedule things to be executed on the main thread.
void ScheduleEvent_Threadsafe(s64 cyclesIntoFuture, int event_type, u64 userdata)
{
lock_guard lk(externalEventSection);
std::lock_guard<std::mutex> lk(externalEventLock);
Event *ne = GetNewTsEvent();
ne->time = GetTicks() + cyclesIntoFuture;
ne->type = event_type;
@@ -271,7 +271,7 @@ void ScheduleEvent_Threadsafe_Immediate(int event_type, u64 userdata)
{
if(false) //Core::IsCPUThread())
{
lock_guard lk(externalEventSection);
std::lock_guard<std::mutex> lk(externalEventLock);
event_types[event_type].callback(userdata, 0);
}
else
@@ -366,7 +366,7 @@ s64 UnscheduleEvent(int event_type, u64 userdata)
s64 UnscheduleThreadsafeEvent(int event_type, u64 userdata)
{
s64 result = 0;
lock_guard lk(externalEventSection);
std::lock_guard<std::mutex> lk(externalEventLock);
if (!tsFirst)
return result;
while(tsFirst)
@@ -470,7 +470,7 @@ void RemoveEvent(int event_type)
void RemoveThreadsafeEvent(int event_type)
{
lock_guard lk(externalEventSection);
std::lock_guard<std::mutex> lk(externalEventLock);
if (!tsFirst)
{
return;
@@ -544,7 +544,7 @@ void MoveEvents()
{
Common::AtomicStoreRelease(hasTsEvents, 0);
lock_guard lk(externalEventSection);
std::lock_guard<std::mutex> lk(externalEventLock);
// Move events from async queue into main queue
while (tsFirst)
{
@@ -682,7 +682,7 @@ void Event_DoStateOld(PointerWrap &p, BaseEvent *ev)
void DoState(PointerWrap &p)
{
lock_guard lk(externalEventSection);
std::lock_guard<std::mutex> lk(externalEventLock);
auto s = p.Section("CoreTiming", 1, 3);
if (!s)
+41 -41
View File
@@ -42,13 +42,13 @@
SymbolMap *g_symbolMap;
void SymbolMap::SortSymbols() {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
AssignFunctionIndices();
}
void SymbolMap::Clear() {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
functions.clear();
labels.clear();
data.clear();
@@ -62,7 +62,7 @@ void SymbolMap::Clear() {
bool SymbolMap::LoadSymbolMap(const char *filename) {
Clear(); // let's not recurse the lock
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
#if defined(_WIN32) && defined(UNICODE)
gzFile f = gzopen_w(ConvertUTF8ToWString(filename).c_str(), "r");
@@ -181,7 +181,7 @@ bool SymbolMap::LoadSymbolMap(const char *filename) {
}
void SymbolMap::SaveSymbolMap(const char *filename) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
// Don't bother writing a blank file.
if (!File::Exists(filename) && functions.empty() && data.empty()) {
@@ -217,7 +217,7 @@ void SymbolMap::SaveSymbolMap(const char *filename) const {
}
bool SymbolMap::LoadNocashSym(const char *filename) {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
FILE *f = File::OpenCFile(filename, "r");
if (!f)
return false;
@@ -275,7 +275,7 @@ bool SymbolMap::LoadNocashSym(const char *filename) {
}
void SymbolMap::SaveNocashSym(const char *filename) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
// Don't bother writing a blank file.
if (!File::Exists(filename) && functions.empty() && data.empty()) {
@@ -296,7 +296,7 @@ void SymbolMap::SaveNocashSym(const char *filename) const {
}
SymbolType SymbolMap::GetSymbolType(u32 address) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
if (activeFunctions.find(address) != activeFunctions.end())
return ST_FUNCTION;
if (activeData.find(address) != activeData.end())
@@ -343,7 +343,7 @@ bool SymbolMap::GetSymbolInfo(SymbolInfo *info, u32 address, SymbolType symmask)
}
u32 SymbolMap::GetNextSymbolAddress(u32 address, SymbolType symmask) {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
const auto functionEntry = symmask & ST_FUNCTION ? activeFunctions.upper_bound(address) : activeFunctions.end();
const auto dataEntry = symmask & ST_DATA ? activeData.upper_bound(address) : activeData.end();
@@ -360,7 +360,7 @@ u32 SymbolMap::GetNextSymbolAddress(u32 address, SymbolType symmask) {
}
std::string SymbolMap::GetDescription(unsigned int address) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
const char* labelName = NULL;
u32 funcStart = GetFunctionStart(address);
@@ -384,7 +384,7 @@ std::vector<SymbolEntry> SymbolMap::GetAllSymbols(SymbolType symmask) {
std::vector<SymbolEntry> result;
if (symmask & ST_FUNCTION) {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
for (auto it = activeFunctions.begin(); it != activeFunctions.end(); it++) {
SymbolEntry entry;
entry.address = it->first;
@@ -397,7 +397,7 @@ std::vector<SymbolEntry> SymbolMap::GetAllSymbols(SymbolType symmask) {
}
if (symmask & ST_DATA) {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
for (auto it = activeData.begin(); it != activeData.end(); it++) {
SymbolEntry entry;
entry.address = it->first;
@@ -413,7 +413,7 @@ std::vector<SymbolEntry> SymbolMap::GetAllSymbols(SymbolType symmask) {
}
void SymbolMap::AddModule(const char *name, u32 address, u32 size) {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
for (auto it = modules.begin(), end = modules.end(); it != end; ++it) {
if (!strcmp(it->name, name)) {
@@ -439,13 +439,13 @@ void SymbolMap::AddModule(const char *name, u32 address, u32 size) {
}
void SymbolMap::UnloadModule(u32 address, u32 size) {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
activeModuleEnds.erase(address + size);
UpdateActiveSymbols();
}
u32 SymbolMap::GetModuleRelativeAddr(u32 address, int moduleIndex) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
if (moduleIndex == -1) {
moduleIndex = GetModuleIndex(address);
}
@@ -459,7 +459,7 @@ u32 SymbolMap::GetModuleRelativeAddr(u32 address, int moduleIndex) const {
}
u32 SymbolMap::GetModuleAbsoluteAddr(u32 relative, int moduleIndex) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
for (auto it = modules.begin(), end = modules.end(); it != end; ++it) {
if (it->index == moduleIndex) {
return it->start + relative;
@@ -469,7 +469,7 @@ u32 SymbolMap::GetModuleAbsoluteAddr(u32 relative, int moduleIndex) const {
}
int SymbolMap::GetModuleIndex(u32 address) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
auto iter = activeModuleEnds.upper_bound(address);
if (iter == activeModuleEnds.end())
return -1;
@@ -481,7 +481,7 @@ bool SymbolMap::IsModuleActive(int moduleIndex) const {
return true;
}
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
for (auto it = activeModuleEnds.begin(), end = activeModuleEnds.end(); it != end; ++it) {
if (it->second.index == moduleIndex) {
return true;
@@ -491,7 +491,7 @@ bool SymbolMap::IsModuleActive(int moduleIndex) const {
}
std::vector<LoadedModuleInfo> SymbolMap::getAllModules() const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
std::vector<LoadedModuleInfo> result;
for (size_t i = 0; i < modules.size(); i++) {
@@ -510,7 +510,7 @@ std::vector<LoadedModuleInfo> SymbolMap::getAllModules() const {
}
void SymbolMap::AddFunction(const char* name, u32 address, u32 size, int moduleIndex) {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
if (moduleIndex == -1) {
moduleIndex = GetModuleIndex(address);
@@ -560,7 +560,7 @@ void SymbolMap::AddFunction(const char* name, u32 address, u32 size, int moduleI
}
u32 SymbolMap::GetFunctionStart(u32 address) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
auto it = activeFunctions.upper_bound(address);
if (it == activeFunctions.end()) {
// check last element
@@ -587,7 +587,7 @@ u32 SymbolMap::GetFunctionStart(u32 address) const {
}
u32 SymbolMap::FindPossibleFunctionAtAfter(u32 address) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
auto it = activeFunctions.lower_bound(address);
if (it == activeFunctions.end()) {
return (u32)-1;
@@ -596,7 +596,7 @@ u32 SymbolMap::FindPossibleFunctionAtAfter(u32 address) const {
}
u32 SymbolMap::GetFunctionSize(u32 startAddress) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
auto it = activeFunctions.find(startAddress);
if (it == activeFunctions.end())
return INVALID_ADDRESS;
@@ -605,7 +605,7 @@ u32 SymbolMap::GetFunctionSize(u32 startAddress) const {
}
u32 SymbolMap::GetFunctionModuleAddress(u32 startAddress) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
auto it = activeFunctions.find(startAddress);
if (it == activeFunctions.end())
return INVALID_ADDRESS;
@@ -614,7 +614,7 @@ u32 SymbolMap::GetFunctionModuleAddress(u32 startAddress) const {
}
int SymbolMap::GetFunctionNum(u32 address) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
u32 start = GetFunctionStart(address);
if (start == INVALID_ADDRESS)
return INVALID_ADDRESS;
@@ -627,7 +627,7 @@ int SymbolMap::GetFunctionNum(u32 address) const {
}
void SymbolMap::AssignFunctionIndices() {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
int index = 0;
for (auto mod = activeModuleEnds.begin(), modend = activeModuleEnds.end(); mod != modend; ++mod) {
int moduleIndex = mod->second.index;
@@ -641,7 +641,7 @@ void SymbolMap::AssignFunctionIndices() {
void SymbolMap::UpdateActiveSymbols() {
// return; (slow in debug mode)
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
activeFunctions.clear();
activeLabels.clear();
@@ -688,7 +688,7 @@ void SymbolMap::UpdateActiveSymbols() {
}
bool SymbolMap::SetFunctionSize(u32 startAddress, u32 newSize) {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
auto funcInfo = activeFunctions.find(startAddress);
if (funcInfo != activeFunctions.end()) {
@@ -705,7 +705,7 @@ bool SymbolMap::SetFunctionSize(u32 startAddress, u32 newSize) {
}
bool SymbolMap::RemoveFunction(u32 startAddress, bool removeName) {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
auto it = activeFunctions.find(startAddress);
if (it == activeFunctions.end())
@@ -734,7 +734,7 @@ bool SymbolMap::RemoveFunction(u32 startAddress, bool removeName) {
}
void SymbolMap::AddLabel(const char* name, u32 address, int moduleIndex) {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
if (moduleIndex == -1) {
moduleIndex = GetModuleIndex(address);
@@ -783,7 +783,7 @@ void SymbolMap::AddLabel(const char* name, u32 address, int moduleIndex) {
}
void SymbolMap::SetLabelName(const char* name, u32 address) {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
auto labelInfo = activeLabels.find(address);
if (labelInfo == activeLabels.end()) {
AddLabel(name, address);
@@ -805,7 +805,7 @@ void SymbolMap::SetLabelName(const char* name, u32 address) {
}
const char *SymbolMap::GetLabelName(u32 address) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
auto it = activeLabels.find(address);
if (it == activeLabels.end())
return NULL;
@@ -814,7 +814,7 @@ const char *SymbolMap::GetLabelName(u32 address) const {
}
const char *SymbolMap::GetLabelNameRel(u32 relAddress, int moduleIndex) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
auto it = labels.find(std::make_pair(moduleIndex, relAddress));
if (it == labels.end())
return NULL;
@@ -823,7 +823,7 @@ const char *SymbolMap::GetLabelNameRel(u32 relAddress, int moduleIndex) const {
}
std::string SymbolMap::GetLabelString(u32 address) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
const char *label = GetLabelName(address);
if (label == NULL)
return "";
@@ -831,7 +831,7 @@ std::string SymbolMap::GetLabelString(u32 address) const {
}
bool SymbolMap::GetLabelValue(const char* name, u32& dest) {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
for (auto it = activeLabels.begin(); it != activeLabels.end(); it++) {
if (strcasecmp(name, it->second.name) == 0) {
dest = it->first;
@@ -843,7 +843,7 @@ bool SymbolMap::GetLabelValue(const char* name, u32& dest) {
}
void SymbolMap::AddData(u32 address, u32 size, DataType type, int moduleIndex) {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
if (moduleIndex == -1) {
moduleIndex = GetModuleIndex(address);
@@ -892,7 +892,7 @@ void SymbolMap::AddData(u32 address, u32 size, DataType type, int moduleIndex) {
}
u32 SymbolMap::GetDataStart(u32 address) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
auto it = activeData.upper_bound(address);
if (it == activeData.end())
{
@@ -922,7 +922,7 @@ u32 SymbolMap::GetDataStart(u32 address) const {
}
u32 SymbolMap::GetDataSize(u32 startAddress) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
auto it = activeData.find(startAddress);
if (it == activeData.end())
return INVALID_ADDRESS;
@@ -930,7 +930,7 @@ u32 SymbolMap::GetDataSize(u32 startAddress) const {
}
u32 SymbolMap::GetDataModuleAddress(u32 startAddress) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
auto it = activeData.find(startAddress);
if (it == activeData.end())
return INVALID_ADDRESS;
@@ -938,7 +938,7 @@ u32 SymbolMap::GetDataModuleAddress(u32 startAddress) const {
}
DataType SymbolMap::GetDataType(u32 startAddress) const {
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
auto it = activeData.find(startAddress);
if (it == activeData.end())
return DATATYPE_NONE;
@@ -947,7 +947,7 @@ DataType SymbolMap::GetDataType(u32 startAddress) const {
void SymbolMap::GetLabels(std::vector<LabelDefinition> &dest) const
{
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
for (auto it = activeLabels.begin(); it != activeLabels.end(); it++) {
LabelDefinition entry;
entry.value = it->first;
@@ -973,7 +973,7 @@ static const DefaultSymbol defaultSymbols[]= {
void SymbolMap::FillSymbolListBox(HWND listbox,SymbolType symType) const {
wchar_t temp[256];
lock_guard guard(lock_);
std::lock_guard<std::recursive_mutex> guard(lock_);
SendMessage(listbox, WM_SETREDRAW, FALSE, 0);
ListBox_ResetContent(listbox);
+2 -3
View File
@@ -21,8 +21,7 @@
#include <set>
#include <map>
#include <string>
#include "base/mutex.h"
#include <mutex>
#include "Common/CommonTypes.h"
@@ -169,7 +168,7 @@ private:
std::map<SymbolKey, DataEntry> data;
std::vector<ModuleEntry> modules;
mutable recursive_mutex lock_;
mutable std::recursive_mutex lock_;
bool sawUnknownModule;
};
+7 -8
View File
@@ -299,9 +299,8 @@ void PSPSaveDialog::DisplayBanner(int which)
PPGeDrawText(title, 30, 11, PPGE_ALIGN_VCENTER, 0.6f, CalcFadedColor(0xFFFFFFFF));
}
void PSPSaveDialog::DisplaySaveList(bool canMove)
{
lock_guard guard(paramLock);
void PSPSaveDialog::DisplaySaveList(bool canMove) {
std::lock_guard<std::mutex> guard(paramLock);
static int upFramesHeld = 0;
static int downFramesHeld = 0;
@@ -361,7 +360,7 @@ void PSPSaveDialog::DisplaySaveList(bool canMove)
void PSPSaveDialog::DisplaySaveIcon()
{
lock_guard guard(paramLock);
std::lock_guard<std::mutex> guard(paramLock);
int textureColor = CalcFadedColor(0xFFFFFFFF);
auto curSave = param.GetFileInfo(currentSelectedSave);
@@ -390,7 +389,7 @@ void PSPSaveDialog::DisplaySaveIcon()
void PSPSaveDialog::DisplaySaveDataInfo1()
{
lock_guard guard(paramLock);
std::lock_guard<std::mutex> guard(paramLock);
if (param.GetFileInfo(currentSelectedSave).size == 0) {
I18NCategory *di = GetI18NCategory("Dialog");
PPGeDrawText(di->T("NEW DATA"), 180, 136, PPGE_ALIGN_VCENTER, 0.6f, CalcFadedColor(0xFFFFFFFF));
@@ -463,7 +462,7 @@ void PSPSaveDialog::DisplaySaveDataInfo1()
void PSPSaveDialog::DisplaySaveDataInfo2()
{
lock_guard guard(paramLock);
std::lock_guard<std::mutex> guard(paramLock);
if (param.GetFileInfo(currentSelectedSave).size == 0) {
} else {
char txt[1024];
@@ -589,7 +588,7 @@ int PSPSaveDialog::Update(int animSpeed)
memset(&request, 0, sizeof(request));
Memory::Memcpy(&request, requestAddr, size);
Memory::Memcpy(&originalRequest, requestAddr, size);
lock_guard guard(paramLock);
std::lock_guard<std::mutex> guard(paramLock);
param.SetPspParam(&request);
}
@@ -1002,7 +1001,7 @@ int PSPSaveDialog::Update(int animSpeed)
}
void PSPSaveDialog::ExecuteIOAction() {
lock_guard guard(paramLock);
std::lock_guard<std::mutex> guard(paramLock);
switch (display) {
case DS_LOAD_LOADING:
if (param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave)) {
+2 -2
View File
@@ -18,8 +18,8 @@
#pragma once
#include <thread>
#include <mutex>
#include "base/mutex.h"
#include "Core/Dialog/PSPDialog.h"
#include "Core/Dialog/SavedataParam.h"
@@ -154,7 +154,7 @@ private:
};
std::thread *ioThread;
recursive_mutex paramLock;
std::mutex paramLock;
volatile SaveIOStatus ioThreadStatus;
};
+11 -11
View File
@@ -50,7 +50,7 @@ CachingFileLoader::~CachingFileLoader() {
bool CachingFileLoader::Exists() {
if (exists_ == -1) {
lock_guard guard(backendMutex_);
std::lock_guard<std::mutex> guard(backendMutex_);
exists_ = backend_->Exists() ? 1 : 0;
}
return exists_ == 1;
@@ -58,7 +58,7 @@ bool CachingFileLoader::Exists() {
bool CachingFileLoader::ExistsFast() {
if (exists_ == -1) {
lock_guard guard(backendMutex_);
std::lock_guard<std::mutex> guard(backendMutex_);
return backend_->ExistsFast();
}
return exists_ == 1;
@@ -66,7 +66,7 @@ bool CachingFileLoader::ExistsFast() {
bool CachingFileLoader::IsDirectory() {
if (isDirectory_ == -1) {
lock_guard guard(backendMutex_);
std::lock_guard<std::mutex> guard(backendMutex_);
isDirectory_ = backend_->IsDirectory() ? 1 : 0;
}
return isDirectory_ == 1;
@@ -78,7 +78,7 @@ s64 CachingFileLoader::FileSize() {
}
std::string CachingFileLoader::Path() const {
lock_guard guard(backendMutex_);
std::lock_guard<std::mutex> guard(backendMutex_);
return backend_->Path();
}
@@ -96,7 +96,7 @@ size_t CachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Flag
size_t readSize = 0;
if ((flags & Flags::HINT_UNCACHED) != 0) {
lock_guard guard(backendMutex_);
std::lock_guard<std::mutex> guard(backendMutex_);
readSize = backend_->ReadAt(absolutePos, bytes, data, flags);
} else {
readSize = ReadFromCache(absolutePos, bytes, data);
@@ -132,7 +132,7 @@ void CachingFileLoader::ShutdownCache() {
sleep_ms(1);
}
lock_guard guard(blocksMutex_);
std::lock_guard<std::mutex> guard(blocksMutex_);
for (auto block : blocks_) {
delete [] block.second.ptr;
}
@@ -148,7 +148,7 @@ size_t CachingFileLoader::ReadFromCache(s64 pos, size_t bytes, void *data) {
size_t offset = (size_t)(pos - (cacheStartPos << BLOCK_SHIFT));
u8 *p = (u8 *)data;
lock_guard guard(blocksMutex_);
std::lock_guard<std::mutex> guard(blocksMutex_);
for (s64 i = cacheStartPos; i <= cacheEndPos; ++i) {
auto block = blocks_.find(i);
if (block == blocks_.end()) {
@@ -170,7 +170,7 @@ void CachingFileLoader::SaveIntoCache(s64 pos, size_t bytes, Flags flags, bool r
s64 cacheStartPos = pos >> BLOCK_SHIFT;
s64 cacheEndPos = (pos + bytes - 1) >> BLOCK_SHIFT;
lock_guard guard(blocksMutex_);
std::lock_guard<std::mutex> guard(blocksMutex_);
size_t blocksToRead = 0;
for (s64 i = cacheStartPos; i <= cacheEndPos; ++i) {
auto block = blocks_.find(i);
@@ -235,7 +235,7 @@ bool CachingFileLoader::MakeCacheSpaceFor(size_t blocks, bool readingAhead) {
return false;
}
lock_guard guard(blocksMutex_);
std::lock_guard<std::mutex> guard(blocksMutex_);
while (cacheSize_ > goal) {
u64 minGeneration = generation_;
@@ -274,7 +274,7 @@ bool CachingFileLoader::MakeCacheSpaceFor(size_t blocks, bool readingAhead) {
}
void CachingFileLoader::StartReadAhead(s64 pos) {
lock_guard guard(blocksMutex_);
std::lock_guard<std::mutex> guard(blocksMutex_);
if (aheadThread_) {
// Already going.
return;
@@ -288,7 +288,7 @@ void CachingFileLoader::StartReadAhead(s64 pos) {
std::thread th([this, pos] {
setCurrentThreadName("FileLoaderReadAhead");
lock_guard guard(blocksMutex_);
std::lock_guard<std::mutex> guard(blocksMutex_);
s64 cacheStartPos = pos >> BLOCK_SHIFT;
s64 cacheEndPos = cacheStartPos + BLOCK_READAHEAD - 1;
+4 -3
View File
@@ -18,7 +18,8 @@
#pragma once
#include <map>
#include "base/mutex.h"
#include <mutex>
#include "Common/CommonTypes.h"
#include "Core/Loaders.h"
@@ -83,8 +84,8 @@ private:
};
std::map<s64, BlockInfo> blocks_;
recursive_mutex blocksMutex_;
mutable recursive_mutex backendMutex_;
std::mutex blocksMutex_;
mutable std::mutex backendMutex_;
bool aheadThread_;
bool prepared_;
};
+10 -7
View File
@@ -18,11 +18,14 @@
#include <algorithm>
#include <cstddef>
#include <set>
#include <string.h>
#include <mutex>
#include <cstring>
#include "file/file_util.h"
#include "file/free.h"
#include "util/text/utf8.h"
#include "Common/FileUtil.h"
#include "Common/CommonWindows.h"
#include "Core/FileLoaders/DiskCachingFileLoader.h"
#include "Core/System.h"
@@ -34,7 +37,7 @@ static const u32 CACHE_SPACE_FLEX = 4;
std::string DiskCachingFileLoaderCache::cacheDir_;
std::map<std::string, DiskCachingFileLoaderCache *> DiskCachingFileLoader::caches_;
recursive_mutex DiskCachingFileLoader::cachesMutex_;
std::mutex DiskCachingFileLoader::cachesMutex_;
// Takes ownership of backend.
DiskCachingFileLoader::DiskCachingFileLoader(FileLoader *backend)
@@ -121,7 +124,7 @@ size_t DiskCachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data,
}
std::vector<std::string> DiskCachingFileLoader::GetCachedPathsInUse() {
lock_guard guard(cachesMutex_);
std::lock_guard<std::mutex> guard(cachesMutex_);
// This is on the file loader so that it can manage the caches_.
std::vector<std::string> files;
@@ -134,7 +137,7 @@ std::vector<std::string> DiskCachingFileLoader::GetCachedPathsInUse() {
}
void DiskCachingFileLoader::InitCache() {
lock_guard guard(cachesMutex_);
std::lock_guard<std::mutex> guard(cachesMutex_);
std::string path = backend_->Path();
auto &entry = caches_[path];
@@ -147,7 +150,7 @@ void DiskCachingFileLoader::InitCache() {
}
void DiskCachingFileLoader::ShutdownCache() {
lock_guard guard(cachesMutex_);
std::lock_guard<std::mutex> guard(cachesMutex_);
if (cache_->Release()) {
// If it ran out of counts, delete it.
@@ -222,7 +225,7 @@ void DiskCachingFileLoaderCache::ShutdownCache() {
}
size_t DiskCachingFileLoaderCache::ReadFromCache(s64 pos, size_t bytes, void *data) {
lock_guard guard(lock_);
std::lock_guard<std::mutex> guard(lock_);
if (!f_) {
return 0;
@@ -257,7 +260,7 @@ size_t DiskCachingFileLoaderCache::ReadFromCache(s64 pos, size_t bytes, void *da
}
size_t DiskCachingFileLoaderCache::SaveIntoCache(FileLoader *backend, s64 pos, size_t bytes, void *data, FileLoader::Flags flags) {
lock_guard guard(lock_);
std::lock_guard<std::mutex> guard(lock_);
if (!f_) {
// Just to keep things working.
+4 -3
View File
@@ -19,7 +19,8 @@
#include <vector>
#include <map>
#include "base/mutex.h"
#include <mutex>
#include "Common/Common.h"
#include "Core/Loaders.h"
@@ -64,7 +65,7 @@ private:
// We don't support concurrent disk cache access (we use memory cached indexes.)
// So we have to ensure there's only one of these per.
static std::map<std::string, DiskCachingFileLoaderCache *> caches_;
static recursive_mutex cachesMutex_;
static std::mutex cachesMutex_;
};
class DiskCachingFileLoaderCache {
@@ -154,7 +155,7 @@ private:
u32 flags_;
size_t cacheSize_;
size_t indexCount_;
recursive_mutex lock_;
std::mutex lock_;
std::string origPath_;
struct FileHeader {
+15 -13
View File
@@ -18,6 +18,8 @@
#include <algorithm>
#include <thread>
#include <cstring>
#include <cstdlib>
#include "base/timeutil.h"
#include "thread/threadutil.h"
#include "Core/FileLoaders/RamCachingFileLoader.h"
@@ -43,7 +45,7 @@ RamCachingFileLoader::~RamCachingFileLoader() {
bool RamCachingFileLoader::Exists() {
if (exists_ == -1) {
lock_guard guard(backendMutex_);
std::lock_guard<std::mutex> guard(backendMutex_);
exists_ = backend_->Exists() ? 1 : 0;
}
return exists_ == 1;
@@ -51,7 +53,7 @@ bool RamCachingFileLoader::Exists() {
bool RamCachingFileLoader::ExistsFast() {
if (exists_ == -1) {
lock_guard guard(backendMutex_);
std::lock_guard<std::mutex> guard(backendMutex_);
return backend_->ExistsFast();
}
return exists_ == 1;
@@ -59,7 +61,7 @@ bool RamCachingFileLoader::ExistsFast() {
bool RamCachingFileLoader::IsDirectory() {
if (isDirectory_ == -1) {
lock_guard guard(backendMutex_);
std::lock_guard<std::mutex> guard(backendMutex_);
isDirectory_ = backend_->IsDirectory() ? 1 : 0;
}
return isDirectory_ == 1;
@@ -70,7 +72,7 @@ s64 RamCachingFileLoader::FileSize() {
}
std::string RamCachingFileLoader::Path() const {
lock_guard guard(backendMutex_);
std::lock_guard<std::mutex> guard(backendMutex_);
return backend_->Path();
}
@@ -81,7 +83,7 @@ void RamCachingFileLoader::Seek(s64 absolutePos) {
size_t RamCachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags) {
size_t readSize = 0;
if (cache_ == nullptr || (flags & Flags::HINT_UNCACHED) != 0) {
lock_guard guard(backendMutex_);
std::lock_guard<std::mutex> guard(backendMutex_);
readSize = backend_->ReadAt(absolutePos, bytes, data, flags);
} else {
readSize = ReadFromCache(absolutePos, bytes, data);
@@ -104,7 +106,7 @@ size_t RamCachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, F
}
void RamCachingFileLoader::InitCache() {
lock_guard guard(blocksMutex_);
std::lock_guard<std::mutex> guard(blocksMutex_);
u32 blockCount = (u32)((filesize_ + BLOCK_SIZE - 1) >> BLOCK_SHIFT);
// Overallocate for the last block.
cache_ = (u8 *)malloc((size_t)blockCount << BLOCK_SHIFT);
@@ -117,7 +119,7 @@ void RamCachingFileLoader::InitCache() {
void RamCachingFileLoader::ShutdownCache() {
{
lock_guard guard(blocksMutex_);
std::lock_guard<std::mutex> guard(blocksMutex_);
// Try to have the thread stop.
aheadRemaining_ = 0;
}
@@ -128,7 +130,7 @@ void RamCachingFileLoader::ShutdownCache() {
sleep_ms(1);
}
lock_guard guard(blocksMutex_);
std::lock_guard<std::mutex> guard(blocksMutex_);
blocks_.clear();
if (cache_ != nullptr) {
free(cache_);
@@ -156,7 +158,7 @@ size_t RamCachingFileLoader::ReadFromCache(s64 pos, size_t bytes, void *data) {
bytes = filesize_ - pos;
}
lock_guard guard(blocksMutex_);
std::lock_guard<std::mutex> guard(blocksMutex_);
for (s64 i = cacheStartPos; i <= cacheEndPos; ++i) {
if (blocks_[i] == 0) {
return readSize;
@@ -182,7 +184,7 @@ void RamCachingFileLoader::SaveIntoCache(s64 pos, size_t bytes, Flags flags) {
size_t blocksToRead = 0;
{
lock_guard guard(blocksMutex_);
std::lock_guard<std::mutex> guard(blocksMutex_);
for (s64 i = cacheStartPos; i <= cacheEndPos; ++i) {
if (blocks_[i] == 0) {
++blocksToRead;
@@ -201,7 +203,7 @@ void RamCachingFileLoader::SaveIntoCache(s64 pos, size_t bytes, Flags flags) {
// In case there was an error, let's not mark blocks that failed to read as read.
u32 blocksActuallyRead = (u32)((bytesRead + BLOCK_SIZE - 1) >> BLOCK_SHIFT);
{
lock_guard guard(blocksMutex_);
std::lock_guard<std::mutex> guard(blocksMutex_);
// In case they were simultaneously read.
u32 blocksRead = 0;
@@ -223,7 +225,7 @@ void RamCachingFileLoader::StartReadAhead(s64 pos) {
return;
}
lock_guard guard(blocksMutex_);
std::lock_guard<std::mutex> guard(blocksMutex_);
aheadPos_ = pos;
if (aheadThread_) {
// Already going.
@@ -260,7 +262,7 @@ void RamCachingFileLoader::StartReadAhead(s64 pos) {
}
u32 RamCachingFileLoader::NextAheadBlock() {
lock_guard guard(blocksMutex_);
std::lock_guard<std::mutex> guard(blocksMutex_);
// If we had an aheadPos_ set, start reading from there and go forward.
u32 startFrom = (u32)(aheadPos_ >> BLOCK_SHIFT);
+4 -3
View File
@@ -18,7 +18,8 @@
#pragma once
#include <vector>
#include "base/mutex.h"
#include <mutex>
#include "Common/CommonTypes.h"
#include "Core/Loaders.h"
@@ -69,8 +70,8 @@ private:
int isDirectory_;
std::vector<u8> blocks_;
recursive_mutex blocksMutex_;
mutable recursive_mutex backendMutex_;
std::mutex blocksMutex_;
mutable std::mutex backendMutex_;
u32 aheadRemaining_;
s64 aheadPos_;
bool aheadThread_;
+3 -6
View File
@@ -360,13 +360,10 @@ bool CISOFileBlockDevice::ReadBlocks(u32 minBlock, int count, u8 *outPtr) {
return true;
}
recursive_mutex NPDRMDemoBlockDevice::mutex_;
NPDRMDemoBlockDevice::NPDRMDemoBlockDevice(FileLoader *fileLoader)
: fileLoader_(fileLoader)
{
lock_guard guard(mutex_);
std::lock_guard<std::mutex> guard(mutex_);
MAC_KEY mkey;
CIPHER_KEY ckey;
u8 np_header[256];
@@ -432,7 +429,7 @@ NPDRMDemoBlockDevice::NPDRMDemoBlockDevice(FileLoader *fileLoader)
NPDRMDemoBlockDevice::~NPDRMDemoBlockDevice()
{
lock_guard guard(mutex_);
std::lock_guard<std::mutex> guard(mutex_);
delete [] table;
delete [] tempBuf;
delete [] blockBuf;
@@ -443,7 +440,7 @@ int lzrc_decompress(void *out, int out_len, void *in, int in_len);
bool NPDRMDemoBlockDevice::ReadBlock(int blockNumber, u8 *outPtr, bool uncached)
{
FileLoader::Flags flags = uncached ? FileLoader::Flags::HINT_UNCACHED : FileLoader::Flags::NONE;
lock_guard guard(mutex_);
std::lock_guard<std::mutex> guard(mutex_);
CIPHER_KEY ckey;
int block, lba, lzsize;
size_t readSize;
+7 -11
View File
@@ -23,14 +23,14 @@
// The ISOFileSystemReader reads from a BlockDevice, so it automatically works
// with CISO images.
#include <mutex>
#include "Common/CommonTypes.h"
#include "Core/ELF/PBPReader.h"
#include "base/mutex.h"
class FileLoader;
class BlockDevice
{
class BlockDevice {
public:
virtual ~BlockDevice() {}
virtual bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) = 0;
@@ -49,9 +49,7 @@ public:
u32 CalculateCRC();
};
class CISOFileBlockDevice : public BlockDevice
{
class CISOFileBlockDevice : public BlockDevice {
public:
CISOFileBlockDevice(FileLoader *fileLoader);
~CISOFileBlockDevice();
@@ -73,8 +71,7 @@ private:
};
class FileBlockDevice : public BlockDevice
{
class FileBlockDevice : public BlockDevice {
public:
FileBlockDevice(FileLoader *fileLoader);
~FileBlockDevice();
@@ -98,8 +95,7 @@ struct table_info {
int unk_1c;
};
class NPDRMDemoBlockDevice : public BlockDevice
{
class NPDRMDemoBlockDevice : public BlockDevice {
public:
NPDRMDemoBlockDevice(FileLoader *fileLoader);
~NPDRMDemoBlockDevice();
@@ -109,7 +105,7 @@ public:
private:
FileLoader *fileLoader_;
static recursive_mutex mutex_;
std::mutex mutex_;
u32 lbaSize;
u32 psarOffset;
+26 -26
View File
@@ -166,7 +166,7 @@ static bool RealPath(const std::string &currentDirectory, const std::string &inP
IFileSystem *MetaFileSystem::GetHandleOwner(u32 handle)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
for (size_t i = 0; i < fileSystems.size(); i++)
{
if (fileSystems[i].system->OwnsHandle(handle))
@@ -178,7 +178,7 @@ IFileSystem *MetaFileSystem::GetHandleOwner(u32 handle)
bool MetaFileSystem::MapFilePath(const std::string &_inpath, std::string &outpath, MountPoint **system)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
std::string realpath;
std::string inpath = _inpath;
@@ -271,7 +271,7 @@ std::string MetaFileSystem::NormalizePrefix(std::string prefix) const {
void MetaFileSystem::Mount(std::string prefix, IFileSystem *system)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
MountPoint x;
x.prefix = prefix;
x.system = system;
@@ -280,7 +280,7 @@ void MetaFileSystem::Mount(std::string prefix, IFileSystem *system)
void MetaFileSystem::Unmount(std::string prefix, IFileSystem *system)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
MountPoint x;
x.prefix = prefix;
x.system = system;
@@ -312,7 +312,7 @@ IFileSystem *MetaFileSystem::GetSystem(const std::string &prefix) {
void MetaFileSystem::Shutdown()
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
current = 6;
// Ownership is a bit convoluted. Let's just delete everything once.
@@ -334,7 +334,7 @@ void MetaFileSystem::Shutdown()
u32 MetaFileSystem::OpenWithError(int &error, std::string filename, FileAccess access, const char *devicename)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
u32 h = OpenFile(filename, access, devicename);
error = lastOpenError;
return h;
@@ -342,7 +342,7 @@ u32 MetaFileSystem::OpenWithError(int &error, std::string filename, FileAccess a
u32 MetaFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
lastOpenError = 0;
std::string of;
MountPoint *mount;
@@ -364,7 +364,7 @@ u32 MetaFileSystem::OpenFile(std::string filename, FileAccess access, const char
PSPFileInfo MetaFileSystem::GetFileInfo(std::string filename)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
std::string of;
IFileSystem *system;
if (MapFilePath(filename, of, &system))
@@ -380,7 +380,7 @@ PSPFileInfo MetaFileSystem::GetFileInfo(std::string filename)
bool MetaFileSystem::GetHostPath(const std::string &inpath, std::string &outpath)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
std::string of;
IFileSystem *system;
if (MapFilePath(inpath, of, &system)) {
@@ -392,7 +392,7 @@ bool MetaFileSystem::GetHostPath(const std::string &inpath, std::string &outpath
std::vector<PSPFileInfo> MetaFileSystem::GetDirListing(std::string path)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
std::string of;
IFileSystem *system;
if (MapFilePath(path, of, &system))
@@ -408,13 +408,13 @@ std::vector<PSPFileInfo> MetaFileSystem::GetDirListing(std::string path)
void MetaFileSystem::ThreadEnded(int threadID)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
currentDir.erase(threadID);
}
int MetaFileSystem::ChDir(const std::string &dir)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
// Retain the old path and fail if the arg is 1023 bytes or longer.
if (dir.size() >= 1023)
return SCE_KERNEL_ERROR_NAMETOOLONG;
@@ -449,7 +449,7 @@ int MetaFileSystem::ChDir(const std::string &dir)
bool MetaFileSystem::MkDir(const std::string &dirname)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
std::string of;
IFileSystem *system;
if (MapFilePath(dirname, of, &system))
@@ -464,7 +464,7 @@ bool MetaFileSystem::MkDir(const std::string &dirname)
bool MetaFileSystem::RmDir(const std::string &dirname)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
std::string of;
IFileSystem *system;
if (MapFilePath(dirname, of, &system))
@@ -479,7 +479,7 @@ bool MetaFileSystem::RmDir(const std::string &dirname)
int MetaFileSystem::RenameFile(const std::string &from, const std::string &to)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
std::string of;
std::string rf;
IFileSystem *osystem;
@@ -511,7 +511,7 @@ int MetaFileSystem::RenameFile(const std::string &from, const std::string &to)
bool MetaFileSystem::RemoveFile(const std::string &filename)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
std::string of;
IFileSystem *system;
if (MapFilePath(filename, of, &system))
@@ -526,7 +526,7 @@ bool MetaFileSystem::RemoveFile(const std::string &filename)
int MetaFileSystem::Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
IFileSystem *sys = GetHandleOwner(handle);
if (sys)
return sys->Ioctl(handle, cmd, indataPtr, inlen, outdataPtr, outlen, usec);
@@ -535,7 +535,7 @@ int MetaFileSystem::Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 out
int MetaFileSystem::DevType(u32 handle)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
IFileSystem *sys = GetHandleOwner(handle);
if (sys)
return sys->DevType(handle);
@@ -544,7 +544,7 @@ int MetaFileSystem::DevType(u32 handle)
void MetaFileSystem::CloseFile(u32 handle)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
IFileSystem *sys = GetHandleOwner(handle);
if (sys)
sys->CloseFile(handle);
@@ -552,7 +552,7 @@ void MetaFileSystem::CloseFile(u32 handle)
size_t MetaFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
IFileSystem *sys = GetHandleOwner(handle);
if (sys)
return sys->ReadFile(handle, pointer, size);
@@ -562,7 +562,7 @@ size_t MetaFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size)
size_t MetaFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
IFileSystem *sys = GetHandleOwner(handle);
if (sys)
return sys->WriteFile(handle, pointer, size);
@@ -572,7 +572,7 @@ size_t MetaFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size)
size_t MetaFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size, int &usec)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
IFileSystem *sys = GetHandleOwner(handle);
if (sys)
return sys->ReadFile(handle, pointer, size, usec);
@@ -582,7 +582,7 @@ size_t MetaFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size, int &usec)
size_t MetaFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
IFileSystem *sys = GetHandleOwner(handle);
if (sys)
return sys->WriteFile(handle, pointer, size, usec);
@@ -592,7 +592,7 @@ size_t MetaFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size, int &u
size_t MetaFileSystem::SeekFile(u32 handle, s32 position, FileMove type)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
IFileSystem *sys = GetHandleOwner(handle);
if (sys)
return sys->SeekFile(handle,position,type);
@@ -619,7 +619,7 @@ int MetaFileSystem::ReadEntireFile(const std::string &filename, std::vector<u8>
u64 MetaFileSystem::FreeSpace(const std::string &path)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
std::string of;
IFileSystem *system;
if (MapFilePath(path, of, &system))
@@ -630,7 +630,7 @@ u64 MetaFileSystem::FreeSpace(const std::string &path)
void MetaFileSystem::DoState(PointerWrap &p)
{
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
auto s = p.Section("MetaFileSystem", 1);
if (!s)
+3 -3
View File
@@ -19,8 +19,8 @@
#include <string>
#include <vector>
#include <mutex>
#include "base/mutex.h"
#include "Core/FileSystems/FileSystem.h"
class MetaFileSystem : public IHandleAllocator, public IFileSystem {
@@ -42,7 +42,7 @@ private:
std::string startingDirectory;
int lastOpenError;
recursive_mutex lock;
std::recursive_mutex lock; // must be recursive
public:
MetaFileSystem() {
@@ -120,7 +120,7 @@ public:
int ReadEntireFile(const std::string &filename, std::vector<u8> &data);
void SetStartingDirectory(const std::string &dir) {
lock_guard guard(lock);
std::lock_guard<std::recursive_mutex> guard(lock);
startingDirectory = dir;
}
};
+3 -3
View File
@@ -15,7 +15,8 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "base/mutex.h"
#include <atomic>
#include <mutex>
#include "Globals.h" // only for clamp_s16
#include "Common/CommonTypes.h"
@@ -48,8 +49,7 @@ AudioDebugStats g_AudioDebugStats;
// Should be used to lock anything related to the outAudioQueue.
// atomic locks are used on the lock. TODO: make this lock-free
atomic_flag atomicLock_;
recursive_mutex mutex_;
std::atomic_flag atomicLock_;
enum latency {
LOW_LATENCY = 0,
+3 -12
View File
@@ -51,7 +51,7 @@ int metasocket;
SceNetAdhocctlParameter parameter;
SceNetAdhocctlAdhocId product_code;
std::thread friendFinderThread;
recursive_mutex peerlock;
std::mutex peerlock;
SceNetAdhocPdpStat * pdp[255];
SceNetAdhocPtpStat * ptp[255];
uint32_t localip;
@@ -104,7 +104,7 @@ void addFriend(SceNetAdhocctlConnectPacketS2C * packet) {
if (packet == NULL) return;
// Multithreading Lock
peerlock.lock();
std::lock_guard<std::mutex> guard(peerlock);
SceNetAdhocctlPeerInfo * peer = findFriend(&packet->mac);
// Already existed
@@ -143,9 +143,6 @@ void addFriend(SceNetAdhocctlConnectPacketS2C * packet) {
friends = peer;
}
}
// Multithreading Unlock
peerlock.unlock();
}
SceNetAdhocctlPeerInfo * findFriend(SceNetEtherAddr * MAC) {
@@ -1528,7 +1525,7 @@ bool resolveMAC(SceNetEtherAddr * mac, uint32_t * ip) {
}
// Multithreading Lock
peerlock.lock();
std::lock_guard<std::mutex> guard(peerlock);
// Peer Reference
SceNetAdhocctlPeerInfo * peer = friends;
@@ -1540,17 +1537,11 @@ bool resolveMAC(SceNetEtherAddr * mac, uint32_t * ip) {
// Copy Data
*ip = peer->ip_addr;
// Multithreading Unlock
peerlock.unlock();
// Return Success
return true;
}
}
// Multithreading Unlock
peerlock.unlock();
// Peer not found
return false;
}
+5 -5
View File
@@ -18,9 +18,9 @@
#pragma once
#include <thread>
#include <mutex>
#include "base/timeutil.h"
#include "base/mutex.h"
#include "net/resolve.h"
#include "Common/ChunkFile.h"
@@ -412,7 +412,7 @@ typedef struct SceNetAdhocMatchingContext {
// Local PDP Socket
s32_le socket;
// Socket Lock
recursive_mutex *socketlock;
std::recursive_mutex *socketlock;
// Receive Buffer Length
s32_le rxbuflen;
@@ -468,11 +468,11 @@ typedef struct SceNetAdhocMatchingContext {
bool inputRunning = false;
// Event Caller Thread Message Stack
recursive_mutex *eventlock; // s32_le event_stack_lock;
std::recursive_mutex *eventlock; // s32_le event_stack_lock;
ThreadMessage *event_stack;
// IO Handler Thread Message Stack
recursive_mutex *inputlock; // s32_le input_stack_lock;
std::recursive_mutex *inputlock; // s32_le input_stack_lock;
ThreadMessage *input_stack;
// Socket Connectivity
@@ -788,7 +788,7 @@ extern int metasocket;
extern SceNetAdhocctlParameter parameter;
extern SceNetAdhocctlAdhocId product_code;
extern std::thread friendFinderThread;
extern recursive_mutex peerlock;
extern std::mutex peerlock;
extern SceNetAdhocPdpStat * pdp[255];
extern SceNetAdhocPtpStat * ptp[255];
extern std::map<int, AdhocctlHandler> adhocctlHandlers;
+13 -12
View File
@@ -16,8 +16,9 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <math.h>
#include "base/mutex.h"
#include <cmath>
#include <mutex>
#include "Globals.h"
#include "Core/HLE/HLE.h"
#include "Core/HLE/FunctionWrappers.h"
@@ -84,7 +85,7 @@ static int ctrlIdleBack = -1;
static int ctrlCycle = 0;
static std::vector<SceUID> waitingThreads;
static recursive_mutex ctrlMutex;
static std::mutex ctrlMutex;
static int ctrlTimer = -1;
@@ -101,7 +102,7 @@ const u32 CTRL_EMU_RAPIDFIRE_MASK = CTRL_UP | CTRL_DOWN | CTRL_LEFT | CTRL_RIGHT
static void __CtrlUpdateLatch()
{
lock_guard guard(ctrlMutex);
std::lock_guard<std::mutex> guard(ctrlMutex);
// Copy in the current data to the current buffer.
ctrlBufs[ctrlBuf] = ctrlCurrent;
@@ -144,14 +145,14 @@ static int __CtrlResetLatch()
u32 __CtrlPeekButtons()
{
lock_guard guard(ctrlMutex);
std::lock_guard<std::mutex> guard(ctrlMutex);
return ctrlCurrent.buttons;
}
void __CtrlPeekAnalog(int stick, float *x, float *y)
{
lock_guard guard(ctrlMutex);
std::lock_guard<std::mutex> guard(ctrlMutex);
*x = (ctrlCurrent.analog[stick][CTRL_ANALOG_X] - 127.5f) / 127.5f;
*y = -(ctrlCurrent.analog[stick][CTRL_ANALOG_Y] - 127.5f) / 127.5f;
@@ -170,27 +171,27 @@ u32 __CtrlReadLatch()
void __CtrlButtonDown(u32 buttonBit)
{
lock_guard guard(ctrlMutex);
std::lock_guard<std::mutex> guard(ctrlMutex);
ctrlCurrent.buttons |= buttonBit;
}
void __CtrlButtonUp(u32 buttonBit)
{
lock_guard guard(ctrlMutex);
std::lock_guard<std::mutex> guard(ctrlMutex);
ctrlCurrent.buttons &= ~buttonBit;
}
void __CtrlSetAnalogX(float x, int stick)
{
u8 scaled = clamp_u8((int)ceilf(x * 127.5f + 127.5f));
lock_guard guard(ctrlMutex);
std::lock_guard<std::mutex> 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));
lock_guard guard(ctrlMutex);
std::lock_guard<std::mutex> guard(ctrlMutex);
ctrlCurrent.analog[stick][CTRL_ANALOG_Y] = scaled;
}
@@ -304,7 +305,7 @@ void __CtrlInit()
ctrlIdleBack = -1;
ctrlCycle = 0;
lock_guard guard(ctrlMutex);
std::lock_guard<std::mutex> guard(ctrlMutex);
ctrlBuf = 1;
ctrlBufRead = 0;
@@ -326,7 +327,7 @@ void __CtrlInit()
void __CtrlDoState(PointerWrap &p)
{
lock_guard guard(ctrlMutex);
std::lock_guard<std::mutex> guard(ctrlMutex);
auto s = p.Section("sceCtrl", 1, 3);
if (!s)
+1 -1
View File
@@ -17,8 +17,8 @@
#include <map>
#include <vector>
#include <mutex>
#include "base/mutex.h"
#include "Common/ChunkFile.h"
#include "Common/ThreadSafeList.h"
#include "Core/HLE/HLE.h"
+9 -11
View File
@@ -15,7 +15,7 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <mutex>
// sceNetAdhoc
// This is a direct port of Coldbird's code from http://code.google.com/p/aemu/
@@ -37,8 +37,6 @@
#include "Core/HLE/sceNet.h"
#include "Core/HLE/proAdhocServer.h"
#include "base/mutex.h"
// shared in sceNetAdhoc.h since it need to be used from sceNet.cpp also
// TODO: Make accessor functions instead, and throw all this state in a struct.
bool netAdhocInited;
@@ -50,7 +48,7 @@ int netAdhocMatchingStarted = 0;
SceUID threadAdhocID;
recursive_mutex adhocEvtMtx;
std::mutex adhocEvtMtx;
std::vector<std::pair<u32, u32>> adhocctlEvents;
std::vector<u64> matchingEvents;
u32 dummyThreadHackAddr = 0;
@@ -121,13 +119,13 @@ void __NetAdhocDoState(PointerWrap &p) {
}
void __UpdateAdhocctlHandlers(u32 flag, u32 error) {
lock_guard adhocGuard(adhocEvtMtx);
std::lock_guard<std::mutex> adhocGuard(adhocEvtMtx);
adhocctlEvents.push_back({ flag, error });
}
// TODO: MipsCall needs to be called from it's own PSP Thread instead of from any random PSP Thread
void __UpdateMatchingHandler(u64 ArgsPtr) {
lock_guard adhocGuard(adhocEvtMtx);
std::lock_guard<std::mutex> adhocGuard(adhocEvtMtx);
matchingEvents.push_back(ArgsPtr);
}
@@ -1100,7 +1098,7 @@ static u32 sceNetAdhocctlDisconnect() {
// Notify Event Handlers (even if we weren't connected, not doing this will freeze games like God Eater, which expect this behaviour)
{
lock_guard adhocGuard(adhocEvtMtx);
std::lock_guard<std::mutex> adhocGuard(adhocEvtMtx);
adhocctlEvents.push_back({ ADHOCCTL_EVENT_DISCONNECT, 0 });
}
// Return Success, some games might ignore returned value and always treat it as success, otherwise repeatedly calling this function
@@ -2668,9 +2666,9 @@ static int sceNetAdhocMatchingCreate(int mode, int maxnum, int port, int rxbufle
context->mac = localmac;
// Create locks
context->socketlock = new recursive_mutex;
context->eventlock = new recursive_mutex;
context->inputlock = new recursive_mutex;
context->socketlock = new std::recursive_mutex;
context->eventlock = new std::recursive_mutex;
context->inputlock = new std::recursive_mutex;
// Create fake thread
//#define PSP_THREAD_ATTR_KERNEL 0x00001000 // PSP_THREAD_ATTR_KERNEL is located in sceKernelThread.cpp instead of sceKernelThread.h :(
@@ -3472,7 +3470,7 @@ int sceNetAdhocMatchingGetPoolStat(u32 poolstatPtr) {
void __NetTriggerCallbacks()
{
{
lock_guard adhocGuard(adhocEvtMtx);
std::lock_guard<std::mutex> adhocGuard(adhocEvtMtx);
for (auto &params : adhocctlEvents)
{
+9 -10
View File
@@ -29,9 +29,9 @@
#include <cstdlib>
#include <functional>
#include <thread>
#include <mutex>
#include "base/basictypes.h"
#include "base/mutex.h"
#include "profiler/profiler.h"
#include "thread/threadutil.h"
#include "Common/Log.h"
@@ -91,10 +91,10 @@ struct SasThreadParams {
};
static std::thread *sasThread;
static recursive_mutex sasWakeMutex;
static recursive_mutex sasDoneMutex;
static condition_variable sasWake;
static condition_variable sasDone;
static std::mutex sasWakeMutex;
static std::mutex sasDoneMutex;
static std::condition_variable sasWake;
static std::condition_variable sasDone;
static volatile int sasThreadState = SasThreadState::DISABLED;
static SasThreadParams sasThreadParams;
static int sasMixEvent = -1;
@@ -102,9 +102,9 @@ static int sasMixEvent = -1;
int __SasThread() {
setCurrentThreadName("SAS");
lock_guard guard(sasWakeMutex);
std::unique_lock<std::mutex> guard(sasWakeMutex);
while (sasThreadState != SasThreadState::DISABLED) {
sasWake.wait(sasWakeMutex);
sasWake.wait(guard);
if (sasThreadState == SasThreadState::QUEUED) {
sas->Mix(sasThreadParams.outAddr, sasThreadParams.inAddr, sasThreadParams.leftVol, sasThreadParams.rightVol);
@@ -118,10 +118,9 @@ int __SasThread() {
}
static void __SasDrain() {
sasDoneMutex.lock();
std::unique_lock<std::mutex> guard(sasDoneMutex);
while (sasThreadState == SasThreadState::QUEUED)
sasDone.wait(sasDoneMutex);
sasDoneMutex.unlock();
sasDone.wait(guard);
}
static void __SasEnqueueMix(u32 outAddr, u32 inAddr = 0, int leftVol = 0, int rightVol = 0) {
+13 -16
View File
@@ -15,6 +15,9 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <condition_variable>
#include <mutex>
#include "Common/ChunkFile.h"
#include "Core/MIPS/MIPS.h"
#include "Core/Reporting.h"
@@ -34,7 +37,7 @@ bool AsyncIOManager::HasOperation(u32 handle) {
void AsyncIOManager::ScheduleOperation(AsyncIOEvent ev) {
{
lock_guard guard(resultsLock_);
std::lock_guard<std::mutex> guard(resultsLock_);
if (!resultsPending_.insert(ev.handle).second) {
ERROR_LOG_REPORT(SCEIO, "Scheduling operation for file %d while one is pending (type %d)", ev.handle, ev.type);
}
@@ -43,18 +46,17 @@ void AsyncIOManager::ScheduleOperation(AsyncIOEvent ev) {
}
void AsyncIOManager::Shutdown() {
lock_guard guard(resultsLock_);
std::lock_guard<std::mutex> guard(resultsLock_);
resultsPending_.clear();
results_.clear();
}
bool AsyncIOManager::HasResult(u32 handle) {
lock_guard guard(resultsLock_);
std::lock_guard<std::mutex> guard(resultsLock_);
return results_.find(handle) != results_.end();
}
bool AsyncIOManager::PopResult(u32 handle, AsyncIOResult &result) {
lock_guard guard(resultsLock_);
if (results_.find(handle) != results_.end()) {
result = results_[handle];
results_.erase(handle);
@@ -70,7 +72,6 @@ bool AsyncIOManager::PopResult(u32 handle, AsyncIOResult &result) {
}
bool AsyncIOManager::ReadResult(u32 handle, AsyncIOResult &result) {
lock_guard guard(resultsLock_);
if (results_.find(handle) != results_.end()) {
result = results_[handle];
return true;
@@ -80,31 +81,27 @@ bool AsyncIOManager::ReadResult(u32 handle, AsyncIOResult &result) {
}
bool AsyncIOManager::WaitResult(u32 handle, AsyncIOResult &result) {
lock_guard guard(resultsLock_);
std::unique_lock<std::mutex> guard(resultsLock_);
ScheduleEvent(IO_EVENT_SYNC);
while (HasEvents() && ThreadEnabled() && resultsPending_.find(handle) != resultsPending_.end()) {
if (PopResult(handle, result)) {
return true;
}
resultsWait_.wait_for(resultsLock_, 16);
resultsWait_.wait_for(guard, std::chrono::milliseconds(16));
}
if (PopResult(handle, result)) {
return true;
}
return false;
return PopResult(handle, result);
}
u64 AsyncIOManager::ResultFinishTicks(u32 handle) {
AsyncIOResult result;
lock_guard guard(resultsLock_);
std::unique_lock<std::mutex> guard(resultsLock_);
ScheduleEvent(IO_EVENT_SYNC);
while (HasEvents() && ThreadEnabled() && resultsPending_.find(handle) != resultsPending_.end()) {
if (ReadResult(handle, result)) {
return result.finishTicks;
}
resultsWait_.wait_for(resultsLock_, 16);
resultsWait_.wait_for(guard, std::chrono::milliseconds(16));
}
if (ReadResult(handle, result)) {
return result.finishTicks;
@@ -141,7 +138,7 @@ void AsyncIOManager::Write(u32 handle, u8 *buf, size_t bytes) {
}
void AsyncIOManager::EventResult(u32 handle, AsyncIOResult result) {
lock_guard guard(resultsLock_);
std::lock_guard<std::mutex> guard(resultsLock_);
if (results_.find(handle) != results_.end()) {
ERROR_LOG_REPORT(SCEIO, "Overwriting previous result for file action on handle %d", handle);
}
@@ -155,7 +152,7 @@ void AsyncIOManager::DoState(PointerWrap &p) {
return;
SyncThread();
lock_guard guard(resultsLock_);
std::lock_guard<std::mutex> guard(resultsLock_);
p.Do(resultsPending_);
if (s >= 2) {
p.Do(results_);
+6 -5
View File
@@ -17,7 +17,8 @@
#include <map>
#include <set>
#include "base/mutex.h"
#include <mutex>
#include "Core/ThreadEventQueue.h"
class NoBase {
@@ -84,8 +85,6 @@ public:
void Shutdown();
bool HasResult(u32 handle);
bool PopResult(u32 handle, AsyncIOResult &result);
bool ReadResult(u32 handle, AsyncIOResult &result);
bool WaitResult(u32 handle, AsyncIOResult &result);
u64 ResultFinishTicks(u32 handle);
@@ -96,13 +95,15 @@ protected:
}
private:
bool PopResult(u32 handle, AsyncIOResult &result);
bool ReadResult(u32 handle, AsyncIOResult &result);
void Read(u32 handle, u8 *buf, size_t bytes, u32 invalidateAddr);
void Write(u32 handle, u8 *buf, size_t bytes);
void EventResult(u32 handle, AsyncIOResult result);
recursive_mutex resultsLock_;
condition_variable resultsWait_;
std::mutex resultsLock_;
std::condition_variable resultsWait_;
std::set<u32> resultsPending_;
std::map<u32, AsyncIOResult> results_;
};
-2
View File
@@ -21,8 +21,6 @@
#include <string>
#include "base/mutex.h"
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
+12 -11
View File
@@ -16,10 +16,11 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include "base/mutex.h"
#include <mutex>
#include "ext/cityhash/city.h"
#include "Common/FileUtil.h"
#include "Core/Config.h"
@@ -40,7 +41,7 @@ using namespace MIPSCodeUtils;
// Not in a namespace because MSVC's debugger doesn't like it
typedef std::vector<MIPSAnalyst::AnalyzedFunction> FunctionsVector;
static FunctionsVector functions;
recursive_mutex functions_lock;
std::recursive_mutex functions_lock;
// One function can appear in multiple copies in memory, and they will all have
// the same hash and should all be replaced if possible.
@@ -741,13 +742,13 @@ namespace MIPSAnalyst {
}
void Reset() {
lock_guard guard(functions_lock);
std::lock_guard<std::recursive_mutex> guard(functions_lock);
functions.clear();
hashToFunction.clear();
}
void UpdateHashToFunctionMap() {
lock_guard guard(functions_lock);
std::lock_guard<std::recursive_mutex> guard(functions_lock);
hashToFunction.clear();
// Really need to detect C++11 features with better defines.
#if !defined(IOS)
@@ -869,7 +870,7 @@ namespace MIPSAnalyst {
}
void HashFunctions() {
lock_guard guard(functions_lock);
std::lock_guard<std::recursive_mutex> guard(functions_lock);
std::vector<u32> buffer;
for (auto iter = functions.begin(), end = functions.end(); iter != end; iter++) {
@@ -986,7 +987,7 @@ skip:
}
void ScanForFunctions(u32 startAddr, u32 endAddr, bool insertSymbols) {
lock_guard guard(functions_lock);
std::lock_guard<std::recursive_mutex> guard(functions_lock);
AnalyzedFunction currentFunction = {startAddr};
@@ -1151,7 +1152,7 @@ skip:
}
void RegisterFunction(u32 startAddr, u32 size, const char *name) {
lock_guard guard(functions_lock);
std::lock_guard<std::recursive_mutex> guard(functions_lock);
// Check if we have this already
for (auto iter = functions.begin(); iter != functions.end(); iter++) {
@@ -1184,7 +1185,7 @@ skip:
}
void ForgetFunctions(u32 startAddr, u32 endAddr) {
lock_guard guard(functions_lock);
std::lock_guard<std::recursive_mutex> guard(functions_lock);
// It makes sense to forget functions as modules are unloaded but it breaks
// the easy way of saving a hashmap by unloading and loading a game. I added
@@ -1221,7 +1222,7 @@ skip:
}
void ReplaceFunctions() {
lock_guard guard(functions_lock);
std::lock_guard<std::recursive_mutex> guard(functions_lock);
for (size_t i = 0; i < functions.size(); i++) {
WriteReplaceInstructions(functions[i].start, functions[i].hash, functions[i].size);
@@ -1229,7 +1230,7 @@ skip:
}
void UpdateHashMap() {
lock_guard guard(functions_lock);
std::lock_guard<std::recursive_mutex> guard(functions_lock);
for (auto it = functions.begin(), end = functions.end(); it != end; ++it) {
const AnalyzedFunction &f = *it;
+6 -5
View File
@@ -15,10 +15,11 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <algorithm>
#include "ppsspp_config.h"
#include "base/mutex.h"
#include <algorithm>
#include <mutex>
#include "Common/Common.h"
#include "Common/MemoryUtil.h"
#include "Common/MemArena.h"
@@ -77,7 +78,7 @@ u32 g_MemorySize;
// Used to store the PSP model on game startup.
u32 g_PSPModel;
recursive_mutex g_shutdownLock;
std::mutex g_shutdownLock;
// We don't declare the IO region in here since its handled by other means.
static MemoryView views[] =
@@ -315,7 +316,7 @@ void DoState(PointerWrap &p) {
}
void Shutdown() {
lock_guard guard(g_shutdownLock);
std::lock_guard<std::mutex> guard(g_shutdownLock);
u32 flags = 0;
MemoryMap_Shutdown(flags);
base = nullptr;
+3
View File
@@ -19,6 +19,9 @@
#include "util/text/utf8.h"
#include "Common/StringUtils.h"
#ifdef _WIN32
#include "Common/CommonWindows.h"
#endif
#include "Core/ELF/ElfReader.h"
#include "Core/ELF/ParamSFO.h"
+6 -6
View File
@@ -85,8 +85,8 @@ namespace Reporting
static Payload payloadBuffer[PAYLOAD_BUFFER_SIZE];
static int payloadBufferPos = 0;
static recursive_mutex crcLock;
static condition_variable crcCond;
static std::mutex crcLock;
static std::condition_variable crcCond;
static std::string crcFilename;
static std::map<std::string, u32> crcResults;
@@ -105,7 +105,7 @@ namespace Reporting
delete blockDevice;
delete fileLoader;
lock_guard guard(crcLock);
std::lock_guard<std::mutex> guard(crcLock);
crcResults[crcFilename] = crc;
crcCond.notify_one();
@@ -113,7 +113,7 @@ namespace Reporting
}
void QueueCRC() {
lock_guard guard(crcLock);
std::lock_guard<std::mutex> guard(crcLock);
const std::string &gamePath = PSP_CoreParameter().fileToStart;
auto it = crcResults.find(gamePath);
@@ -137,10 +137,10 @@ namespace Reporting
const std::string &gamePath = PSP_CoreParameter().fileToStart;
QueueCRC();
lock_guard guard(crcLock);
std::unique_lock<std::mutex> guard(crcLock);
auto it = crcResults.find(gamePath);
while (it == crcResults.end()) {
crcCond.wait(crcLock);
crcCond.wait(guard);
it = crcResults.find(gamePath);
}
+12 -12
View File
@@ -18,8 +18,8 @@
#include <algorithm>
#include <vector>
#include <thread>
#include <mutex>
#include "base/mutex.h"
#include "base/timeutil.h"
#include "i18n/i18n.h"
#include "thread/threadutil.h"
@@ -98,7 +98,7 @@ namespace SaveState
CChunkFileReader::Error Save()
{
lock_guard guard(lock_);
std::lock_guard<std::mutex> guard(lock_);
int n = next_++ % size_;
if ((next_ % size_) == first_)
@@ -129,7 +129,7 @@ namespace SaveState
CChunkFileReader::Error Restore()
{
lock_guard guard(lock_);
std::lock_guard<std::mutex> guard(lock_);
// No valid states left.
if (Empty())
@@ -155,7 +155,7 @@ namespace SaveState
void Compress(std::vector<u8> &result, const std::vector<u8> &state, const std::vector<u8> &base)
{
lock_guard guard(lock_);
std::lock_guard<std::mutex> guard(lock_);
// Bail if we were cleared before locking.
if (first_ == 0 && next_ == 0)
return;
@@ -176,7 +176,7 @@ namespace SaveState
void Decompress(std::vector<u8> &result, const std::vector<u8> &compressed, const std::vector<u8> &base)
{
lock_guard guard(lock_);
std::lock_guard<std::mutex> guard(lock_);
result.clear();
result.reserve(base.size());
auto basePos = base.begin();
@@ -203,7 +203,7 @@ namespace SaveState
void Clear()
{
// This lock is mainly for shutdown.
lock_guard guard(lock_);
std::lock_guard<std::mutex> guard(lock_);
first_ = 0;
next_ = 0;
}
@@ -226,7 +226,7 @@ namespace SaveState
std::vector<StateBuffer> states_;
StateBuffer bases_[2];
std::vector<int> baseMapping_;
recursive_mutex lock_;
std::mutex lock_;
int base_;
int baseUsage_;
@@ -234,7 +234,7 @@ namespace SaveState
static bool needsProcess = false;
static std::vector<Operation> pending;
static recursive_mutex mutex;
static std::mutex mutex;
static bool hasLoadedState = false;
// TODO: Should this be configurable?
@@ -278,7 +278,7 @@ namespace SaveState
void Enqueue(SaveState::Operation op)
{
lock_guard guard(mutex);
std::lock_guard<std::mutex> guard(mutex);
pending.push_back(op);
// Don't actually run it until next frame.
@@ -508,7 +508,7 @@ namespace SaveState
std::vector<Operation> Flush()
{
lock_guard guard(mutex);
std::lock_guard<std::mutex> guard(mutex);
std::vector<Operation> copy = pending;
pending.clear();
@@ -697,7 +697,7 @@ namespace SaveState
// Make sure there's a directory for save slots
pspFileSystem.MkDir("ms0:/PSP/PPSSPP_STATE");
lock_guard guard(mutex);
std::lock_guard<std::mutex> guard(mutex);
rewindStates.Clear();
hasLoadedState = false;
@@ -705,7 +705,7 @@ namespace SaveState
void Shutdown()
{
lock_guard guard(mutex);
std::lock_guard<std::mutex> guard(mutex);
rewindStates.Clear();
}
}
+17 -13
View File
@@ -25,10 +25,10 @@
#include <codecvt>
#endif
#include <thread>
#include <mutex>
#include "math/math_util.h"
#include "thread/threadutil.h"
#include "base/mutex.h"
#include "util/text/utf8.h"
#include "Core/MemMap.h"
@@ -80,9 +80,9 @@ static CoreParameter coreParameter;
static FileLoader *loadedFile;
static std::thread *cpuThread = nullptr;
static std::thread::id cpuThreadID;
static recursive_mutex cpuThreadLock;
static condition_variable cpuThreadCond;
static condition_variable cpuThreadReplyCond;
static std::mutex cpuThreadLock;
static std::condition_variable cpuThreadCond;
static std::condition_variable cpuThreadReplyCond;
static u64 cpuThreadUntil;
bool audioInitialized;
@@ -133,17 +133,21 @@ bool IsOnSeparateCPUThread() {
}
}
void CPU_SetState(CPUThreadState to) {
lock_guard guard(cpuThreadLock);
void CPU_SetStateNoLock(CPUThreadState to) {
cpuThreadState = to;
cpuThreadCond.notify_one();
cpuThreadReplyCond.notify_one();
}
void CPU_SetState(CPUThreadState to) {
std::lock_guard<std::mutex> guard(cpuThreadLock);
CPU_SetStateNoLock(to);
}
bool CPU_NextState(CPUThreadState from, CPUThreadState to) {
lock_guard guard(cpuThreadLock);
std::lock_guard<std::mutex> guard(cpuThreadLock);
if (cpuThreadState == from) {
CPU_SetState(to);
CPU_SetStateNoLock(to);
return true;
} else {
return false;
@@ -151,9 +155,9 @@ bool CPU_NextState(CPUThreadState from, CPUThreadState to) {
}
bool CPU_NextStateNot(CPUThreadState from, CPUThreadState to) {
lock_guard guard(cpuThreadLock);
std::lock_guard<std::mutex> guard(cpuThreadLock);
if (cpuThreadState != from) {
CPU_SetState(to);
CPU_SetStateNoLock(to);
return true;
} else {
return false;
@@ -172,10 +176,10 @@ bool CPU_HasPendingAction() {
return cpuThreadState != CPU_THREAD_RUNNING;
}
void CPU_WaitStatus(condition_variable &cond, bool (*pred)()) {
lock_guard guard(cpuThreadLock);
void CPU_WaitStatus(std::condition_variable &cond, bool (*pred)()) {
std::unique_lock<std::mutex> guard(cpuThreadLock);
while (!pred()) {
cond.wait(cpuThreadLock);
cond.wait(guard);
}
}
+21 -19
View File
@@ -17,10 +17,12 @@
#pragma once
#include "base/mutex.h"
#include <mutex>
#include <condition_variable>
#include <deque>
#include "Core/System.h"
#include "Core/CoreTiming.h"
#include <deque>
template <typename B, typename Event, typename EventType, EventType EVENT_INVALID, EventType EVENT_SYNC, EventType EVENT_FINISH>
struct ThreadEventQueue : public B {
@@ -37,7 +39,7 @@ struct ThreadEventQueue : public B {
void ScheduleEvent(Event ev) {
if (threadEnabled_) {
lock_guard guard(eventsLock_);
std::lock_guard<std::recursive_mutex> guard(eventsLock_);
events_.push_back(ev);
eventsWait_.notify_one();
} else {
@@ -51,7 +53,7 @@ struct ThreadEventQueue : public B {
bool HasEvents() {
if (threadEnabled_) {
lock_guard guard(eventsLock_);
std::lock_guard<std::recursive_mutex> guard(eventsLock_);
return !events_.empty();
} else {
return !events_.empty();
@@ -60,14 +62,14 @@ struct ThreadEventQueue : public B {
void NotifyDrain() {
if (threadEnabled_) {
lock_guard guard(eventsLock_);
std::lock_guard<std::recursive_mutex> guard(eventsLock_);
eventsDrain_.notify_one();
}
}
Event GetNextEvent() {
if (threadEnabled_) {
lock_guard guard(eventsLock_);
std::lock_guard<std::recursive_mutex> guard(eventsLock_);
if (events_.empty()) {
NotifyDrain();
return EVENT_INVALID;
@@ -96,22 +98,22 @@ struct ThreadEventQueue : public B {
return;
}
lock_guard guard(eventsLock_);
std::unique_lock<std::recursive_mutex> guard(eventsLock_);
eventsRunning_ = true;
eventsHaveRun_ = true;
do {
while (!HasEvents() && !ShouldExitEventLoop()) {
eventsWait_.wait(eventsLock_);
while (events_.empty() && !ShouldExitEventLoop()) {
eventsWait_.wait(guard);
}
// Quit the loop if the queue is drained and coreState has tripped, or threading is disabled.
if (!HasEvents()) {
if (events_.empty()) {
break;
}
for (Event ev = GetNextEvent(); EventType(ev) != EVENT_INVALID; ev = GetNextEvent()) {
eventsLock_.unlock();
guard.unlock();
ProcessEventIfApplicable(ev, globalticks);
eventsLock_.lock();
guard.lock();
}
} while (CoreTiming::GetTicks() < globalticks);
@@ -122,7 +124,7 @@ struct ThreadEventQueue : public B {
void SyncBeginFrame() {
if (threadEnabled_) {
lock_guard guard(eventsLock_);
std::lock_guard<std::recursive_mutex> guard(eventsLock_);
eventsHaveRun_ = false;
} else {
eventsHaveRun_ = false;
@@ -151,12 +153,12 @@ struct ThreadEventQueue : public B {
return;
}
lock_guard guard(eventsLock_);
std::unique_lock<std::recursive_mutex> guard(eventsLock_);
// While processing the last event, HasEvents() will be false even while not done.
// So we schedule a nothing event and wait for that to finish.
ScheduleEvent(EVENT_SYNC);
while (ShouldSyncThread(force)) {
eventsDrain_.wait(eventsLock_);
eventsDrain_.wait(guard);
}
}
@@ -165,7 +167,7 @@ struct ThreadEventQueue : public B {
return;
}
lock_guard guard(eventsLock_);
std::lock_guard<std::recursive_mutex> guard(eventsLock_);
// Don't schedule a finish if it's not even running.
if (eventsRunning_) {
ScheduleEvent(EVENT_FINISH);
@@ -197,7 +199,7 @@ private:
bool eventsRunning_;
bool eventsHaveRun_;
std::deque<Event> events_;
recursive_mutex eventsLock_;
condition_variable eventsWait_;
condition_variable eventsDrain_;
std::recursive_mutex eventsLock_; // TODO: Should really make this non-recursive - condition_variable_any is dangerous
std::condition_variable_any eventsWait_;
std::condition_variable_any eventsDrain_;
};
+3
View File
@@ -15,6 +15,8 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <algorithm>
#include "base/logging.h"
#include "base/timeutil.h"
@@ -32,6 +34,7 @@
#include "GPU/Common/TextureDecoder.h"
#include "GPU/Common/SplineCommon.h"
#include "GPU/Common/TransformCommon.h"
#include "GPU/Common/VertexDecoderCommon.h"
#include "GPU/Common/SoftwareTransformCommon.h"
+2 -1
View File
@@ -17,9 +17,10 @@
#pragma once
#include "Common/CommonWindows.h"
#include <d3d11.h>
#include "../Globals.h"
#include "GPU/GPU.h"
#include "GPU/GPUInterface.h"
#include "GPU/D3D11/TextureScalerD3D11.h"
+18 -16
View File
@@ -17,13 +17,15 @@
#include <vector>
#include <set>
#include "base/mutex.h"
#include <mutex>
#include "base/basictypes.h"
#include "GPU/Debugger/Breakpoints.h"
#include "GPU/GPUState.h"
namespace GPUBreakpoints {
static recursive_mutex breaksLock;
static std::mutex breaksLock;
static std::vector<bool> breakCmds;
static std::set<u32> breakPCs;
static std::set<u32> breakTextures;
@@ -175,7 +177,7 @@ bool IsAddressBreakpoint(u32 addr, bool &temp) {
return false;
}
lock_guard guard(breaksLock);
std::lock_guard<std::mutex> guard(breaksLock);
temp = breakPCsTemp.find(addr) != breakPCsTemp.end();
return breakPCs.find(addr) != breakPCs.end();
}
@@ -185,7 +187,7 @@ bool IsAddressBreakpoint(u32 addr) {
return false;
}
lock_guard guard(breaksLock);
std::lock_guard<std::mutex> guard(breaksLock);
return breakPCs.find(addr) != breakPCs.end();
}
@@ -195,7 +197,7 @@ bool IsTextureBreakpoint(u32 addr, bool &temp) {
return false;
}
lock_guard guard(breaksLock);
std::lock_guard<std::mutex> guard(breaksLock);
temp = breakTexturesTemp.find(addr) != breakTexturesTemp.end();
return breakTextures.find(addr) != breakTextures.end();
}
@@ -205,7 +207,7 @@ bool IsTextureBreakpoint(u32 addr) {
return false;
}
lock_guard guard(breaksLock);
std::lock_guard<std::mutex> guard(breaksLock);
return breakTextures.find(addr) != breakTextures.end();
}
@@ -217,7 +219,7 @@ bool IsRenderTargetBreakpoint(u32 addr, bool &temp) {
addr &= 0x003FFFF0;
lock_guard guard(breaksLock);
std::lock_guard<std::mutex> guard(breaksLock);
temp = breakRenderTargetsTemp.find(addr) != breakRenderTargetsTemp.end();
return breakRenderTargets.find(addr) != breakRenderTargets.end();
}
@@ -229,7 +231,7 @@ bool IsRenderTargetBreakpoint(u32 addr) {
addr &= 0x003FFFF0;
lock_guard guard(breaksLock);
std::lock_guard<std::mutex> guard(breaksLock);
return breakRenderTargets.find(addr) != breakRenderTargets.end();
}
@@ -251,7 +253,7 @@ bool IsCmdBreakpoint(u8 cmd) {
}
void AddAddressBreakpoint(u32 addr, bool temp) {
lock_guard guard(breaksLock);
std::lock_guard<std::mutex> guard(breaksLock);
if (temp) {
if (breakPCs.find(addr) == breakPCs.end()) {
@@ -283,7 +285,7 @@ void AddCmdBreakpoint(u8 cmd, bool temp) {
}
void AddTextureBreakpoint(u32 addr, bool temp) {
lock_guard guard(breaksLock);
std::lock_guard<std::mutex> guard(breaksLock);
if (temp) {
if (breakTextures.find(addr) == breakTextures.end()) {
@@ -299,7 +301,7 @@ void AddTextureBreakpoint(u32 addr, bool temp) {
}
void AddRenderTargetBreakpoint(u32 addr, bool temp) {
lock_guard guard(breaksLock);
std::lock_guard<std::mutex> guard(breaksLock);
addr &= 0x003FFFF0;
@@ -321,7 +323,7 @@ void AddTextureChangeTempBreakpoint() {
}
void RemoveAddressBreakpoint(u32 addr) {
lock_guard guard(breaksLock);
std::lock_guard<std::mutex> guard(breaksLock);
breakPCsTemp.erase(addr);
breakPCs.erase(addr);
@@ -335,7 +337,7 @@ void RemoveCmdBreakpoint(u8 cmd) {
}
void RemoveTextureBreakpoint(u32 addr) {
lock_guard guard(breaksLock);
std::lock_guard<std::mutex> guard(breaksLock);
breakTexturesTemp.erase(addr);
breakTextures.erase(addr);
@@ -344,7 +346,7 @@ void RemoveTextureBreakpoint(u32 addr) {
}
void RemoveRenderTargetBreakpoint(u32 addr) {
lock_guard guard(breaksLock);
std::lock_guard<std::mutex> guard(breaksLock);
addr &= 0x003FFFF0;
@@ -363,7 +365,7 @@ void UpdateLastTexture(u32 addr) {
}
void ClearAllBreakpoints() {
lock_guard guard(breaksLock);
std::lock_guard<std::mutex> guard(breaksLock);
breakCmds.clear();
breakCmds.resize(256, false);
@@ -385,7 +387,7 @@ void ClearAllBreakpoints() {
}
void ClearTempBreakpoints() {
lock_guard guard(breaksLock);
std::lock_guard<std::mutex> guard(breaksLock);
// Reset ones that were temporary back to non-breakpoints in the primary arrays.
for (int i = 0; i < 256; ++i) {
+16 -16
View File
@@ -15,7 +15,9 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "base/mutex.h"
#include <mutex>
#include <condition_variable>
#include "GPU/Common/GPUDebugInterface.h"
#include "GPU/Debugger/Stepping.h"
#include "GPU/GPUState.h"
@@ -36,11 +38,11 @@ enum PauseAction {
static bool isStepping;
static recursive_mutex pauseLock;
static condition_variable pauseWait;
static std::mutex pauseLock;
static std::condition_variable pauseWait;
static PauseAction pauseAction = PAUSE_CONTINUE;
static recursive_mutex actionLock;
static condition_variable actionWait;
static std::mutex actionLock;
static std::condition_variable actionWait;
// In case of accidental wakeup.
static volatile bool actionComplete;
@@ -59,22 +61,20 @@ static int bufferLevel;
static u32 pauseSetCmdValue;
static void SetPauseAction(PauseAction act, bool waitComplete = true) {
{
lock_guard guard(pauseLock);
actionLock.lock();
pauseAction = act;
}
pauseLock.lock();
std::unique_lock<std::mutex> guard(actionLock);
pauseAction = act;
pauseLock.unlock();
actionComplete = false;
pauseWait.notify_one();
while (waitComplete && !actionComplete) {
actionWait.wait(actionLock);
actionWait.wait(guard);
}
actionLock.unlock();
}
static void RunPauseAction() {
lock_guard guard(actionLock);
std::lock_guard<std::mutex> guard(actionLock);
switch (pauseAction) {
case PAUSE_CONTINUE:
@@ -118,7 +118,7 @@ static void RunPauseAction() {
}
bool EnterStepping(std::function<void()> callback) {
lock_guard guard(pauseLock);
std::unique_lock<std::mutex> guard(pauseLock);
if (coreState != CORE_RUNNING && coreState != CORE_NEXTFRAME) {
// Shutting down, don't try to step.
return false;
@@ -139,7 +139,7 @@ bool EnterStepping(std::function<void()> callback) {
do {
RunPauseAction();
pauseWait.wait(pauseLock);
pauseWait.wait(guard);
} while (pauseAction != PAUSE_CONTINUE);
gpuDebug->NotifySteppingExit();
@@ -203,4 +203,4 @@ void ForceUnpause() {
actionWait.notify_one();
}
};
} // namespace
+8 -3
View File
@@ -1,7 +1,7 @@
#include <algorithm>
#include <type_traits>
#include <mutex>
#include "base/mutex.h"
#include "base/timeutil.h"
#include "Common/ColorConv.h"
#include "Core/Reporting.h"
@@ -679,7 +679,7 @@ void GPUCommon::UpdatePC(u32 currentPC, u32 newPC) {
}
// Exit the runloop and recalculate things. This happens a lot in some games.
easy_guard innerGuard(listLock);
// No need to lock, this function is always called under listLock.
if (currentList)
downcount = currentList->stall == 0 ? 0x0FFFFFFF : (currentList->stall - newPC) / 4;
else
@@ -936,7 +936,7 @@ void GPUCommon::Execute_Ret(u32 op, u32 diff) {
void GPUCommon::Execute_End(u32 op, u32 diff) {
easy_guard guard(listLock);
const u32 prev = Memory::ReadUnchecked_U32(currentList->pc - 4);
UpdatePC(currentList->pc);
UpdatePC(currentList->pc, currentList->pc);
// Count in a few extra cycles on END.
cyclesExecuted += 60;
@@ -1267,6 +1267,7 @@ void GPUCommon::Execute_WorldMtxNum(u32 op, u32 diff) {
gstate.worldmtxnum = (GE_CMD_WORLDMATRIXNUMBER << 24) | ((op + count) & 0xF);
// Skip over the loaded data, it's done now.
easy_guard innerGuard(listLock);
UpdatePC(currentList->pc, currentList->pc + count * 4);
currentList->pc += count * 4;
}
@@ -1307,6 +1308,7 @@ void GPUCommon::Execute_ViewMtxNum(u32 op, u32 diff) {
gstate.viewmtxnum = (GE_CMD_VIEWMATRIXNUMBER << 24) | ((op + count) & 0xF);
// Skip over the loaded data, it's done now.
easy_guard innerGuard(listLock);
UpdatePC(currentList->pc, currentList->pc + count * 4);
currentList->pc += count * 4;
}
@@ -1347,6 +1349,7 @@ void GPUCommon::Execute_ProjMtxNum(u32 op, u32 diff) {
gstate.projmtxnum = (GE_CMD_PROJMATRIXNUMBER << 24) | ((op + count) & 0x1F);
// Skip over the loaded data, it's done now.
easy_guard innerGuard(listLock);
UpdatePC(currentList->pc, currentList->pc + count * 4);
currentList->pc += count * 4;
}
@@ -1388,6 +1391,7 @@ void GPUCommon::Execute_TgenMtxNum(u32 op, u32 diff) {
gstate.texmtxnum = (GE_CMD_TGENMATRIXNUMBER << 24) | ((op + count) & 0xF);
// Skip over the loaded data, it's done now.
easy_guard innerGuard(listLock);
UpdatePC(currentList->pc, currentList->pc + count * 4);
currentList->pc += count * 4;
}
@@ -1447,6 +1451,7 @@ void GPUCommon::Execute_BoneMtxNum(u32 op, u32 diff) {
gstate.boneMatrixNumber = (GE_CMD_BONEMATRIXNUMBER << 24) | ((op + count) & 0x7F);
// Skip over the loaded data, it's done now.
easy_guard innerGuard(listLock);
UpdatePC(currentList->pc, currentList->pc + count * 4);
currentList->pc += count * 4;
}
+27 -9
View File
@@ -138,7 +138,7 @@ public:
_mm_empty();
return safeResult;
#else
lock_guard guard(curTickEstLock_);
std::lock_guard<std::mutex> guard(curTickEstLock_);
return curTickEst_;
#endif
}
@@ -222,9 +222,6 @@ protected:
virtual void FastRunLoop(DisplayList &list) = 0;
void SlowRunLoop(DisplayList &list);
void UpdatePC(u32 currentPC, u32 newPC);
void UpdatePC(u32 currentPC) {
UpdatePC(currentPC, currentPC);
}
void UpdateState(GPURunState state);
void PopDLQueue();
void CheckDrawSync();
@@ -248,10 +245,31 @@ protected:
void PerformStencilUploadInternal(u32 dest, int size);
void InvalidateCacheInternal(u32 addr, int size, GPUInvalidationType type);
// This mutex can be disabled, which is useful for single core mode.
class optional_mutex {
public:
optional_mutex() : enabled_(true) {}
void set_enabled(bool enabled) {
enabled_ = enabled;
}
void lock() {
if (enabled_)
mutex_.lock();
}
void unlock() {
if (enabled_)
mutex_.unlock();
}
private:
std::mutex mutex_;
bool enabled_;
};
// Allows early unlocking with a guard. Do not double unlock.
class easy_guard {
public:
easy_guard(optional_recursive_mutex &mtx) : mtx_(mtx), locked_(true) { mtx_.lock(); }
easy_guard(optional_mutex &mtx) : mtx_(mtx), locked_(true) { mtx_.lock(); }
~easy_guard() {
if (locked_)
mtx_.unlock();
@@ -265,7 +283,7 @@ protected:
}
private:
optional_recursive_mutex &mtx_;
optional_mutex &mtx_;
bool locked_;
};
@@ -283,7 +301,7 @@ protected:
DisplayList dls[DisplayListMaxCount];
DisplayList *currentList;
DisplayListQueue dlQueue;
optional_recursive_mutex listLock;
optional_mutex listLock;
bool interruptRunning;
GPURunState gpuState;
@@ -309,7 +327,7 @@ private:
alignas(16) std::atomic<u64> curTickEst_;
#else
volatile MEMORY_ALIGNED16(u64) curTickEst_;
recursive_mutex curTickEstLock_;
std::mutex curTickEstLock_;
#endif
inline void UpdateTickEstimate(u64 value) {
@@ -320,7 +338,7 @@ private:
*(__m64 *)&curTickEst_ = result;
_mm_empty();
#else
lock_guard guard(curTickEstLock_);
std::lock_guard<std::mutex> guard(curTickEstLock_);
curTickEst_ = value;
#endif
}
+5 -4
View File
@@ -1,7 +1,8 @@
#include <string>
#include <mutex>
#include "base/logging.h"
#include "base/timeutil.h"
#include "base/mutex.h"
#include "file/chunk_file.h"
#include "Common/CommonTypes.h"
@@ -162,7 +163,7 @@ private:
SimpleAudio *decoder_;
};
static recursive_mutex bgMutex;
static std::mutex bgMutex;
static std::string bgGamePath;
static int playbackOffset;
static AT3PlusReader *at3Reader;
@@ -190,7 +191,7 @@ static void ClearBackgroundAudio(bool hard) {
void SetBackgroundAudioGame(const std::string &path) {
time_update();
lock_guard lock(bgMutex);
std::lock_guard<std::mutex> lock(bgMutex);
if (path == bgGamePath) {
// Do nothing
return;
@@ -211,7 +212,7 @@ void SetBackgroundAudioGame(const std::string &path) {
int PlayBackgroundAudio() {
time_update();
lock_guard lock(bgMutex);
std::lock_guard<std::mutex> lock(bgMutex);
// Immediately stop the sound if it is turned off while playing.
if (!g_Config.bEnableSound) {
+1 -1
View File
@@ -17,8 +17,8 @@
#include <algorithm>
#include <deque>
#include <mutex>
#include "base/mutex.h"
#include "base/colorutil.h"
#include "base/logging.h"
#include "i18n/i18n.h"
+1 -1
View File
@@ -19,8 +19,8 @@
#include <functional>
#include <vector>
#include <mutex>
#include "base/mutex.h"
#include "ui/view.h"
#include "ui/ui_screen.h"
+28 -28
View File
@@ -209,7 +209,7 @@ u64 GameInfo::GetInstallDataSizeInBytes() {
}
bool GameInfo::LoadFromPath(const std::string &gamePath) {
lock_guard guard(lock);
std::lock_guard<std::mutex> guard(lock);
// No need to rebuild if we already have it loaded.
if (filePath_ != gamePath) {
delete fileLoader;
@@ -290,26 +290,26 @@ void GameInfo::ParseParamSFO() {
}
std::string GameInfo::GetTitle() {
lock_guard guard(lock);
std::lock_guard<std::mutex> guard(lock);
return title;
}
bool GameInfo::IsPending() {
lock_guard guard(lock);
std::lock_guard<std::mutex> guard(lock);
return pending;
}
bool GameInfo::IsWorking() {
lock_guard guard(lock);
std::lock_guard<std::mutex> guard(lock);
return working;
}
void GameInfo::SetTitle(const std::string &newTitle) {
lock_guard guard(lock);
std::lock_guard<std::mutex> guard(lock);
title = newTitle;
}
static bool ReadFileToString(IFileSystem *fs, const char *filename, std::string *contents, recursive_mutex *mtx) {
static bool ReadFileToString(IFileSystem *fs, const char *filename, std::string *contents, std::mutex *mtx) {
PSPFileInfo info = fs->GetFileInfo(filename);
if (!info.exists) {
return false;
@@ -321,7 +321,7 @@ static bool ReadFileToString(IFileSystem *fs, const char *filename, std::string
}
if (mtx) {
lock_guard lock(*mtx);
std::lock_guard<std::mutex> lock(*mtx);
contents->resize(info.size);
fs->ReadFile(handle, (u8 *)contents->data(), info.size);
} else {
@@ -332,12 +332,12 @@ static bool ReadFileToString(IFileSystem *fs, const char *filename, std::string
return true;
}
static bool ReadVFSToString(const char *filename, std::string *contents, recursive_mutex *mtx) {
static bool ReadVFSToString(const char *filename, std::string *contents, std::mutex *mtx) {
size_t sz;
uint8_t *data = VFSReadFile(filename, &sz);
if (data) {
if (mtx) {
lock_guard lock(*mtx);
std::lock_guard<std::mutex> lock(*mtx);
*contents = std::string((const char *)data, sz);
} else {
*contents = std::string((const char *)data, sz);
@@ -363,7 +363,7 @@ public:
return;
{
lock_guard lock(info_->lock);
std::lock_guard<std::mutex> lock(info_->lock);
info_->working = true;
info_->fileType = Identify_File(info_->GetFileLoader());
}
@@ -394,14 +394,14 @@ public:
// First, PARAM.SFO.
std::vector<u8> sfoData;
if (pbp.GetSubFile(PBP_PARAM_SFO, &sfoData)) {
lock_guard lock(info_->lock);
std::lock_guard<std::mutex> lock(info_->lock);
info_->paramSFO.ReadSFO(sfoData);
info_->ParseParamSFO();
}
// Then, ICON0.PNG.
if (pbp.GetSubFileSize(PBP_ICON0_PNG) > 0) {
lock_guard lock(info_->lock);
std::lock_guard<std::mutex> lock(info_->lock);
pbp.GetSubFileAsString(PBP_ICON0_PNG, &info_->iconTextureData);
} else {
// Read standard icon
@@ -412,19 +412,19 @@ public:
if (info_->wantFlags & GAMEINFO_WANTBG) {
if (pbp.GetSubFileSize(PBP_PIC0_PNG) > 0) {
lock_guard lock(info_->lock);
std::lock_guard<std::mutex> lock(info_->lock);
pbp.GetSubFileAsString(PBP_PIC0_PNG, &info_->pic0TextureData);
info_->pic0DataLoaded = true;
}
if (pbp.GetSubFileSize(PBP_PIC1_PNG) > 0) {
lock_guard lock(info_->lock);
std::lock_guard<std::mutex> lock(info_->lock);
pbp.GetSubFileAsString(PBP_PIC1_PNG, &info_->pic1TextureData);
info_->pic1DataLoaded = true;
}
}
if (info_->wantFlags & GAMEINFO_WANTSND) {
if (pbp.GetSubFileSize(PBP_SND0_AT3) > 0) {
lock_guard lock(info_->lock);
std::lock_guard<std::mutex> lock(info_->lock);
pbp.GetSubFileAsString(PBP_SND0_AT3, &info_->sndFileData);
info_->sndDataLoaded = true;
}
@@ -436,7 +436,7 @@ public:
handleELF:
// An elf on its own has no usable information, no icons, no nothing.
{
lock_guard lock(info_->lock);
std::lock_guard<std::mutex> lock(info_->lock);
info_->id = "ELF000000";
info_->id_version = "ELF000000_1.00";
info_->paramSFOLoaded = true;
@@ -456,7 +456,7 @@ handleELF:
// Alright, let's fetch the PARAM.SFO.
std::string paramSFOcontents;
if (ReadFileToString(&umd, "/PARAM.SFO", &paramSFOcontents, 0)) {
lock_guard lock(info_->lock);
std::lock_guard<std::mutex> lock(info_->lock);
info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
info_->ParseParamSFO();
}
@@ -474,7 +474,7 @@ handleELF:
{
info_->SetTitle(SaveState::GetTitle(gamePath_));
lock_guard guard(info_->lock);
std::lock_guard<std::mutex> guard(info_->lock);
// Let's use the screenshot as an icon, too.
std::string screenshotPath = ReplaceAll(gamePath_, ".ppst", ".jpg");
@@ -495,7 +495,7 @@ handleELF:
// Alright, let's fetch the PARAM.SFO.
std::string paramSFOcontents;
if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", &paramSFOcontents, 0)) {
lock_guard lock(info_->lock);
std::lock_guard<std::mutex> lock(info_->lock);
info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
info_->ParseParamSFO();
}
@@ -531,18 +531,18 @@ handleELF:
// Alright, let's fetch the PARAM.SFO.
std::string paramSFOcontents;
if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", &paramSFOcontents, nullptr)) {
lock_guard lock(info_->lock);
std::lock_guard<std::mutex> lock(info_->lock);
info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
info_->ParseParamSFO();
if (info_->wantFlags & GAMEINFO_WANTBG) {
ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0TextureData, &info_->lock);
ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0TextureData, nullptr);
info_->pic0DataLoaded = true;
ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1TextureData, &info_->lock);
ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1TextureData, nullptr);
info_->pic1DataLoaded = true;
}
if (info_->wantFlags & GAMEINFO_WANTSND) {
ReadFileToString(&umd, "/PSP_GAME/SND0.AT3", &info_->sndFileData, &info_->lock);
ReadFileToString(&umd, "/PSP_GAME/SND0.AT3", &info_->sndFileData, nullptr);
info_->pic1DataLoaded = true;
}
}
@@ -589,13 +589,13 @@ handleELF:
info_->hasConfig = g_Config.hasGameConfig(info_->id);
if (info_->wantFlags & GAMEINFO_WANTSIZE) {
lock_guard lock(info_->lock);
std::lock_guard<std::mutex> lock(info_->lock);
info_->gameSize = info_->GetGameSizeInBytes();
info_->saveDataSize = info_->GetSaveDataSizeInBytes();
info_->installDataSize = info_->GetInstallDataSizeInBytes();
}
lock_guard lock(info_->lock);
std::lock_guard<std::mutex> lock(info_->lock);
info_->pending = false;
info_->working = false;
// ILOG("Completed writing info for %s", info_->GetTitle().c_str());
@@ -640,7 +640,7 @@ void GameInfoCache::Clear() {
}
for (auto iter = info_.begin(); iter != info_.end(); iter++) {
{
lock_guard lock(iter->second->lock);
std::lock_guard<std::mutex> lock(iter->second->lock);
if (!iter->second->pic0TextureData.empty()) {
iter->second->pic0TextureData.clear();
iter->second->pic0DataLoaded = false;
@@ -678,7 +678,7 @@ void GameInfoCache::Clear() {
void GameInfoCache::FlushBGs() {
for (auto iter = info_.begin(); iter != info_.end(); iter++) {
lock_guard lock(iter->second->lock);
std::lock_guard<std::mutex> lock(iter->second->lock);
if (!iter->second->pic0TextureData.empty()) {
iter->second->pic0TextureData.clear();
iter->second->pic0DataLoaded = false;
@@ -770,7 +770,7 @@ again:
}
{
lock_guard lock(info->lock);
std::lock_guard<std::mutex> lock(info->lock);
info->wantFlags |= wantFlags;
info->pending = true;
}
+2 -2
View File
@@ -19,8 +19,8 @@
#include <string>
#include <map>
#include <mutex>
#include "base/mutex.h"
#include "file/file_util.h"
#include "Core/ELF/ParamSFO.h"
#include "Core/Loaders.h"
@@ -129,7 +129,7 @@ public:
// Don't need to hold it when just passing around the pointer,
// and obviously also not when creating it and holding the only pointer
// to it.
recursive_mutex lock;
std::mutex lock;
std::string id;
std::string id_version;
+2 -2
View File
@@ -673,7 +673,7 @@ const std::string GameBrowser::GetBaseName(const std::string &path) {
UI::EventReturn GameBrowser::GameButtonClick(UI::EventParams &e) {
GameButton *button = static_cast<GameButton *>(e.v);
UI::EventParams e2;
UI::EventParams e2{};
e2.s = button->GamePath();
// Insta-update - here we know we are already on the right thread.
OnChoice.Trigger(e2);
@@ -682,7 +682,7 @@ UI::EventReturn GameBrowser::GameButtonClick(UI::EventParams &e) {
UI::EventReturn GameBrowser::GameButtonHoldClick(UI::EventParams &e) {
GameButton *button = static_cast<GameButton *>(e.v);
UI::EventParams e2;
UI::EventParams e2{};
e2.s = button->GamePath();
// Insta-update - here we know we are already on the right thread.
OnHoldChoice.Trigger(e2);
+4 -4
View File
@@ -35,6 +35,7 @@
#endif
#include <memory>
#include <thread>
#include <mutex>
#if defined(_WIN32)
#include "Windows/DSoundStream.h"
@@ -43,7 +44,6 @@
#include "base/display.h"
#include "base/logging.h"
#include "base/mutex.h"
#include "base/NativeApp.h"
#include "file/vfs.h"
#include "file/zip_read.h"
@@ -139,7 +139,7 @@ struct PendingMessage {
std::string value;
};
static recursive_mutex pendingMutex;
static std::mutex pendingMutex;
static std::vector<PendingMessage> pendingMessages;
static Draw::DrawContext *g_draw;
static Draw::Pipeline *colorPipeline;
@@ -858,7 +858,7 @@ void NativeUpdate(InputState &input) {
PROFILE_END_FRAME();
{
lock_guard lock(pendingMutex);
std::lock_guard<std::mutex> lock(pendingMutex);
for (size_t i = 0; i < pendingMessages.size(); i++) {
HandleGlobalMessage(pendingMessages[i].msg, pendingMessages[i].value);
screenManager->sendMessage(pendingMessages[i].msg.c_str(), pendingMessages[i].value.c_str());
@@ -1010,7 +1010,7 @@ bool NativeAxis(const AxisInput &axis) {
void NativeMessageReceived(const char *message, const char *value) {
// We can only have one message queued.
lock_guard lock(pendingMutex);
std::lock_guard<std::mutex> lock(pendingMutex);
PendingMessage pendingMessage;
pendingMessage.msg = message;
pendingMessage.value = value;
+1 -1
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) {
double now = time_now_d();
lock_guard guard(mutex_);
std::lock_guard<std::mutex> guard(mutex_);
if (checkUnique) {
for (auto iter = messages_.begin(); iter != messages_.end(); ++iter) {
if (iter->text == text || (id && iter->id && !strcmp(iter->id, id))) {
+2 -2
View File
@@ -2,8 +2,8 @@
#include <string>
#include <list>
#include <mutex>
#include "base/mutex.h"
#include "base/basictypes.h"
#include "math/geom2d.h"
@@ -39,7 +39,7 @@ public:
private:
std::list<Message> messages_;
recursive_mutex mutex_;
std::mutex mutex_;
};
class OnScreenMessagesView : public UI::InertView {
+9 -11
View File
@@ -46,19 +46,19 @@ enum class ServerStatus {
static std::thread *serverThread = nullptr;
static ServerStatus serverStatus;
static recursive_mutex serverStatusLock;
static condition_variable serverStatusCond;
static std::mutex serverStatusLock;
static std::condition_variable serverStatusCond;
static bool scanCancelled = false;
static void UpdateStatus(ServerStatus s) {
lock_guard guard(serverStatusLock);
std::lock_guard<std::mutex> guard(serverStatusLock);
serverStatus = s;
serverStatusCond.notify_one();
}
static ServerStatus RetrieveStatus() {
lock_guard guard(serverStatusLock);
std::lock_guard<std::mutex> guard(serverStatusLock);
return serverStatus;
}
@@ -351,7 +351,7 @@ void RemoteISOScreen::CreateViews() {
}
UI::EventReturn RemoteISOScreen::HandleStartServer(UI::EventParams &e) {
lock_guard guard(serverStatusLock);
std::lock_guard<std::mutex> guard(serverStatusLock);
if (serverStatus != ServerStatus::STOPPED) {
return EVENT_SKIPPED;
@@ -365,7 +365,7 @@ UI::EventReturn RemoteISOScreen::HandleStartServer(UI::EventParams &e) {
}
UI::EventReturn RemoteISOScreen::HandleStopServer(UI::EventParams &e) {
lock_guard guard(serverStatusLock);
std::lock_guard<std::mutex> guard(serverStatusLock);
if (serverStatus != ServerStatus::RUNNING) {
return EVENT_SKIPPED;
@@ -385,7 +385,6 @@ UI::EventReturn RemoteISOScreen::HandleBrowse(UI::EventParams &e) {
RemoteISOConnectScreen::RemoteISOConnectScreen() : status_(ScanStatus::SCANNING), nextRetry_(0.0) {
scanCancelled = false;
statusLock_ = new recursive_mutex();
scanThread_ = new std::thread([](RemoteISOConnectScreen *thiz) {
thiz->ExecuteScan();
@@ -404,7 +403,6 @@ RemoteISOConnectScreen::~RemoteISOConnectScreen() {
}
}
delete scanThread_;
delete statusLock_;
}
void RemoteISOConnectScreen::CreateViews() {
@@ -486,12 +484,12 @@ void RemoteISOConnectScreen::ExecuteScan() {
return;
}
lock_guard guard(*statusLock_);
std::lock_guard<std::mutex> guard(statusLock_);
status_ = host_.empty() ? ScanStatus::FAILED : ScanStatus::FOUND;
}
ScanStatus RemoteISOConnectScreen::GetStatus() {
lock_guard guard(*statusLock_);
std::lock_guard<std::mutex> guard(statusLock_);
return status_;
}
@@ -501,7 +499,7 @@ void RemoteISOConnectScreen::ExecuteLoad() {
return;
}
lock_guard guard(*statusLock_);
std::lock_guard<std::mutex> guard(statusLock_);
status_ = result ? ScanStatus::LOADED : ScanStatus::FAILED;
}
+2 -3
View File
@@ -18,14 +18,13 @@
#pragma once
#include <thread>
#include <mutex>
#include "ui/ui_screen.h"
#include "ui/viewgroup.h"
#include "UI/MiscScreens.h"
#include "UI/MainScreen.h"
class recursive_mutex;
class RemoteISOScreen : public UIScreenWithBackground {
public:
RemoteISOScreen();
@@ -69,7 +68,7 @@ protected:
ScanStatus status_;
double nextRetry_;
std::thread *scanThread_;
recursive_mutex *statusLock_;
std::mutex statusLock_;
std::string host_;
int port_;
std::vector<std::string> games_;
+7 -6
View File
@@ -1,8 +1,9 @@
// NOTE: Apologies for the quality of this code, this is really from pre-opensource Dolphin - that is, 2003.
#include <mutex>
#include "base/timeutil.h"
#include "base/NativeApp.h"
#include "base/mutex.h"
#include "i18n/i18n.h"
#include "input/input_state.h"
#include "util/text/utf8.h"
@@ -27,7 +28,7 @@
#include <intrin.h>
#pragma intrinsic(_InterlockedExchange)
static recursive_mutex emuThreadLock;
static std::mutex emuThreadLock;
static HANDLE emuThread;
static volatile long emuThreadReady;
@@ -46,7 +47,7 @@ enum EmuThreadStatus : long
HANDLE EmuThread_GetThreadHandle()
{
lock_guard guard(emuThreadLock);
std::lock_guard<std::mutex> guard(emuThreadLock);
return emuThread;
}
@@ -54,7 +55,7 @@ unsigned int WINAPI TheThread(void *);
void EmuThread_Start()
{
lock_guard guard(emuThreadLock);
std::lock_guard<std::mutex> guard(emuThreadLock);
emuThread = (HANDLE)_beginthreadex(0, 0, &TheThread, 0, 0, 0);
}
@@ -62,7 +63,7 @@ void EmuThread_Stop()
{
// Already stopped?
{
lock_guard guard(emuThreadLock);
std::lock_guard<std::mutex> guard(emuThreadLock);
if (emuThread == NULL || emuThreadReady == THREAD_END)
return;
}
@@ -75,7 +76,7 @@ void EmuThread_Stop()
_dbg_assert_msg_(COMMON, false, "Wait for EmuThread timed out.");
}
{
lock_guard guard(emuThreadLock);
std::lock_guard<std::mutex> guard(emuThreadLock);
CloseHandle(emuThread);
emuThread = 0;
}
+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;
+1 -2
View File
@@ -1,7 +1,6 @@
#pragma once
#include <vector>
#include "base/mutex.h"
#include <map>
#include "InputDevice.h"
extern std::map<int, int> windowsTransTable;
+3 -3
View File
@@ -543,7 +543,7 @@ namespace MainWindow
// Hack: Take the opportunity to show the cursor.
mouseButtonDown = true;
{
lock_guard guard(input_state.lock);
std::lock_guard<std::mutex> guard(input_state.lock);
input_state.mouse_valid = true;
input_state.pointer_down[0] = true;
@@ -589,7 +589,7 @@ namespace MainWindow
prevCursorY = cursorY;
{
lock_guard guard(input_state.lock);
std::lock_guard<std::mutex> guard(input_state.lock);
input_state.pointer_x[0] = GET_X_LPARAM(lParam) * g_dpi_scale;
input_state.pointer_y[0] = GET_Y_LPARAM(lParam) * g_dpi_scale;
}
@@ -612,7 +612,7 @@ namespace MainWindow
// Hack: Take the opportunity to hide the cursor.
mouseButtonDown = false;
{
lock_guard guard(input_state.lock);
std::lock_guard<std::mutex> guard(input_state.lock);
input_state.pointer_down[0] = false;
input_state.pointer_x[0] = GET_X_LPARAM(lParam) * g_dpi_scale;
input_state.pointer_y[0] = GET_Y_LPARAM(lParam) * g_dpi_scale;
+11 -10
View File
@@ -15,11 +15,12 @@
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <queue>
#include <mutex>
#include <thread>
#include "base/basictypes.h"
#include "base/stringutil.h"
#include "base/display.h"
#include "base/mutex.h"
#include "base/NativeApp.h"
#include "base/logging.h"
#include "base/timeutil.h"
@@ -319,7 +320,7 @@ void AndroidVulkanContext::Resize() {
void AndroidVulkanContext::SwapInterval(int interval) {
}
static recursive_mutex frameCommandLock;
static std::mutex frameCommandLock;
static std::queue<FrameCommand> frameCommands;
std::string systemName;
@@ -373,7 +374,7 @@ GraphicsContext *graphicsContext;
static void ProcessFrameCommands(JNIEnv *env);
void PushCommand(std::string cmd, std::string param) {
lock_guard guard(frameCommandLock);
std::lock_guard<std::mutex> guard(frameCommandLock);
frameCommands.push(FrameCommand(cmd, param));
}
@@ -677,7 +678,7 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeRenderer_displayRender(JNIEnv *env,
if (renderer_inited) {
// TODO: Look into if these locks are a perf loss
{
lock_guard guard(input_state.lock);
std::lock_guard<std::mutex> guard(input_state.lock);
input_state.pad_lstick_x = left_joystick_x_async;
input_state.pad_lstick_y = left_joystick_y_async;
@@ -689,7 +690,7 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeRenderer_displayRender(JNIEnv *env,
NativeUpdate(input_state);
{
lock_guard guard(input_state.lock);
std::lock_guard<std::mutex> guard(input_state.lock);
EndInputState(&input_state);
}
@@ -705,7 +706,7 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeRenderer_displayRender(JNIEnv *env,
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}
lock_guard guard(frameCommandLock);
std::lock_guard<std::mutex> guard(frameCommandLock);
if (!nativeActivity) {
while (!frameCommands.empty())
frameCommands.pop();
@@ -763,7 +764,7 @@ extern "C" jboolean JNICALL Java_org_ppsspp_ppsspp_NativeApp_touch
bool retval = NativeTouch(touch);
{
lock_guard guard(input_state.lock);
std::lock_guard<std::mutex> guard(input_state.lock);
if (pointerId >= MAX_POINTERS) {
ELOG("Too many pointers: %i", pointerId);
return false; // We ignore 8+ pointers entirely.
@@ -1000,7 +1001,7 @@ extern "C" jint JNICALL Java_org_ppsspp_ppsspp_NativeApp_getDesiredBackbufferHei
}
static void ProcessFrameCommands(JNIEnv *env) {
lock_guard guard(frameCommandLock);
std::lock_guard<std::mutex> guard(frameCommandLock);
while (!frameCommands.empty()) {
FrameCommand frameCmd;
frameCmd = frameCommands.front();
@@ -1062,7 +1063,7 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
// TODO: Look into if these locks are a perf loss
{
lock_guard guard(input_state.lock);
std::lock_guard<std::mutex> guard(input_state.lock);
input_state.pad_lstick_x = left_joystick_x_async;
input_state.pad_lstick_y = left_joystick_y_async;
@@ -1074,7 +1075,7 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
NativeUpdate(input_state);
{
lock_guard guard(input_state.lock);
std::lock_guard<std::mutex> guard(input_state.lock);
EndInputState(&input_state);
}
-364
View File
@@ -1,364 +0,0 @@
#pragma once
// Simple cross platform mutex implementation.
// Similar to the new C++11 api.
// Windows and pthreads implementations in one.
// TODO: Need to clean up these primitives and put them in a reasonable namespace.
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#include <limits.h>
#include <intrin.h>
// Zap stupid windows defines
// Should move these somewhere clever.
#undef p
#undef DrawText
#undef itoa
#undef min
#undef max
#else
#include <pthread.h>
#include <errno.h>
#include <sys/time.h>
#endif
#include "base/basictypes.h"
struct atomic_flag_init {
atomic_flag_init() : v(false) {
}
bool v;
};
static const atomic_flag_init NATIVE_ATOMIC_FLAG_INIT;
class atomic_flag {
public:
atomic_flag() {
}
atomic_flag(const atomic_flag_init &v) : value(0) {
}
void clear() {
#if defined(_WIN32)
_WriteBarrier();
value = 0;
#else
__sync_lock_release(&value);
#endif
}
// Returns the previous value.
bool test_and_set() {
#if defined(_WIN32)
return InterlockedExchange(&value, 1) != 0;
#else
return __sync_lock_test_and_set(&value, 1) != 0;
#endif
}
private:
volatile unsigned int value;
DISALLOW_COPY_AND_ASSIGN(atomic_flag);
};
class recursive_mutex {
#ifdef _WIN32
typedef CRITICAL_SECTION mutexType;
#else
typedef pthread_mutex_t mutexType;
#endif
public:
recursive_mutex() {
#ifdef _WIN32
InitializeCriticalSection(&mut_);
#else
// Critical sections are recursive so let's make these recursive too.
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&mut_, &attr);
#endif
}
~recursive_mutex() {
#ifdef _WIN32
DeleteCriticalSection(&mut_);
#else
pthread_mutex_destroy(&mut_);
#endif
}
bool trylock() {
#ifdef _WIN32
return TryEnterCriticalSection(&mut_) != FALSE;
#else
return pthread_mutex_trylock(&mut_) != EBUSY;
#endif
}
void lock() {
#ifdef _WIN32
EnterCriticalSection(&mut_);
#else
pthread_mutex_lock(&mut_);
#endif
}
void unlock() {
#ifdef _WIN32
LeaveCriticalSection(&mut_);
#else
pthread_mutex_unlock(&mut_);
#endif
}
mutexType &native_handle() {
return mut_;
}
private:
mutexType mut_;
recursive_mutex(const recursive_mutex &other);
recursive_mutex& operator=(const recursive_mutex& other);
};
class lock_guard {
public:
lock_guard(recursive_mutex &mtx) : mtx_(mtx) {mtx_.lock();}
~lock_guard() {mtx_.unlock();}
private:
recursive_mutex &mtx_;
};
// This mutex can be disabled, which is useful for single core mode.
class optional_recursive_mutex {
public:
optional_recursive_mutex() : enabled_(true) {}
void set_enabled(bool enabled) {
enabled_ = enabled;
}
void lock() {
if (enabled_)
mutex_.lock();
}
void unlock() {
if (enabled_)
mutex_.unlock();
}
bool trylock() {
if (enabled_)
return mutex_.trylock();
else
return true;
}
private:
recursive_mutex mutex_;
bool enabled_;
};
// Like a Windows event, or a modern condition variable.
class event {
public:
#ifdef _WIN32
#else
#endif
event() {
#ifdef _WIN32
event_ = CreateEvent(0, FALSE, FALSE, 0);
#else
pthread_cond_init(&event_, NULL);
#endif
}
~event() {
#ifdef _WIN32
CloseHandle(event_);
#else
pthread_cond_destroy(&event_);
#endif
}
void notify_one() {
#ifdef _WIN32
SetEvent(event_);
#else
pthread_cond_signal(&event_);
#endif
}
// notify_all is not really possible to implement with win32 events?
void wait(recursive_mutex &mtx) {
// broken
#ifdef _WIN32
// This has to be horribly racy.
mtx.lock();
WaitForSingleObject(event_, INFINITE);
ResetEvent(event_); // necessary?
mtx.unlock();
#else
pthread_mutex_lock(&mtx.native_handle());
pthread_cond_wait(&event_, &mtx.native_handle());
pthread_mutex_unlock(&mtx.native_handle());
#endif
}
void wait_for(recursive_mutex &mtx, int milliseconds) {
#ifdef _WIN32
//mtx.unlock();
WaitForSingleObject(event_, milliseconds);
ResetEvent(event_); // necessary?
// mtx.lock();
#else
timespec timeout;
#ifdef __APPLE__
timeval tv;
gettimeofday(&tv, NULL);
timeout.tv_sec = tv.tv_sec;
timeout.tv_nsec = tv.tv_usec * 1000;
#else
clock_gettime(CLOCK_REALTIME, &timeout);
#endif
timeout.tv_sec += milliseconds / 1000;
timeout.tv_nsec += (milliseconds % 1000) * 1000000;
pthread_mutex_lock(&mtx.native_handle());
pthread_cond_timedwait(&event_, &mtx.native_handle(), &timeout);
pthread_mutex_unlock(&mtx.native_handle());
#endif
}
void reset() {
#ifdef _WIN32
ResetEvent(event_);
#endif
}
private:
#ifdef _WIN32
HANDLE event_;
#else
pthread_cond_t event_;
#endif
};
// Win32 CONDITION_VARIABLE is Vista+ only. We thus limit it to our 64-bit builds where
// we can be almost certain that the user isn't running XP.
class condition_variable {
public:
#ifdef _WIN32
#else
#endif
condition_variable() {
#ifdef _WIN32
#ifdef _WIN64
InitializeConditionVariable(&cond_);
#else
sema_ = CreateSemaphore(NULL, 0, LONG_MAX, NULL);
waiting_ = 0;
#endif
#else
pthread_cond_init(&event_, NULL);
#endif
}
~condition_variable() {
#ifdef _WIN32
#ifdef _WIN64
#else
CloseHandle(sema_);
#endif
#else
pthread_cond_destroy(&event_);
#endif
}
void notify_one() {
#ifdef _WIN32
#ifdef _M_X64
WakeConditionVariable(&cond_);
#else
// Should be locked at this time.
if (waiting_ != 0) {
ReleaseSemaphore(sema_, 1, NULL);
}
#endif
#else
pthread_cond_signal(&event_);
#endif
}
// notify_all is not really possible to implement with win32 events?
// Can be done just fine using WakeAllConditionVariable though.
void wait(recursive_mutex &mtx) {
// broken http://msdn.microsoft.com/en-us/library/windows/desktop/ms686301(v=vs.85).aspx
#ifdef _WIN32
#ifdef _M_X64
SleepConditionVariableCS(&cond_, &mtx.native_handle(), INFINITE);
#else
// Since a semaphore keeps a count, the window between unlock and lock won't cause us to deadlock.
// However, we could wake early incorrectly (if the semaphore is signalled already.)
// That's better than deadlocking or forgetting to wake.
waiting_++;
mtx.unlock();
WaitForSingleObject(sema_, INFINITE);
mtx.lock();
waiting_--;
#endif
#else
pthread_cond_wait(&event_, &mtx.native_handle());
#endif
}
void wait_for(recursive_mutex &mtx, int milliseconds) {
#ifdef _WIN32
#ifdef _M_X64
SleepConditionVariableCS(&cond_, &mtx.native_handle(), milliseconds);
#else
// Since a semaphore keeps a count, the window between unlock and lock won't cause us to deadlock.
// However, we could wake early incorrectly (if the semaphore is signalled already.)
// That's better than deadlocking or forgetting to wake.
waiting_++;
mtx.unlock();
WaitForSingleObject(sema_, milliseconds);
mtx.lock();
waiting_--;
#endif
#else
timespec timeout;
#ifdef __APPLE__
timeval tv;
gettimeofday(&tv, NULL);
timeout.tv_sec = tv.tv_sec;
timeout.tv_nsec = tv.tv_usec * 1000;
#else
clock_gettime(CLOCK_REALTIME, &timeout);
#endif
timeout.tv_sec += milliseconds / 1000;
timeout.tv_nsec += (milliseconds % 1000) * 1000000;
pthread_cond_timedwait(&event_, &mtx.native_handle(), &timeout);
#endif
}
private:
#ifdef _WIN32
#ifdef _M_X64
CONDITION_VARIABLE cond_;
#else
HANDLE sema_;
volatile int waiting_;
#endif
#else
pthread_cond_t event_;
#endif
};
+2 -2
View File
@@ -10,9 +10,9 @@
#include <map>
#include <vector>
#include <mutex>
#include "math/lin/vec3.h"
#include "base/mutex.h"
#include "base/basictypes.h"
#include "input/keycodes.h"
@@ -125,7 +125,7 @@ struct AxisPos {
// deltas where applicable.
struct InputState {
// Lock this whenever you access the data in this struct.
mutable recursive_mutex lock;
mutable std::mutex lock;
InputState()
: pad_buttons(0),
pad_last_buttons(0),
-1
View File
@@ -197,7 +197,6 @@
<ClInclude Include="base\compat.h" />
<ClInclude Include="base\display.h" />
<ClInclude Include="base\logging.h" />
<ClInclude Include="base\mutex.h" />
<ClInclude Include="base\NativeApp.h" />
<ClInclude Include="base\stringutil.h" />
<ClInclude Include="base\timeutil.h" />
-3
View File
@@ -116,9 +116,6 @@
<ClInclude Include="ui\ui.h">
<Filter>ui</Filter>
</ClInclude>
<ClInclude Include="base\mutex.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="data\listable.h">
<Filter>data</Filter>
</ClInclude>
+10 -10
View File
@@ -12,19 +12,19 @@ PrioritizedWorkQueue::~PrioritizedWorkQueue() {
}
void PrioritizedWorkQueue::Add(PrioritizedWorkQueueItem *item) {
lock_guard guard(mutex_);
std::lock_guard<std::mutex> guard(mutex_);
queue_.push_back(item);
notEmpty_.notify_one();
}
void PrioritizedWorkQueue::Stop() {
lock_guard guard(mutex_);
std::lock_guard<std::mutex> guard(mutex_);
done_ = true;
notEmpty_.notify_one();
}
void PrioritizedWorkQueue::Flush() {
lock_guard guard(mutex_);
std::lock_guard<std::mutex> guard(mutex_);
int flush_count = 0;
for (auto iter = queue_.begin(); iter != queue_.end(); ++iter) {
delete *iter;
@@ -36,13 +36,13 @@ void PrioritizedWorkQueue::Flush() {
bool PrioritizedWorkQueue::WaitUntilDone(bool all) {
// We'll lock drain this entire time, so make sure you follow that lock ordering.
lock_guard guard(drainMutex_);
std::unique_lock<std::mutex> guard(drainMutex_);
if (AllItemsDone()) {
return true;
}
while (!AllItemsDone()) {
drain_.wait(drainMutex_);
drain_.wait(guard);
if (!all) {
// Return whether empty or not, something just drained.
return AllItemsDone();
@@ -53,32 +53,32 @@ bool PrioritizedWorkQueue::WaitUntilDone(bool all) {
}
void PrioritizedWorkQueue::NotifyDrain() {
lock_guard guard(drainMutex_);
std::lock_guard<std::mutex> guard(drainMutex_);
drain_.notify_one();
}
bool PrioritizedWorkQueue::AllItemsDone() {
lock_guard guard(mutex_);
std::lock_guard<std::mutex> guard(mutex_);
return queue_.empty() && !working_;
}
// The worker should simply call this in a loop. Will block when appropriate.
PrioritizedWorkQueueItem *PrioritizedWorkQueue::Pop() {
{
lock_guard guard(mutex_);
std::lock_guard<std::mutex> guard(mutex_);
working_ = false; // The thread only calls Pop if it's done.
}
// Important: make sure mutex_ is not locked while draining.
NotifyDrain();
lock_guard guard(mutex_);
std::unique_lock<std::mutex> guard(mutex_);
if (done_) {
return 0;
}
while (queue_.empty()) {
notEmpty_.wait(mutex_);
notEmpty_.wait(guard);
if (done_) {
return 0;
}
+5 -5
View File
@@ -2,9 +2,9 @@
#include <vector>
#include <limits>
#include <mutex>
#include "base/basictypes.h"
#include "base/mutex.h"
#include "thread/threadutil.h"
// Priorities can change dynamically.
@@ -46,10 +46,10 @@ private:
bool done_;
bool working_;
recursive_mutex mutex_;
recursive_mutex drainMutex_;
condition_variable notEmpty_;
condition_variable drain_;
std::mutex mutex_;
std::mutex drainMutex_;
std::condition_variable notEmpty_;
std::condition_variable drain_;
std::vector<PrioritizedWorkQueueItem *> queue_;
+8 -7
View File
@@ -26,14 +26,15 @@ void WorkerThread::Process(const std::function<void()>& work) {
}
void WorkerThread::WaitForCompletion() {
done.wait(doneMutex);
std::unique_lock<std::mutex> guard(doneMutex);
done.wait(guard);
}
void WorkerThread::WorkFunc() {
mutex.lock();
std::unique_lock<std::mutex> guard(mutex);
started = true;
while (active) {
signal.wait(mutex);
signal.wait(guard);
if (active) {
work_();
doneMutex.lock();
@@ -50,7 +51,7 @@ LoopWorkerThread::LoopWorkerThread() : WorkerThread(true) {
}
void LoopWorkerThread::Process(const std::function<void(int, int)> &work, int start, int end) {
mutex.lock();
std::lock_guard<std::mutex> guard(mutex);
work_ = work;
start_ = start;
end_ = end;
@@ -59,10 +60,10 @@ void LoopWorkerThread::Process(const std::function<void(int, int)> &work, int st
}
void LoopWorkerThread::WorkFunc() {
mutex.lock();
std::unique_lock<std::mutex> guard(mutex);
started = true;
while (active) {
signal.wait(mutex);
signal.wait(guard);
if (active) {
work_(start_, end_);
doneMutex.lock();
@@ -98,7 +99,7 @@ void ThreadPool::StartWorkers() {
void ThreadPool::ParallelLoop(const std::function<void(int,int)> &loop, int lower, int upper) {
int range = upper - lower;
if (range >= numThreads_ * 2) { // don't parallelize tiny loops (this could be better, maybe add optional parameter that estimates work per iteration)
lock_guard guard(mutex);
std::lock_guard<std::mutex> guard(mutex);
StartWorkers();
// could do slightly better load balancing for the generic case,
+6 -6
View File
@@ -4,8 +4,8 @@
#include <memory>
#include <vector>
#include <thread>
#include "base/mutex.h"
#include <mutex>
#include <condition_variable>
// This is the simplest possible worker implementation I can think of
// but entirely sufficient for the given purpose.
@@ -25,9 +25,9 @@ protected:
virtual void WorkFunc();
std::thread *thread; // the worker thread
::condition_variable signal; // used to signal new work
::condition_variable done; // used to signal work completion
::recursive_mutex mutex, doneMutex; // associated with each respective condition variable
std::condition_variable signal; // used to signal new work
std::condition_variable done; // used to signal work completion
std::mutex mutex, doneMutex; // associated with each respective condition variable
volatile bool active, started;
private:
@@ -65,7 +65,7 @@ public:
private:
int numThreads_;
std::vector<std::shared_ptr<LoopWorkerThread>> workers;
::recursive_mutex mutex; // used to sequentialize loop execution
std::mutex mutex; // used to sequentialize loop execution
bool workersStarted;
void StartWorkers();
+29
View File
@@ -1,6 +1,35 @@
#pragma once
#include <chrono>
#include <mutex>
#include <condition_variable>
// Note that name must be a global string that lives until the end of the process,
// for assertThreadName to work.
void setCurrentThreadName(const char *threadName);
void AssertCurrentThreadName(const char *threadName);
class event {
public:
void notify_one() {
cond_.notify_one();
}
// notify_all is not really possible to implement with win32 events?
void wait(std::mutex &mtx) {
// broken logic
std::unique_lock<std::mutex> guard(mtx);
cond_.wait(guard);
}
void wait_for(std::mutex &mtx, int milliseconds) {
std::unique_lock<std::mutex> guard(mtx);
cond_.wait_for(guard, std::chrono::milliseconds(milliseconds));
}
void reset() {
}
private:
std::condition_variable cond_;
};
+9 -9
View File
@@ -47,7 +47,7 @@ void ScreenManager::update(InputState &input) {
}
void ScreenManager::switchToNext() {
lock_guard guard(inputLock_);
std::lock_guard<std::mutex> guard(inputLock_);
if (!nextScreen_) {
ELOG("switchToNext: No nextScreen_!");
}
@@ -67,7 +67,7 @@ void ScreenManager::switchToNext() {
}
bool ScreenManager::touch(const TouchInput &touch) {
lock_guard guard(inputLock_);
std::lock_guard<std::mutex> guard(inputLock_);
if (!stack_.empty()) {
return stack_.back().screen->touch(touch);
} else {
@@ -76,7 +76,7 @@ bool ScreenManager::touch(const TouchInput &touch) {
}
bool ScreenManager::key(const KeyInput &key) {
lock_guard guard(inputLock_);
std::lock_guard<std::mutex> guard(inputLock_);
if (!stack_.empty()) {
return stack_.back().screen->key(key);
} else {
@@ -85,7 +85,7 @@ bool ScreenManager::key(const KeyInput &key) {
}
bool ScreenManager::axis(const AxisInput &axis) {
lock_guard guard(inputLock_);
std::lock_guard<std::mutex> guard(inputLock_);
if (!stack_.empty()) {
return stack_.back().screen->axis(axis);
} else {
@@ -94,7 +94,7 @@ bool ScreenManager::axis(const AxisInput &axis) {
}
void ScreenManager::resized() {
lock_guard guard(inputLock_);
std::lock_guard<std::mutex> guard(inputLock_);
// Have to notify the whole stack, otherwise there will be problems when going back
// to non-top screens.
for (auto iter = stack_.begin(); iter != stack_.end(); ++iter) {
@@ -168,7 +168,7 @@ Screen *ScreenManager::topScreen() const {
}
void ScreenManager::shutdown() {
lock_guard guard(inputLock_);
std::lock_guard<std::mutex> guard(inputLock_);
for (auto x = stack_.begin(); x != stack_.end(); x++)
delete x->screen;
stack_.clear();
@@ -177,7 +177,7 @@ void ScreenManager::shutdown() {
}
void ScreenManager::push(Screen *screen, int layerFlags) {
lock_guard guard(inputLock_);
std::lock_guard<std::mutex> guard(inputLock_);
if (nextScreen_ && stack_.empty()) {
// we're during init, this is OK
switchToNext();
@@ -192,7 +192,7 @@ void ScreenManager::push(Screen *screen, int layerFlags) {
}
void ScreenManager::pop() {
lock_guard guard(inputLock_);
std::lock_guard<std::mutex> guard(inputLock_);
if (stack_.size()) {
delete stack_.back().screen;
stack_.pop_back();
@@ -223,7 +223,7 @@ void ScreenManager::finishDialog(Screen *dialog, DialogResult result) {
void ScreenManager::processFinishDialog() {
if (dialogFinished_) {
lock_guard guard(inputLock_);
std::lock_guard<std::mutex> guard(inputLock_);
// Another dialog may have been pushed before the render, so search for it.
Screen *caller = 0;
for (size_t i = 0; i < stack_.size(); ++i) {
+2 -2
View File
@@ -14,10 +14,10 @@
#pragma once
#include <vector>
#include <mutex>
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/mutex.h"
#include "base/NativeApp.h"
namespace UI {
@@ -130,7 +130,7 @@ public:
Screen *topScreen() const;
recursive_mutex inputLock_;
std::mutex inputLock_;
private:
void pop();
+1 -1
View File
@@ -19,7 +19,7 @@ UIScreen::~UIScreen() {
}
void UIScreen::DoRecreateViews() {
lock_guard guard(screenManager()->inputLock_);
std::lock_guard<std::mutex> guard(screenManager()->inputLock_);
if (recreateViews_) {
UI::PersistMap persisted;
+4 -5
View File
@@ -1,7 +1,7 @@
#include <queue>
#include <algorithm>
#include <mutex>
#include "base/mutex.h"
#include "base/stringutil.h"
#include "base/timeutil.h"
#include "input/input_state.h"
@@ -20,7 +20,7 @@ namespace UI {
static View *focusedView;
static bool focusMovementEnabled;
bool focusForced;
static recursive_mutex mutex_;
static std::recursive_mutex eventMutex_; // needs recursivity!
const float ITEM_HEIGHT = 64.f;
const float MIN_TEXT_SCALE = 0.8f;
@@ -33,9 +33,8 @@ struct DispatchQueueItem {
std::deque<DispatchQueueItem> g_dispatchQueue;
void EventTriggered(Event *e, EventParams params) {
lock_guard guard(mutex_);
std::unique_lock<std::recursive_mutex> guard(eventMutex_);
DispatchQueueItem item;
item.e = e;
@@ -44,7 +43,7 @@ void EventTriggered(Event *e, EventParams params) {
}
void DispatchEvents() {
lock_guard guard(mutex_);
std::unique_lock<std::recursive_mutex> guard(eventMutex_);
while (!g_dispatchQueue.empty()) {
DispatchQueueItem item = g_dispatchQueue.back();
-1
View File
@@ -16,7 +16,6 @@
#include <vector>
#include "base/logging.h"
#include "base/mutex.h"
#include "base/basictypes.h"
#include "gfx/texture_atlas.h"
#include "math/lin/matrix4x4.h"
+12 -12
View File
@@ -1,8 +1,8 @@
#include <functional>
#include <set>
#include <mutex>
#include "base/logging.h"
#include "base/mutex.h"
#include "base/stringutil.h"
#include "base/timeutil.h"
#include "input/keycodes.h"
@@ -17,7 +17,7 @@ namespace UI {
const float ITEM_HEIGHT = 64.f;
static recursive_mutex focusLock;
static std::mutex focusLock;
static std::vector<int> focusMoves;
extern bool focusForced;
bool dragCaptured[MAX_POINTERS];
@@ -57,7 +57,7 @@ ViewGroup::~ViewGroup() {
}
void ViewGroup::RemoveSubview(View *view) {
lock_guard guard(modifyLock_);
std::lock_guard<std::mutex> guard(modifyLock_);
for (size_t i = 0; i < views_.size(); i++) {
if (views_[i] == view) {
views_.erase(views_.begin() + i);
@@ -68,7 +68,7 @@ void ViewGroup::RemoveSubview(View *view) {
}
void ViewGroup::Clear() {
lock_guard guard(modifyLock_);
std::lock_guard<std::mutex> guard(modifyLock_);
for (size_t i = 0; i < views_.size(); i++) {
delete views_[i];
views_[i] = nullptr;
@@ -77,7 +77,7 @@ void ViewGroup::Clear() {
}
void ViewGroup::PersistData(PersistStatus status, std::string anonId, PersistMap &storage) {
lock_guard guard(modifyLock_);
std::lock_guard<std::mutex> guard(modifyLock_);
std::string tag = Tag();
if (tag.empty()) {
@@ -91,7 +91,7 @@ void ViewGroup::PersistData(PersistStatus status, std::string anonId, PersistMap
}
void ViewGroup::Touch(const TouchInput &input) {
lock_guard guard(modifyLock_);
std::lock_guard<std::mutex> guard(modifyLock_);
for (auto iter = views_.begin(); iter != views_.end(); ++iter) {
// TODO: If there is a transformation active, transform input coordinates accordingly.
if ((*iter)->GetVisibility() == V_VISIBLE)
@@ -109,7 +109,7 @@ void ViewGroup::Query(float x, float y, std::vector<View *> &list) {
}
bool ViewGroup::Key(const KeyInput &input) {
lock_guard guard(modifyLock_);
std::lock_guard<std::mutex> guard(modifyLock_);
bool ret = false;
for (auto iter = views_.begin(); iter != views_.end(); ++iter) {
// TODO: If there is a transformation active, transform input coordinates accordingly.
@@ -120,7 +120,7 @@ bool ViewGroup::Key(const KeyInput &input) {
}
void ViewGroup::Axis(const AxisInput &input) {
lock_guard guard(modifyLock_);
std::lock_guard<std::mutex> guard(modifyLock_);
for (auto iter = views_.begin(); iter != views_.end(); ++iter) {
// TODO: If there is a transformation active, transform input coordinates accordingly.
if ((*iter)->GetVisibility() == V_VISIBLE)
@@ -165,7 +165,7 @@ void ViewGroup::Update(const InputState &input_state) {
}
bool ViewGroup::SetFocus() {
lock_guard guard(modifyLock_);
std::lock_guard<std::mutex> guard(modifyLock_);
if (!CanBeFocused() && !views_.empty()) {
for (size_t i = 0; i < views_.size(); i++) {
if (views_[i]->SetFocus())
@@ -1394,7 +1394,7 @@ bool KeyEvent(const KeyInput &key, ViewGroup *root) {
}
heldKeys.insert(hk);
lock_guard lock(focusLock);
std::lock_guard<std::mutex> lock(focusLock);
focusMoves.push_back(key.keyCode);
retval = true;
}
@@ -1440,7 +1440,7 @@ restart:
key.flags = KEY_DOWN;
KeyEvent(key, root);
lock_guard lock(focusLock);
std::lock_guard<std::mutex> lock(focusLock);
focusMoves.push_back(key.keyCode);
// Cannot modify the current item when looping over a set, so let's do this instead.
@@ -1477,7 +1477,7 @@ void UpdateViewHierarchy(const InputState &input_state, ViewGroup *root) {
}
if (focusMoves.size()) {
lock_guard lock(focusLock);
std::lock_guard<std::mutex> lock(focusLock);
EnableFocusMovement(true);
if (!GetFocusedView()) {
if (root->GetDefaultFocusView()) {
+3 -3
View File
@@ -2,9 +2,9 @@
#include <vector>
#include <set>
#include <mutex>
#include "base/logging.h"
#include "base/mutex.h"
#include "math/geom2d.h"
#include "input/gesture_detector.h"
#include "ui/view.h"
@@ -44,7 +44,7 @@ public:
// Takes ownership! DO NOT add a view to multiple parents!
template <class T>
T *Add(T *view) {
lock_guard guard(modifyLock_);
std::lock_guard<std::mutex> guard(modifyLock_);
views_.push_back(view);
return view;
}
@@ -77,7 +77,7 @@ public:
std::string Describe() const override { return "ViewGroup: " + View::Describe(); }
protected:
recursive_mutex modifyLock_; // Hold this when changing the subviews.
std::mutex modifyLock_; // Hold this when changing the subviews.
std::vector<View *> views_;
View *defaultFocusView_;
Drawable bg_;
+2 -2
View File
@@ -258,7 +258,7 @@ static GraphicsContext *graphicsContext;
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
{
lock_guard guard(input_state.lock);
std::lock_guard<std::mutex> guard(input_state.lock);
UpdateInputState(&input_state);
NativeUpdate(input_state);
EndInputState(&input_state);
@@ -270,7 +270,7 @@ static GraphicsContext *graphicsContext;
- (void)touchX:(float)x y:(float)y code:(int)code pointerId:(int)pointerId
{
lock_guard guard(input_state.lock);
std::lock_guard<std::mutex> guard(input_state.lock);
float scale = [UIScreen mainScreen].scale;