1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-24 13:54:17 +01:00

[dxvk] Add function to safely acquire a resource

This commit is contained in:
Philip Rebohle 2024-10-18 03:25:49 +02:00
parent 4f4f9177cc
commit 5975dde85f

View File

@ -513,6 +513,28 @@ namespace dxvk {
return m_useCount.load(std::memory_order_acquire) >= getIncrement(access);
}
/**
* \brief Tries to acquire reference
*
* If the reference count is zero at the time this is called,
* the method will fail, otherwise the reference count will
* be incremented by one. This is useful to safely obtain a
* pointer from a look-up table that does not own references.
* \returns \c true on success
*/
Rc<DxvkPagedResource> tryAcquire() {
uint64_t increment = getIncrement(DxvkAccess::None);
uint64_t refCount = m_useCount.load(std::memory_order_acquire);
do {
if (!refCount)
return nullptr;
} while (!m_useCount.compare_exchange_strong( refCount,
refCount + increment, std::memory_order_relaxed));
return Rc<DxvkPagedResource>::unsafeCreate(this);
}
/**
* \brief Queries sparse page table
*