Merge pull request #2312 from lioncash/locks

general: Use deducation guides for std::lock_guard and std::unique_lock
This commit is contained in:
bunnei 2019-04-01 14:36:24 -04:00 committed by GitHub
commit e0eee250bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 77 additions and 75 deletions

View File

@ -16,22 +16,22 @@ DetachedTasks::DetachedTasks() {
} }
void DetachedTasks::WaitForAllTasks() { void DetachedTasks::WaitForAllTasks() {
std::unique_lock<std::mutex> lock(mutex); std::unique_lock lock{mutex};
cv.wait(lock, [this]() { return count == 0; }); cv.wait(lock, [this]() { return count == 0; });
} }
DetachedTasks::~DetachedTasks() { DetachedTasks::~DetachedTasks() {
std::unique_lock<std::mutex> lock(mutex); std::unique_lock lock{mutex};
ASSERT(count == 0); ASSERT(count == 0);
instance = nullptr; instance = nullptr;
} }
void DetachedTasks::AddTask(std::function<void()> task) { void DetachedTasks::AddTask(std::function<void()> task) {
std::unique_lock<std::mutex> lock(instance->mutex); std::unique_lock lock{instance->mutex};
++instance->count; ++instance->count;
std::thread([task{std::move(task)}]() { std::thread([task{std::move(task)}]() {
task(); task();
std::unique_lock<std::mutex> lock(instance->mutex); std::unique_lock lock{instance->mutex};
--instance->count; --instance->count;
std::notify_all_at_thread_exit(instance->cv, std::move(lock)); std::notify_all_at_thread_exit(instance->cv, std::move(lock));
}) })

View File

@ -46,12 +46,12 @@ public:
} }
void AddBackend(std::unique_ptr<Backend> backend) { void AddBackend(std::unique_ptr<Backend> backend) {
std::lock_guard<std::mutex> lock(writing_mutex); std::lock_guard lock{writing_mutex};
backends.push_back(std::move(backend)); backends.push_back(std::move(backend));
} }
void RemoveBackend(std::string_view backend_name) { void RemoveBackend(std::string_view backend_name) {
std::lock_guard<std::mutex> lock(writing_mutex); std::lock_guard lock{writing_mutex};
const auto it = const auto it =
std::remove_if(backends.begin(), backends.end(), std::remove_if(backends.begin(), backends.end(),
[&backend_name](const auto& i) { return backend_name == i->GetName(); }); [&backend_name](const auto& i) { return backend_name == i->GetName(); });
@ -80,7 +80,7 @@ private:
backend_thread = std::thread([&] { backend_thread = std::thread([&] {
Entry entry; Entry entry;
auto write_logs = [&](Entry& e) { auto write_logs = [&](Entry& e) {
std::lock_guard<std::mutex> lock(writing_mutex); std::lock_guard lock{writing_mutex};
for (const auto& backend : backends) { for (const auto& backend : backends) {
backend->Write(e); backend->Write(e);
} }

View File

@ -15,7 +15,7 @@ namespace Common {
class Event { class Event {
public: public:
void Set() { void Set() {
std::lock_guard<std::mutex> lk(mutex); std::lock_guard lk{mutex};
if (!is_set) { if (!is_set) {
is_set = true; is_set = true;
condvar.notify_one(); condvar.notify_one();
@ -23,14 +23,14 @@ public:
} }
void Wait() { void Wait() {
std::unique_lock<std::mutex> lk(mutex); std::unique_lock lk{mutex};
condvar.wait(lk, [&] { return is_set; }); condvar.wait(lk, [&] { return is_set; });
is_set = false; is_set = false;
} }
template <class Clock, class Duration> template <class Clock, class Duration>
bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) { bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) {
std::unique_lock<std::mutex> lk(mutex); std::unique_lock lk{mutex};
if (!condvar.wait_until(lk, time, [this] { return is_set; })) if (!condvar.wait_until(lk, time, [this] { return is_set; }))
return false; return false;
is_set = false; is_set = false;
@ -38,7 +38,7 @@ public:
} }
void Reset() { void Reset() {
std::unique_lock<std::mutex> lk(mutex); std::unique_lock lk{mutex};
// no other action required, since wait loops on the predicate and any lingering signal will // no other action required, since wait loops on the predicate and any lingering signal will
// get cleared on the first iteration // get cleared on the first iteration
is_set = false; is_set = false;
@ -56,7 +56,7 @@ public:
/// Blocks until all "count" threads have called Sync() /// Blocks until all "count" threads have called Sync()
void Sync() { void Sync() {
std::unique_lock<std::mutex> lk(mutex); std::unique_lock lk{mutex};
const std::size_t current_generation = generation; const std::size_t current_generation = generation;
if (++waiting == count) { if (++waiting == count) {

View File

@ -78,7 +78,7 @@ public:
T PopWait() { T PopWait() {
if (Empty()) { if (Empty()) {
std::unique_lock<std::mutex> lock(cv_mutex); std::unique_lock lock{cv_mutex};
cv.wait(lock, [this]() { return !Empty(); }); cv.wait(lock, [this]() { return !Empty(); });
} }
T t; T t;
@ -137,7 +137,7 @@ public:
template <typename Arg> template <typename Arg>
void Push(Arg&& t) { void Push(Arg&& t) {
std::lock_guard<std::mutex> lock(write_lock); std::lock_guard lock{write_lock};
spsc_queue.Push(t); spsc_queue.Push(t);
} }

View File

@ -22,7 +22,7 @@
namespace Core { namespace Core {
void CpuBarrier::NotifyEnd() { void CpuBarrier::NotifyEnd() {
std::unique_lock<std::mutex> lock(mutex); std::unique_lock lock{mutex};
end = true; end = true;
condition.notify_all(); condition.notify_all();
} }
@ -34,7 +34,7 @@ bool CpuBarrier::Rendezvous() {
} }
if (!end) { if (!end) {
std::unique_lock<std::mutex> lock(mutex); std::unique_lock lock{mutex};
--cores_waiting; --cores_waiting;
if (!cores_waiting) { if (!cores_waiting) {
@ -131,7 +131,7 @@ void Cpu::Reschedule() {
reschedule_pending = false; reschedule_pending = false;
// Lock the global kernel mutex when we manipulate the HLE state // Lock the global kernel mutex when we manipulate the HLE state
std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock); std::lock_guard lock{HLE::g_hle_lock};
scheduler->Reschedule(); scheduler->Reschedule();
} }

View File

@ -30,7 +30,7 @@ private:
explicit Device(std::weak_ptr<TouchState>&& touch_state) : touch_state(touch_state) {} explicit Device(std::weak_ptr<TouchState>&& touch_state) : touch_state(touch_state) {}
std::tuple<float, float, bool> GetStatus() const override { std::tuple<float, float, bool> GetStatus() const override {
if (auto state = touch_state.lock()) { if (auto state = touch_state.lock()) {
std::lock_guard<std::mutex> guard(state->mutex); std::lock_guard guard{state->mutex};
return std::make_tuple(state->touch_x, state->touch_y, state->touch_pressed); return std::make_tuple(state->touch_x, state->touch_y, state->touch_pressed);
} }
return std::make_tuple(0.0f, 0.0f, false); return std::make_tuple(0.0f, 0.0f, false);
@ -81,7 +81,7 @@ void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) {
if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y))
return; return;
std::lock_guard<std::mutex> guard(touch_state->mutex); std::lock_guard guard{touch_state->mutex};
touch_state->touch_x = static_cast<float>(framebuffer_x - framebuffer_layout.screen.left) / touch_state->touch_x = static_cast<float>(framebuffer_x - framebuffer_layout.screen.left) /
(framebuffer_layout.screen.right - framebuffer_layout.screen.left); (framebuffer_layout.screen.right - framebuffer_layout.screen.left);
touch_state->touch_y = static_cast<float>(framebuffer_y - framebuffer_layout.screen.top) / touch_state->touch_y = static_cast<float>(framebuffer_y - framebuffer_layout.screen.top) /
@ -91,7 +91,7 @@ void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) {
} }
void EmuWindow::TouchReleased() { void EmuWindow::TouchReleased() {
std::lock_guard<std::mutex> guard(touch_state->mutex); std::lock_guard guard{touch_state->mutex};
touch_state->touch_pressed = false; touch_state->touch_pressed = false;
touch_state->touch_x = 0; touch_state->touch_x = 0;
touch_state->touch_y = 0; touch_state->touch_y = 0;

View File

@ -34,7 +34,7 @@ static void ThreadWakeupCallback(u64 thread_handle, [[maybe_unused]] s64 cycles_
const auto& system = Core::System::GetInstance(); const auto& system = Core::System::GetInstance();
// Lock the global kernel mutex when we enter the kernel HLE. // Lock the global kernel mutex when we enter the kernel HLE.
std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock); std::lock_guard lock{HLE::g_hle_lock};
SharedPtr<Thread> thread = SharedPtr<Thread> thread =
system.Kernel().RetrieveThreadFromWakeupCallbackHandleTable(proper_handle); system.Kernel().RetrieveThreadFromWakeupCallbackHandleTable(proper_handle);

View File

@ -2138,7 +2138,7 @@ void CallSVC(u32 immediate) {
MICROPROFILE_SCOPE(Kernel_SVC); MICROPROFILE_SCOPE(Kernel_SVC);
// Lock the global kernel mutex when we enter the kernel HLE. // Lock the global kernel mutex when we enter the kernel HLE.
std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock); std::lock_guard lock{HLE::g_hle_lock};
const FunctionDef* info = GetSVCInfo(immediate); const FunctionDef* info = GetSVCInfo(immediate);
if (info) { if (info) {

View File

@ -335,7 +335,7 @@ void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) {
} }
bool Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) { bool Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) {
std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock); std::lock_guard lock{HLE::g_hle_lock};
if (buffer.size() < sizeof(AmiiboFile)) { if (buffer.size() < sizeof(AmiiboFile)) {
return false; return false;
} }

View File

@ -18,13 +18,13 @@ using std::chrono::microseconds;
namespace Core { namespace Core {
void PerfStats::BeginSystemFrame() { void PerfStats::BeginSystemFrame() {
std::lock_guard<std::mutex> lock(object_mutex); std::lock_guard lock{object_mutex};
frame_begin = Clock::now(); frame_begin = Clock::now();
} }
void PerfStats::EndSystemFrame() { void PerfStats::EndSystemFrame() {
std::lock_guard<std::mutex> lock(object_mutex); std::lock_guard lock{object_mutex};
auto frame_end = Clock::now(); auto frame_end = Clock::now();
accumulated_frametime += frame_end - frame_begin; accumulated_frametime += frame_end - frame_begin;
@ -35,13 +35,13 @@ void PerfStats::EndSystemFrame() {
} }
void PerfStats::EndGameFrame() { void PerfStats::EndGameFrame() {
std::lock_guard<std::mutex> lock(object_mutex); std::lock_guard lock{object_mutex};
game_frames += 1; game_frames += 1;
} }
PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us) { PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us) {
std::lock_guard<std::mutex> lock(object_mutex); std::lock_guard lock{object_mutex};
const auto now = Clock::now(); const auto now = Clock::now();
// Walltime elapsed since stats were reset // Walltime elapsed since stats were reset
@ -67,7 +67,7 @@ PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us
} }
double PerfStats::GetLastFrameTimeScale() { double PerfStats::GetLastFrameTimeScale() {
std::lock_guard<std::mutex> lock(object_mutex); std::lock_guard lock{object_mutex};
constexpr double FRAME_LENGTH = 1.0 / 60; constexpr double FRAME_LENGTH = 1.0 / 60;
return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH; return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH;

View File

@ -36,18 +36,18 @@ struct KeyButtonPair {
class KeyButtonList { class KeyButtonList {
public: public:
void AddKeyButton(int key_code, KeyButton* key_button) { void AddKeyButton(int key_code, KeyButton* key_button) {
std::lock_guard<std::mutex> guard(mutex); std::lock_guard guard{mutex};
list.push_back(KeyButtonPair{key_code, key_button}); list.push_back(KeyButtonPair{key_code, key_button});
} }
void RemoveKeyButton(const KeyButton* key_button) { void RemoveKeyButton(const KeyButton* key_button) {
std::lock_guard<std::mutex> guard(mutex); std::lock_guard guard{mutex};
list.remove_if( list.remove_if(
[key_button](const KeyButtonPair& pair) { return pair.key_button == key_button; }); [key_button](const KeyButtonPair& pair) { return pair.key_button == key_button; });
} }
void ChangeKeyStatus(int key_code, bool pressed) { void ChangeKeyStatus(int key_code, bool pressed) {
std::lock_guard<std::mutex> guard(mutex); std::lock_guard guard{mutex};
for (const KeyButtonPair& pair : list) { for (const KeyButtonPair& pair : list) {
if (pair.key_code == key_code) if (pair.key_code == key_code)
pair.key_button->status.store(pressed); pair.key_button->status.store(pressed);
@ -55,7 +55,7 @@ public:
} }
void ChangeAllKeyStatus(bool pressed) { void ChangeAllKeyStatus(bool pressed) {
std::lock_guard<std::mutex> guard(mutex); std::lock_guard guard{mutex};
for (const KeyButtonPair& pair : list) { for (const KeyButtonPair& pair : list) {
pair.key_button->status.store(pressed); pair.key_button->status.store(pressed);
} }

View File

@ -39,7 +39,7 @@ public:
void Tilt(int x, int y) { void Tilt(int x, int y) {
auto mouse_move = Common::MakeVec(x, y) - mouse_origin; auto mouse_move = Common::MakeVec(x, y) - mouse_origin;
if (is_tilting) { if (is_tilting) {
std::lock_guard<std::mutex> guard(tilt_mutex); std::lock_guard guard{tilt_mutex};
if (mouse_move.x == 0 && mouse_move.y == 0) { if (mouse_move.x == 0 && mouse_move.y == 0) {
tilt_angle = 0; tilt_angle = 0;
} else { } else {
@ -51,13 +51,13 @@ public:
} }
void EndTilt() { void EndTilt() {
std::lock_guard<std::mutex> guard(tilt_mutex); std::lock_guard guard{tilt_mutex};
tilt_angle = 0; tilt_angle = 0;
is_tilting = false; is_tilting = false;
} }
std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() { std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() {
std::lock_guard<std::mutex> guard(status_mutex); std::lock_guard guard{status_mutex};
return status; return status;
} }
@ -93,7 +93,7 @@ private:
old_q = q; old_q = q;
{ {
std::lock_guard<std::mutex> guard(tilt_mutex); std::lock_guard guard{tilt_mutex};
// Find the quaternion describing current 3DS tilting // Find the quaternion describing current 3DS tilting
q = Common::MakeQuaternion( q = Common::MakeQuaternion(
@ -115,7 +115,7 @@ private:
// Update the sensor state // Update the sensor state
{ {
std::lock_guard<std::mutex> guard(status_mutex); std::lock_guard guard{status_mutex};
status = std::make_tuple(gravity, angular_rate); status = std::make_tuple(gravity, angular_rate);
} }
} }

View File

@ -55,22 +55,22 @@ public:
: guid{std::move(guid_)}, port{port_}, sdl_joystick{joystick, deleter} {} : guid{std::move(guid_)}, port{port_}, sdl_joystick{joystick, deleter} {}
void SetButton(int button, bool value) { void SetButton(int button, bool value) {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard lock{mutex};
state.buttons[button] = value; state.buttons[button] = value;
} }
bool GetButton(int button) const { bool GetButton(int button) const {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard lock{mutex};
return state.buttons.at(button); return state.buttons.at(button);
} }
void SetAxis(int axis, Sint16 value) { void SetAxis(int axis, Sint16 value) {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard lock{mutex};
state.axes[axis] = value; state.axes[axis] = value;
} }
float GetAxis(int axis) const { float GetAxis(int axis) const {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard lock{mutex};
return state.axes.at(axis) / 32767.0f; return state.axes.at(axis) / 32767.0f;
} }
@ -92,12 +92,12 @@ public:
} }
void SetHat(int hat, Uint8 direction) { void SetHat(int hat, Uint8 direction) {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard lock{mutex};
state.hats[hat] = direction; state.hats[hat] = direction;
} }
bool GetHatDirection(int hat, Uint8 direction) const { bool GetHatDirection(int hat, Uint8 direction) const {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard lock{mutex};
return (state.hats.at(hat) & direction) != 0; return (state.hats.at(hat) & direction) != 0;
} }
/** /**
@ -140,7 +140,7 @@ private:
* Get the nth joystick with the corresponding GUID * Get the nth joystick with the corresponding GUID
*/ */
std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickByGUID(const std::string& guid, int port) { std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickByGUID(const std::string& guid, int port) {
std::lock_guard<std::mutex> lock(joystick_map_mutex); std::lock_guard lock{joystick_map_mutex};
const auto it = joystick_map.find(guid); const auto it = joystick_map.find(guid);
if (it != joystick_map.end()) { if (it != joystick_map.end()) {
while (it->second.size() <= port) { while (it->second.size() <= port) {
@ -161,7 +161,8 @@ std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickByGUID(const std::string& g
std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickBySDLID(SDL_JoystickID sdl_id) { std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickBySDLID(SDL_JoystickID sdl_id) {
auto sdl_joystick = SDL_JoystickFromInstanceID(sdl_id); auto sdl_joystick = SDL_JoystickFromInstanceID(sdl_id);
const std::string guid = GetGUID(sdl_joystick); const std::string guid = GetGUID(sdl_joystick);
std::lock_guard<std::mutex> lock(joystick_map_mutex);
std::lock_guard lock{joystick_map_mutex};
auto map_it = joystick_map.find(guid); auto map_it = joystick_map.find(guid);
if (map_it != joystick_map.end()) { if (map_it != joystick_map.end()) {
auto vec_it = std::find_if(map_it->second.begin(), map_it->second.end(), auto vec_it = std::find_if(map_it->second.begin(), map_it->second.end(),
@ -198,8 +199,9 @@ void SDLState::InitJoystick(int joystick_index) {
LOG_ERROR(Input, "failed to open joystick {}", joystick_index); LOG_ERROR(Input, "failed to open joystick {}", joystick_index);
return; return;
} }
std::string guid = GetGUID(sdl_joystick); const std::string guid = GetGUID(sdl_joystick);
std::lock_guard<std::mutex> lock(joystick_map_mutex);
std::lock_guard lock{joystick_map_mutex};
if (joystick_map.find(guid) == joystick_map.end()) { if (joystick_map.find(guid) == joystick_map.end()) {
auto joystick = std::make_shared<SDLJoystick>(guid, 0, sdl_joystick); auto joystick = std::make_shared<SDLJoystick>(guid, 0, sdl_joystick);
joystick_map[guid].emplace_back(std::move(joystick)); joystick_map[guid].emplace_back(std::move(joystick));
@ -221,7 +223,7 @@ void SDLState::CloseJoystick(SDL_Joystick* sdl_joystick) {
std::string guid = GetGUID(sdl_joystick); std::string guid = GetGUID(sdl_joystick);
std::shared_ptr<SDLJoystick> joystick; std::shared_ptr<SDLJoystick> joystick;
{ {
std::lock_guard<std::mutex> lock(joystick_map_mutex); std::lock_guard lock{joystick_map_mutex};
// This call to guid is safe since the joystick is guaranteed to be in the map // This call to guid is safe since the joystick is guaranteed to be in the map
auto& joystick_guid_list = joystick_map[guid]; auto& joystick_guid_list = joystick_map[guid];
const auto joystick_it = const auto joystick_it =
@ -274,7 +276,7 @@ void SDLState::HandleGameControllerEvent(const SDL_Event& event) {
} }
void SDLState::CloseJoysticks() { void SDLState::CloseJoysticks() {
std::lock_guard<std::mutex> lock(joystick_map_mutex); std::lock_guard lock{joystick_map_mutex};
joystick_map.clear(); joystick_map.clear();
} }

View File

@ -10,7 +10,7 @@ namespace Tegra {
void DebugContext::DoOnEvent(Event event, void* data) { void DebugContext::DoOnEvent(Event event, void* data) {
{ {
std::unique_lock<std::mutex> lock(breakpoint_mutex); std::unique_lock lock{breakpoint_mutex};
// TODO(Subv): Commit the rasterizer's caches so framebuffers, render targets, etc. will // TODO(Subv): Commit the rasterizer's caches so framebuffers, render targets, etc. will
// show on debug widgets // show on debug widgets
@ -32,7 +32,7 @@ void DebugContext::DoOnEvent(Event event, void* data) {
void DebugContext::Resume() { void DebugContext::Resume() {
{ {
std::lock_guard<std::mutex> lock(breakpoint_mutex); std::lock_guard lock{breakpoint_mutex};
// Tell all observers that we are about to resume // Tell all observers that we are about to resume
for (auto& breakpoint_observer : breakpoint_observers) { for (auto& breakpoint_observer : breakpoint_observers) {

View File

@ -40,7 +40,7 @@ public:
/// Constructs the object such that it observes events of the given DebugContext. /// Constructs the object such that it observes events of the given DebugContext.
explicit BreakPointObserver(std::shared_ptr<DebugContext> debug_context) explicit BreakPointObserver(std::shared_ptr<DebugContext> debug_context)
: context_weak(debug_context) { : context_weak(debug_context) {
std::unique_lock<std::mutex> lock(debug_context->breakpoint_mutex); std::unique_lock lock{debug_context->breakpoint_mutex};
debug_context->breakpoint_observers.push_back(this); debug_context->breakpoint_observers.push_back(this);
} }
@ -48,7 +48,7 @@ public:
auto context = context_weak.lock(); auto context = context_weak.lock();
if (context) { if (context) {
{ {
std::unique_lock<std::mutex> lock(context->breakpoint_mutex); std::unique_lock lock{context->breakpoint_mutex};
context->breakpoint_observers.remove(this); context->breakpoint_observers.remove(this);
} }

View File

@ -95,13 +95,13 @@ struct SynchState final {
std::condition_variable frames_condition; std::condition_variable frames_condition;
void IncrementFramesCounter() { void IncrementFramesCounter() {
std::lock_guard<std::mutex> lock{frames_mutex}; std::lock_guard lock{frames_mutex};
++queued_frame_count; ++queued_frame_count;
} }
void DecrementFramesCounter() { void DecrementFramesCounter() {
{ {
std::lock_guard<std::mutex> lock{frames_mutex}; std::lock_guard lock{frames_mutex};
--queued_frame_count; --queued_frame_count;
if (queued_frame_count) { if (queued_frame_count) {
@ -113,7 +113,7 @@ struct SynchState final {
void WaitForFrames() { void WaitForFrames() {
{ {
std::lock_guard<std::mutex> lock{frames_mutex}; std::lock_guard lock{frames_mutex};
if (!queued_frame_count) { if (!queued_frame_count) {
return; return;
} }
@ -121,14 +121,14 @@ struct SynchState final {
// Wait for the GPU to be idle (all commands to be executed) // Wait for the GPU to be idle (all commands to be executed)
{ {
std::unique_lock<std::mutex> lock{frames_mutex}; std::unique_lock lock{frames_mutex};
frames_condition.wait(lock, [this] { return !queued_frame_count; }); frames_condition.wait(lock, [this] { return !queued_frame_count; });
} }
} }
void SignalCommands() { void SignalCommands() {
{ {
std::unique_lock<std::mutex> lock{commands_mutex}; std::unique_lock lock{commands_mutex};
if (queue.Empty()) { if (queue.Empty()) {
return; return;
} }
@ -138,7 +138,7 @@ struct SynchState final {
} }
void WaitForCommands() { void WaitForCommands() {
std::unique_lock<std::mutex> lock{commands_mutex}; std::unique_lock lock{commands_mutex};
commands_condition.wait(lock, [this] { return !queue.Empty(); }); commands_condition.wait(lock, [this] { return !queue.Empty(); });
} }

View File

@ -84,7 +84,7 @@ public:
/// Write any cached resources overlapping the specified region back to memory /// Write any cached resources overlapping the specified region back to memory
void FlushRegion(CacheAddr addr, std::size_t size) { void FlushRegion(CacheAddr addr, std::size_t size) {
std::lock_guard<std::recursive_mutex> lock{mutex}; std::lock_guard lock{mutex};
const auto& objects{GetSortedObjectsFromRegion(addr, size)}; const auto& objects{GetSortedObjectsFromRegion(addr, size)};
for (auto& object : objects) { for (auto& object : objects) {
@ -94,7 +94,7 @@ public:
/// Mark the specified region as being invalidated /// Mark the specified region as being invalidated
void InvalidateRegion(CacheAddr addr, u64 size) { void InvalidateRegion(CacheAddr addr, u64 size) {
std::lock_guard<std::recursive_mutex> lock{mutex}; std::lock_guard lock{mutex};
const auto& objects{GetSortedObjectsFromRegion(addr, size)}; const auto& objects{GetSortedObjectsFromRegion(addr, size)};
for (auto& object : objects) { for (auto& object : objects) {
@ -108,7 +108,7 @@ public:
/// Invalidates everything in the cache /// Invalidates everything in the cache
void InvalidateAll() { void InvalidateAll() {
std::lock_guard<std::recursive_mutex> lock{mutex}; std::lock_guard lock{mutex};
while (interval_cache.begin() != interval_cache.end()) { while (interval_cache.begin() != interval_cache.end()) {
Unregister(*interval_cache.begin()->second.begin()); Unregister(*interval_cache.begin()->second.begin());
@ -133,7 +133,7 @@ protected:
/// Register an object into the cache /// Register an object into the cache
virtual void Register(const T& object) { virtual void Register(const T& object) {
std::lock_guard<std::recursive_mutex> lock{mutex}; std::lock_guard lock{mutex};
object->SetIsRegistered(true); object->SetIsRegistered(true);
interval_cache.add({GetInterval(object), ObjectSet{object}}); interval_cache.add({GetInterval(object), ObjectSet{object}});
@ -143,7 +143,7 @@ protected:
/// Unregisters an object from the cache /// Unregisters an object from the cache
virtual void Unregister(const T& object) { virtual void Unregister(const T& object) {
std::lock_guard<std::recursive_mutex> lock{mutex}; std::lock_guard lock{mutex};
object->SetIsRegistered(false); object->SetIsRegistered(false);
rasterizer.UpdatePagesCachedCount(object->GetCpuAddr(), object->GetSizeInBytes(), -1); rasterizer.UpdatePagesCachedCount(object->GetCpuAddr(), object->GetSizeInBytes(), -1);
@ -153,14 +153,14 @@ protected:
/// Returns a ticks counter used for tracking when cached objects were last modified /// Returns a ticks counter used for tracking when cached objects were last modified
u64 GetModifiedTicks() { u64 GetModifiedTicks() {
std::lock_guard<std::recursive_mutex> lock{mutex}; std::lock_guard lock{mutex};
return ++modified_ticks; return ++modified_ticks;
} }
/// Flushes the specified object, updating appropriate cache state as needed /// Flushes the specified object, updating appropriate cache state as needed
void FlushObject(const T& object) { void FlushObject(const T& object) {
std::lock_guard<std::recursive_mutex> lock{mutex}; std::lock_guard lock{mutex};
if (!object->IsDirty()) { if (!object->IsDirty()) {
return; return;

View File

@ -24,7 +24,7 @@ constexpr u32 TIMEOUT_SECONDS = 30;
struct Client::Impl { struct Client::Impl {
Impl(std::string host, std::string username, std::string token) Impl(std::string host, std::string username, std::string token)
: host{std::move(host)}, username{std::move(username)}, token{std::move(token)} { : host{std::move(host)}, username{std::move(username)}, token{std::move(token)} {
std::lock_guard<std::mutex> lock(jwt_cache.mutex); std::lock_guard lock{jwt_cache.mutex};
if (this->username == jwt_cache.username && this->token == jwt_cache.token) { if (this->username == jwt_cache.username && this->token == jwt_cache.token) {
jwt = jwt_cache.jwt; jwt = jwt_cache.jwt;
} }
@ -151,7 +151,7 @@ struct Client::Impl {
if (result.result_code != Common::WebResult::Code::Success) { if (result.result_code != Common::WebResult::Code::Success) {
LOG_ERROR(WebService, "UpdateJWT failed"); LOG_ERROR(WebService, "UpdateJWT failed");
} else { } else {
std::lock_guard<std::mutex> lock(jwt_cache.mutex); std::lock_guard lock{jwt_cache.mutex};
jwt_cache.username = username; jwt_cache.username = username;
jwt_cache.token = token; jwt_cache.token = token;
jwt_cache.jwt = jwt = result.returned_data; jwt_cache.jwt = jwt = result.returned_data;

View File

@ -163,6 +163,6 @@ void QtProfileSelector::SelectProfile(
void QtProfileSelector::MainWindowFinishedSelection(std::optional<Service::Account::UUID> uuid) { void QtProfileSelector::MainWindowFinishedSelection(std::optional<Service::Account::UUID> uuid) {
// Acquire the HLE mutex // Acquire the HLE mutex
std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock); std::lock_guard lock{HLE::g_hle_lock};
callback(uuid); callback(uuid);
} }

View File

@ -141,12 +141,12 @@ void QtSoftwareKeyboard::SendTextCheckDialog(std::u16string error_message,
void QtSoftwareKeyboard::MainWindowFinishedText(std::optional<std::u16string> text) { void QtSoftwareKeyboard::MainWindowFinishedText(std::optional<std::u16string> text) {
// Acquire the HLE mutex // Acquire the HLE mutex
std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock); std::lock_guard lock{HLE::g_hle_lock};
text_output(text); text_output(text);
} }
void QtSoftwareKeyboard::MainWindowFinishedCheckDialog() { void QtSoftwareKeyboard::MainWindowFinishedCheckDialog() {
// Acquire the HLE mutex // Acquire the HLE mutex
std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock); std::lock_guard lock{HLE::g_hle_lock};
finished_check(); finished_check();
} }

View File

@ -104,12 +104,12 @@ void QtWebBrowser::OpenPage(std::string_view url, std::function<void()> unpack_r
void QtWebBrowser::MainWindowUnpackRomFS() { void QtWebBrowser::MainWindowUnpackRomFS() {
// Acquire the HLE mutex // Acquire the HLE mutex
std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock); std::lock_guard lock{HLE::g_hle_lock};
unpack_romfs_callback(); unpack_romfs_callback();
} }
void QtWebBrowser::MainWindowFinishedBrowsing() { void QtWebBrowser::MainWindowFinishedBrowsing() {
// Acquire the HLE mutex // Acquire the HLE mutex
std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock); std::lock_guard lock{HLE::g_hle_lock};
finished_callback(); finished_callback();
} }

View File

@ -67,7 +67,7 @@ void EmuThread::run() {
was_active = false; was_active = false;
} else { } else {
std::unique_lock<std::mutex> lock(running_mutex); std::unique_lock lock{running_mutex};
running_cv.wait(lock, [this] { return IsRunning() || exec_step || stop_run; }); running_cv.wait(lock, [this] { return IsRunning() || exec_step || stop_run; });
} }
} }

View File

@ -53,7 +53,7 @@ public:
* @note This function is thread-safe * @note This function is thread-safe
*/ */
void SetRunning(bool running) { void SetRunning(bool running) {
std::unique_lock<std::mutex> lock(running_mutex); std::unique_lock lock{running_mutex};
this->running = running; this->running = running;
lock.unlock(); lock.unlock();
running_cv.notify_all(); running_cv.notify_all();