rpcs3/rpcs3/Emu/Memory/vm_reservation.h
Lassi Hämäläinen 499035512b Split Emu/Memory into more logical headers
- Add vm_locking.h and vm_reservation.h and move relevant functions
  and types to these headers.
- Change include order and make vm_ptr.h, vm_var.h and vm_ref.h headers
  usable invidually and them including vm.h instead of other way around
- Because usage of vm::ptr now requires including vm_ptr.h instead of
  vm.h updated multiple #includes
- Added additional #includes to vm_reservation.h and vm_locking to
  where vm::reservation_* and locking related functions are used
2019-06-25 17:11:10 +03:00

46 lines
1.0 KiB
C++

#pragma once
#include "vm.h"
#include "Utilities/cond.h"
class notifier;
namespace vm
{
// Get reservation status for further atomic update: last update timestamp
inline atomic_t<u64>& reservation_acquire(u32 addr, u32 size)
{
// Access reservation info: stamp and the lock bit
return reinterpret_cast<atomic_t<u64>*>(g_reservations)[addr / 128];
}
// Update reservation status
inline void reservation_update(u32 addr, u32 size, bool lsb = false)
{
// Update reservation info with new timestamp
reservation_acquire(addr, size) += 128;
}
// Get reservation sync variable
inline shared_cond& reservation_notifier(u32 addr, u32 size)
{
return *reinterpret_cast<shared_cond*>(g_reservations2 + addr / 128 * 8);
}
void reservation_lock_internal(atomic_t<u64>&);
inline atomic_t<u64>& reservation_lock(u32 addr, u32 size)
{
auto& res = vm::reservation_acquire(addr, size);
if (UNLIKELY(atomic_storage<u64>::bts(res.raw(), 0)))
{
reservation_lock_internal(res);
}
return res;
}
} // namespace vm