Skip to content

Commit 548ceb7

Browse files
committed
Use std::recusive_mutex
1 parent 3fa7065 commit 548ceb7

5 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/FSWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ FSError FSWrapper::FSOpenFileWrapper(const char *path, const char *mode, FSFileH
249249
if (fd >= 0) {
250250
auto fileHandle = getNewFileHandle();
251251
if (fileHandle) {
252-
std::lock_guard<std::mutex> lock(openFilesMutex);
252+
std::lock_guard lock(openFilesMutex);
253253

254254
fileHandle->handle = (((uint32_t) fileHandle.get()) & 0x0FFFFFFF) | 0x30000000;
255255
*handle = fileHandle->handle;

src/FSWrapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ class FSWrapper : public IFSWrapper {
134134
std::string pPathToReplace;
135135
std::string pReplacePathWith;
136136
bool pIsWriteable = false;
137-
std::mutex openFilesMutex;
138-
std::mutex openDirsMutex;
137+
std::recursive_mutex openFilesMutex;
138+
std::recursive_mutex openDirsMutex;
139139
std::vector<std::shared_ptr<FileInfo>> openFiles;
140140
std::vector<std::shared_ptr<DirInfoBase>> openDirs;
141141
};

src/FileUtils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
#include <unistd.h>
1313

1414
namespace {
15-
std::mutex sWorkingDirMutex;
15+
std::recursive_mutex sWorkingDirMutex;
1616
std::map<FSAClientHandle, std::string> sWorkingDirs;
1717
} // namespace
1818

19-
std::mutex gFSLayerMutex;
19+
std::recursive_mutex gFSLayerMutex;
2020
std::vector<std::unique_ptr<IFSWrapper>> gFSLayers;
2121

22-
std::string getFullPathGeneric(const FSAClientHandle client, const char *path, std::mutex &mutex, const std::map<FSAClientHandle, std::string> &map) {
22+
std::string getFullPathGeneric(const FSAClientHandle client, const char *path, std::recursive_mutex &mutex, const std::map<FSAClientHandle, std::string> &map) {
2323
std::lock_guard workingDirLock(mutex);
2424

2525
std::string res;
@@ -39,7 +39,7 @@ std::string getFullPathGeneric(const FSAClientHandle client, const char *path, s
3939
return res;
4040
}
4141

42-
void setWorkingDirGeneric(const FSAClientHandle client, const char *path, std::mutex &mutex, std::map<FSAClientHandle, std::string> &map) {
42+
void setWorkingDirGeneric(const FSAClientHandle client, const char *path, std::recursive_mutex &mutex, std::map<FSAClientHandle, std::string> &map) {
4343
if (!path) {
4444
DEBUG_FUNCTION_LINE_WARN("Path was NULL");
4545
return;

src/FileUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct FSShimWrapperMessage {
5555

5656
extern bool gThreadsRunning;
5757
extern FSIOThreadData gThreadData[3];
58-
extern std::mutex gFSLayerMutex;
58+
extern std::recursive_mutex gFSLayerMutex;
5959
extern std::vector<std::unique_ptr<IFSWrapper>> gFSLayers;
6060

6161
#define fsaShimPrepareRequestReadFile ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, uint8_t * buffer, uint32_t size, uint32_t count, uint32_t pos, FSFileHandle handle, FSAReadFlag readFlags))(0x101C400 + 0x436cc))

src/utils/utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ std::shared_ptr<T> make_shared_nothrow(Args &&...args) noexcept(noexcept(T(std::
1515
}
1616

1717
template<typename T, class Allocator, class Predicate>
18-
bool remove_locked_first_if(std::mutex &mutex, std::vector<T, Allocator> &list, Predicate pred) {
19-
std::lock_guard<std::mutex> lock(mutex);
18+
bool remove_locked_first_if(std::recursive_mutex &mutex, std::vector<T, Allocator> &list, Predicate pred) {
19+
std::lock_guard lock(mutex);
2020
auto it = list.begin();
2121
while (it != list.end()) {
2222
if (pred(*it)) {

0 commit comments

Comments
 (0)