mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d-common: Introduce vkd3d_atomic_exchange_ptr().
This commit is contained in:
committed by
Alexandre Julliard
parent
b1c326ce56
commit
af33caf036
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
@@ -442,6 +442,17 @@ static inline bool vkd3d_atomic_compare_exchange_u32(uint32_t volatile *x, uint3
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline bool vkd3d_atomic_compare_exchange_ptr(void * volatile *x, void *expected, void *val)
|
||||
{
|
||||
#if HAVE_SYNC_BOOL_COMPARE_AND_SWAP
|
||||
return __sync_bool_compare_and_swap(x, expected, val);
|
||||
#elif defined(_WIN32)
|
||||
return InterlockedCompareExchangePointer(x, val, expected) == expected;
|
||||
#else
|
||||
# error "vkd3d_atomic_compare_exchange_ptr() not implemented for this platform"
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint32_t vkd3d_atomic_exchange_u32(uint32_t volatile *x, uint32_t val)
|
||||
{
|
||||
#if HAVE_ATOMIC_EXCHANGE_N
|
||||
@@ -460,6 +471,24 @@ static inline uint32_t vkd3d_atomic_exchange_u32(uint32_t volatile *x, uint32_t
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void *vkd3d_atomic_exchange_ptr(void * volatile *x, void *val)
|
||||
{
|
||||
#if HAVE_ATOMIC_EXCHANGE_N
|
||||
return __atomic_exchange_n(x, val, __ATOMIC_SEQ_CST);
|
||||
#elif defined(_WIN32)
|
||||
return InterlockedExchangePointer(x, val);
|
||||
#else
|
||||
void *expected;
|
||||
|
||||
do
|
||||
{
|
||||
expected = *x;
|
||||
} while (!vkd3d_atomic_compare_exchange_ptr(x, expected, val));
|
||||
|
||||
return expected;
|
||||
#endif
|
||||
}
|
||||
|
||||
struct vkd3d_mutex
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
Reference in New Issue
Block a user