mirror of
https://gitee.com/openharmony/third_party_mesa3d
synced 2024-11-23 07:19:50 +00: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> (cherry picked from commit 6718bff75b4d3823df5f9c1d66eace07d37e9c92) Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18349>
This commit is contained in:
parent
5383fd12d2
commit
6b77710d2d
@ -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…
Reference in New Issue
Block a user