mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-26 04:32:35 +01:00
Improve vm::reader_lock
Add upgrade() method
This commit is contained in:
parent
6ec4a88eb5
commit
e8d144f399
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user