mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-12 12:45:56 +00:00
Use shared_first_mutex (#3179)
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions
This commit is contained in:
parent
0594dac405
commit
efa7093f34
3 changed files with 49 additions and 1 deletions
|
@ -689,6 +689,7 @@ set(COMMON src/common/logging/backend.cpp
|
||||||
src/common/recursive_lock.cpp
|
src/common/recursive_lock.cpp
|
||||||
src/common/recursive_lock.h
|
src/common/recursive_lock.h
|
||||||
src/common/sha1.h
|
src/common/sha1.h
|
||||||
|
src/common/shared_first_mutex.h
|
||||||
src/common/signal_context.h
|
src/common/signal_context.h
|
||||||
src/common/signal_context.cpp
|
src/common/signal_context.cpp
|
||||||
src/common/singleton.h
|
src/common/singleton.h
|
||||||
|
|
46
src/common/shared_first_mutex.h
Normal file
46
src/common/shared_first_mutex.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
namespace Common {
|
||||||
|
|
||||||
|
// Like std::shared_mutex, but reader has priority over writer.
|
||||||
|
class SharedFirstMutex {
|
||||||
|
public:
|
||||||
|
void lock() {
|
||||||
|
std::unique_lock<std::mutex> lock(mtx);
|
||||||
|
cv.wait(lock, [this]() { return !writer_active && readers == 0; });
|
||||||
|
writer_active = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlock() {
|
||||||
|
std::lock_guard<std::mutex> lock(mtx);
|
||||||
|
writer_active = false;
|
||||||
|
cv.notify_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
void lock_shared() {
|
||||||
|
std::unique_lock<std::mutex> lock(mtx);
|
||||||
|
cv.wait(lock, [this]() { return !writer_active; });
|
||||||
|
++readers;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlock_shared() {
|
||||||
|
std::lock_guard<std::mutex> lock(mtx);
|
||||||
|
if (--readers == 0) {
|
||||||
|
cv.notify_all();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::mutex mtx;
|
||||||
|
std::condition_variable cv;
|
||||||
|
int readers = 0;
|
||||||
|
bool writer_active = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Common
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
#include "common/recursive_lock.h"
|
#include "common/recursive_lock.h"
|
||||||
|
#include "common/shared_first_mutex.h"
|
||||||
#include "video_core/buffer_cache/buffer_cache.h"
|
#include "video_core/buffer_cache/buffer_cache.h"
|
||||||
#include "video_core/page_manager.h"
|
#include "video_core/page_manager.h"
|
||||||
#include "video_core/renderer_vulkan/vk_pipeline_cache.h"
|
#include "video_core/renderer_vulkan/vk_pipeline_cache.h"
|
||||||
|
@ -122,7 +123,7 @@ private:
|
||||||
AmdGpu::Liverpool* liverpool;
|
AmdGpu::Liverpool* liverpool;
|
||||||
Core::MemoryManager* memory;
|
Core::MemoryManager* memory;
|
||||||
boost::icl::interval_set<VAddr> mapped_ranges;
|
boost::icl::interval_set<VAddr> mapped_ranges;
|
||||||
std::shared_mutex mapped_ranges_mutex;
|
Common::SharedFirstMutex mapped_ranges_mutex;
|
||||||
PipelineCache pipeline_cache;
|
PipelineCache pipeline_cache;
|
||||||
|
|
||||||
boost::container::static_vector<
|
boost::container::static_vector<
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue