mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-20 10:54:16 +01:00
[dxvk] Add function to safely acquire a resource
This commit is contained in:
parent
c7a9c626f5
commit
800792a67d
@ -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
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user