From e8d144f3991b69d775664e66c88814a74f6fec46 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 18 Aug 2018 21:14:52 +0300 Subject: [PATCH] Improve vm::reader_lock Add upgrade() method --- rpcs3/Emu/Memory/vm.cpp | 22 +++++++++++++++++----- rpcs3/Emu/Memory/vm.h | 7 ++++--- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/rpcs3/Emu/Memory/vm.cpp b/rpcs3/Emu/Memory/vm.cpp index 8fa7b92eb4..7b02d8c637 100644 --- a/rpcs3/Emu/Memory/vm.cpp +++ b/rpcs3/Emu/Memory/vm.cpp @@ -155,7 +155,6 @@ namespace vm } reader_lock::reader_lock() - : locked(true) { auto cpu = get_current_cpu_thread(); @@ -175,12 +174,27 @@ namespace vm reader_lock::~reader_lock() { - if (locked) + if (m_upgraded) + { + g_mutex.unlock(); + } + else { g_mutex.unlock_shared(); } } + void reader_lock::upgrade() + { + if (m_upgraded) + { + return; + } + + g_mutex.lock_upgrade(); + m_upgraded = true; + } + writer_lock::writer_lock(int full) : locked(true) { @@ -844,15 +858,13 @@ namespace vm { if (location == vm::user64k || location == vm::user1m) { - g_mutex.lock_upgrade(); + lock.upgrade(); if (!loc) { // Deferred allocation loc = _find_map(0x10000000, 0x10000000, location == vm::user64k ? 0x201 : 0x401); } - - g_mutex.lock_degrade(); } } diff --git a/rpcs3/Emu/Memory/vm.h b/rpcs3/Emu/Memory/vm.h index 9aefb06a8f..b421904520 100644 --- a/rpcs3/Emu/Memory/vm.h +++ b/rpcs3/Emu/Memory/vm.h @@ -64,15 +64,16 @@ namespace vm void temporary_unlock(cpu_thread& cpu) noexcept; void temporary_unlock() noexcept; - struct reader_lock final + class reader_lock final { - const bool locked; + bool m_upgraded = false; + public: reader_lock(const reader_lock&) = delete; reader_lock(); ~reader_lock(); - explicit operator bool() const { return locked; } + void upgrade(); }; struct writer_lock final