diff options
author | wm4 <wm4@nowhere> | 2018-02-21 11:47:12 +0100 |
---|---|---|
committer | Kevin Mitchell <kevmitch@gmail.com> | 2018-02-28 00:55:06 -0800 |
commit | b6c7d899ca9250147b9eef2a6b9bf8a0596a576d (patch) | |
tree | 21943d06bf0a2dcf0c579419faac595e98b571a4 | |
parent | 74c3c2ccb49a46fc58aa7ec2506b6f05731d316b (diff) | |
download | mpv-b6c7d899ca9250147b9eef2a6b9bf8a0596a576d.tar.bz2 mpv-b6c7d899ca9250147b9eef2a6b9bf8a0596a576d.tar.xz |
osdep/atomic: add emulation for atomic_exchange()
-rw-r--r-- | osdep/atomic.h | 7 |
1 files changed, 7 insertions, 0 deletions
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); \ |