From b6c7d899ca9250147b9eef2a6b9bf8a0596a576d Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 21 Feb 2018 11:47:12 +0100 Subject: osdep/atomic: add emulation for atomic_exchange() --- osdep/atomic.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'osdep') diff --git a/osdep/atomic.h b/osdep/atomic.h index 85773cbcb5..9e1c5be721 100644 --- a/osdep/atomic.h +++ b/osdep/atomic.h @@ -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_and(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) \ ({ __typeof__(p) p_ = (p); \ __typeof__(old) old_ = (old); \ -- cgit v1.2.3