Improve vm::reader_lock

Add upgrade() method
This commit is contained in:
Nekotekina 2018-08-18 21:14:52 +03:00
parent 6ec4a88eb5
commit e8d144f399
2 changed files with 21 additions and 8 deletions

View file

@ -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();
}
}