mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-06 08:50:09 +01:00
u_atomic: Add a helper for pointer compare-exchange
Notably this helps with MSVC, which complains about compiling the not-taken branches of the ternary when called with pointer args. Using a version that doesn't have "runtime" sizeof checks eliminates the warnings. Reviewed-by: Jonathan Strobl <jonathan.strobl@gmx.de> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17338>
This commit is contained in:
parent
3efdaaf115
commit
6718bff75b
1 changed files with 14 additions and 0 deletions
|
|
@ -76,6 +76,7 @@
|
|||
*/
|
||||
#define p_atomic_cmpxchg(v, old, _new) \
|
||||
__sync_val_compare_and_swap((v), (old), (_new))
|
||||
#define p_atomic_cmpxchg_ptr(v, old, _new) p_atomic_cmpxchg(v, old, _new)
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -100,6 +101,7 @@
|
|||
#define p_atomic_add_return(_v, _i) (*(_v) = *(_v) + (_i))
|
||||
#define p_atomic_fetch_add(_v, _i) (*(_v) = *(_v) + (_i), *(_v) - (_i))
|
||||
#define p_atomic_cmpxchg(_v, _old, _new) (*(_v) == (_old) ? (*(_v) = (_new), (_old)) : *(_v))
|
||||
#define p_atomic_cmpxchg_ptr(_v, _old, _new) p_atomic_cmpxchg(_v, _old, _new)
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -174,6 +176,12 @@
|
|||
sizeof *(_v) == sizeof(__int64) ? InterlockedCompareExchange64 ((__int64 *)(_v), (__int64)(_new), (__int64)(_old)) : \
|
||||
(assert(!"should not get here"), 0))
|
||||
|
||||
#if defined(_WIN64)
|
||||
#define p_atomic_cmpxchg_ptr(_v, _old, _new) (void *)InterlockedCompareExchange64((__int64 *)(_v), (__int64)(_new), (__int64)(_old))
|
||||
#else
|
||||
#define p_atomic_cmpxchg_ptr(_v, _old, _new) (void *)InterlockedCompareExchange((long *)(_v), (long)(_new), (long)(_old))
|
||||
#endif
|
||||
|
||||
#define PIPE_NATIVE_ATOMIC_XCHG
|
||||
#define p_atomic_xchg(_v, _new) (\
|
||||
sizeof *(_v) == sizeof(long) ? InterlockedExchange ((long *) (_v), (long) (_new)) : \
|
||||
|
|
@ -255,6 +263,12 @@
|
|||
sizeof(*v) == sizeof(uint64_t) ? atomic_cas_64((uint64_t *)(v), (uint64_t)(old), (uint64_t)(_new)) : \
|
||||
(assert(!"should not get here"), 0))
|
||||
|
||||
#if INTPTR_MAX == INT32_MAX
|
||||
#define p_atomic_cmpxchg_ptr(v, old, _new) (__typeof(*v))(atomic_cas_32((uint32_t *)(v), (uint32_t)(old), (uint32_t)(_new)))
|
||||
#else
|
||||
#define p_atomic_cmpxchg_ptr(v, old, _new) (__typeof(*v))(atomic_cas_64((uint64_t *)(v), (uint64_t)(old), (uint64_t)(_new)))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef PIPE_ATOMIC
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue