mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
vkd3d-common: Introduce vkd3d_atomic_compare_exchange_u32().
This commit is contained in:
parent
bfbd29efe6
commit
5c8a90a6c9
Notes:
Alexandre Julliard
2024-04-25 00:15:41 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/829
@ -431,6 +431,17 @@ static inline uint32_t vkd3d_atomic_increment_u32(uint32_t volatile *x)
|
||||
return vkd3d_atomic_add_fetch_u32(x, 1);
|
||||
}
|
||||
|
||||
static inline bool vkd3d_atomic_compare_exchange_u32(uint32_t volatile *x, uint32_t expected, uint32_t val)
|
||||
{
|
||||
#if HAVE_SYNC_BOOL_COMPARE_AND_SWAP
|
||||
return __sync_bool_compare_and_swap(x, expected, val);
|
||||
#elif defined(_WIN32)
|
||||
return InterlockedCompareExchange((LONG *)x, val, expected) == expected;
|
||||
#else
|
||||
# error "vkd3d_atomic_compare_exchange_u32() not implemented for this platform"
|
||||
#endif
|
||||
}
|
||||
|
||||
struct vkd3d_mutex
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
@ -2350,7 +2350,7 @@ static void *vkd3d_desc_object_cache_get(struct vkd3d_desc_object_cache *cache)
|
||||
i = vkd3d_atomic_increment_u32(&cache->next_index) & HEAD_INDEX_MASK;
|
||||
for (;;)
|
||||
{
|
||||
if (vkd3d_atomic_compare_exchange(&cache->heads[i].spinlock, 0, 1))
|
||||
if (vkd3d_atomic_compare_exchange_u32(&cache->heads[i].spinlock, 0, 1))
|
||||
{
|
||||
if ((u.object = cache->heads[i].head))
|
||||
{
|
||||
@ -2381,7 +2381,7 @@ static void vkd3d_desc_object_cache_push(struct vkd3d_desc_object_cache *cache,
|
||||
i = vkd3d_atomic_increment_u32(&cache->next_index) & HEAD_INDEX_MASK;
|
||||
for (;;)
|
||||
{
|
||||
if (vkd3d_atomic_compare_exchange(&cache->heads[i].spinlock, 0, 1))
|
||||
if (vkd3d_atomic_compare_exchange_u32(&cache->heads[i].spinlock, 0, 1))
|
||||
break;
|
||||
i = (i + 1) & HEAD_INDEX_MASK;
|
||||
}
|
||||
@ -2695,10 +2695,10 @@ static void d3d12_desc_mark_as_modified(struct d3d12_desc *dst, struct d3d12_des
|
||||
head = descriptor_heap->dirty_list_head;
|
||||
|
||||
/* Only one thread can swap the value away from zero. */
|
||||
if (!vkd3d_atomic_compare_exchange(&dst->next, 0, (head << 1) | 1))
|
||||
if (!vkd3d_atomic_compare_exchange_u32(&dst->next, 0, (head << 1) | 1))
|
||||
return;
|
||||
/* Now it is safe to modify 'next' to another nonzero value if necessary. */
|
||||
while (!vkd3d_atomic_compare_exchange(&descriptor_heap->dirty_list_head, head, i))
|
||||
while (!vkd3d_atomic_compare_exchange_u32(&descriptor_heap->dirty_list_head, head, i))
|
||||
{
|
||||
head = descriptor_heap->dirty_list_head;
|
||||
vkd3d_atomic_exchange(&dst->next, (head << 1) | 1);
|
||||
|
@ -204,11 +204,6 @@ union vkd3d_thread_handle
|
||||
void *handle;
|
||||
};
|
||||
|
||||
static inline bool vkd3d_atomic_compare_exchange(unsigned int volatile *x, unsigned int cmp, unsigned int xchg)
|
||||
{
|
||||
return InterlockedCompareExchange((LONG volatile *)x, xchg, cmp) == cmp;
|
||||
}
|
||||
|
||||
static inline unsigned int vkd3d_atomic_exchange(unsigned int volatile *x, unsigned int val)
|
||||
{
|
||||
return InterlockedExchange((LONG volatile *)x, val);
|
||||
@ -229,15 +224,6 @@ union vkd3d_thread_handle
|
||||
void *handle;
|
||||
};
|
||||
|
||||
# if HAVE_SYNC_BOOL_COMPARE_AND_SWAP
|
||||
static inline bool vkd3d_atomic_compare_exchange(unsigned int volatile *x, unsigned int cmp, unsigned int xchg)
|
||||
{
|
||||
return __sync_bool_compare_and_swap(x, cmp, xchg);
|
||||
}
|
||||
# else
|
||||
# error "vkd3d_atomic_compare_exchange() not implemented for this platform"
|
||||
# endif
|
||||
|
||||
# if HAVE_ATOMIC_EXCHANGE_N
|
||||
static inline unsigned int vkd3d_atomic_exchange(unsigned int volatile *x, unsigned int val)
|
||||
{
|
||||
@ -735,7 +721,7 @@ static inline bool vkd3d_view_incref(void *desc)
|
||||
if (refcount <= 0)
|
||||
return false;
|
||||
}
|
||||
while (!vkd3d_atomic_compare_exchange(&h->refcount, refcount, refcount + 1));
|
||||
while (!vkd3d_atomic_compare_exchange_u32(&h->refcount, refcount, refcount + 1));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user