1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

utils/atomic.cpp: Fixup utils::get_unique_tsc()

It was reading s_min_tsc again inside the atomic operation.
Also optimize it a bit.
This commit is contained in:
Elad 2024-11-02 08:27:36 +02:00
parent 0e31aafc09
commit 1417f9b7de

View File

@ -674,19 +674,28 @@ u64 utils::get_unique_tsc()
{
const u64 stamp0 = utils::get_tsc();
return s_min_tsc.atomic_op([&](u64& tsc)
if (!s_min_tsc.fetch_op([=](u64& tsc)
{
if (stamp0 <= s_min_tsc)
if (stamp0 <= tsc)
{
// Add 1 if new stamp is too old
return ++tsc;
return false;
}
else
{
// Update last tsc with new stamp otherwise
return ((tsc = stamp0));
tsc = stamp0;
return true;
}
});
}).second)
{
// Add 1 if new stamp is too old
// Avoid doing it in the atomic operaion because, if it gets here it means there is already much cntention
// So break the race (at least on x86)
return s_min_tsc.add_fetch(1);
}
return stamp0;
}
atomic_t<u16>* root_info::slot_alloc(uptr ptr) noexcept