osdep/atomic: add emulation for atomic_exchange()

This commit is contained in:
wm4 2018-02-21 11:47:12 +01:00 committed by Kevin Mitchell
parent 74c3c2ccb4
commit b6c7d899ca
1 changed files with 7 additions and 0 deletions

View File

@ -74,6 +74,13 @@ extern pthread_mutex_t mp_atomic_mutex;
#define atomic_fetch_add(a, b) atomic_fetch_op(a, b, +) #define atomic_fetch_add(a, b) atomic_fetch_op(a, b, +)
#define atomic_fetch_and(a, b) atomic_fetch_op(a, b, &) #define atomic_fetch_and(a, b) atomic_fetch_op(a, b, &)
#define atomic_fetch_or(a, b) atomic_fetch_op(a, b, |) #define atomic_fetch_or(a, b) atomic_fetch_op(a, b, |)
#define atomic_exchange(p, new) \
({ __typeof__(p) p_ = (p); \
pthread_mutex_lock(&mp_atomic_mutex); \
__typeof__(p_->v) res_ = p_->v; \
p_->v = (new); \
pthread_mutex_unlock(&mp_atomic_mutex); \
res_; })
#define atomic_compare_exchange_strong(p, old, new) \ #define atomic_compare_exchange_strong(p, old, new) \
({ __typeof__(p) p_ = (p); \ ({ __typeof__(p) p_ = (p); \
__typeof__(old) old_ = (old); \ __typeof__(old) old_ = (old); \