Rewrite cpu_thread::suspend_all

Now it's a function of higher order.
Make only one thread do the hard work of thread pausing.
This commit is contained in:
Nekotekina 2020-10-09 20:33:12 +03:00
parent 6d83c9cc0e
commit 050c3e1d6b
10 changed files with 299 additions and 415 deletions

View file

@ -497,33 +497,25 @@ namespace vm
void reservation_op_internal(u32 addr, std::function<bool()> func)
{
const auto _cpu = get_current_cpu_thread();
// Acknowledge contender if necessary (TODO: check)
_cpu->state += cpu_flag::wait;
const bool ok = cpu_thread::suspend_all(get_current_cpu_thread(), [&]
{
cpu_thread::suspend_all cpu_lock(_cpu);
// Wait to acquire unique lock
while (vm::reservation_acquire(addr, 128).bts(std::countr_zero<u32>(vm::rsrv_unique_lock)))
{
busy_wait(100);
}
if (func())
{
// Success, release all locks if necessary
vm::reservation_acquire(addr, 128) += 63;
vm::reservation_acquire(addr, 128) += 127;
return true;
}
else
{
// Fake update (TODO)
vm::reservation_acquire(addr, 128) += 63;
vm::reservation_acquire(addr, 128) -= 1;
return false;
}
}
});
vm::reservation_notifier(addr, 128).notify_all();
if (ok)
{
vm::reservation_notifier(addr, 128).notify_all();
}
}
void reservation_escape_internal()