diff options
author | NRK <nrk@disroot.org> | 2023-10-18 20:32:16 +0600 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2023-10-20 21:31:09 +0200 |
commit | 2fa695c3f9d4164344228ef4083e87369de3bb33 (patch) | |
tree | 86479e5d70197a27615a55ee47cdb3d3502d63e7 /osdep | |
parent | 3fb4eb2ba47fea78e69937971974f42cba82d1df (diff) | |
download | mpv-2fa695c3f9d4164344228ef4083e87369de3bb33.tar.bz2 mpv-2fa695c3f9d4164344228ef4083e87369de3bb33.tar.xz |
osdep: drop atomic fallback
even msvc (which mpv apparently doesn't support) supports C11 atomics
now. no need to carry around fallback with subtle semantic differences.
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/atomic.h | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/osdep/atomic.h b/osdep/atomic.h index 0bd301f637..ea00cea9b7 100644 --- a/osdep/atomic.h +++ b/osdep/atomic.h @@ -22,90 +22,10 @@ #include <inttypes.h> #include "config.h" -#if HAVE_STDATOMIC #include <stdatomic.h> typedef _Atomic float mp_atomic_float; typedef _Atomic double mp_atomic_double; typedef _Atomic int64_t mp_atomic_int64; typedef _Atomic uint64_t mp_atomic_uint64; -#else - -// Emulate the parts of C11 stdatomic.h needed by mpv. - -typedef struct { unsigned long v; } atomic_ulong; -typedef struct { int v; } atomic_int; -typedef struct { unsigned int v; } atomic_uint; -typedef struct { _Bool v; } atomic_bool; -typedef struct { long long v; } atomic_llong; -typedef struct { uint_least32_t v; } atomic_uint_least32_t; -typedef struct { unsigned long long v; } atomic_ullong; - -typedef struct { float v; } mp_atomic_float; -typedef struct { double v; } mp_atomic_double; -typedef struct { int64_t v; } mp_atomic_int64; -typedef struct { uint64_t v; } mp_atomic_uint64; - -#define ATOMIC_VAR_INIT(x) \ - {.v = (x)} - -#define memory_order_relaxed 1 -#define memory_order_seq_cst 2 -#define memory_order_acq_rel 3 - -#include <pthread.h> - -extern pthread_mutex_t mp_atomic_mutex; - -#define atomic_load(p) \ - ({ __typeof__(p) p_ = (p); \ - pthread_mutex_lock(&mp_atomic_mutex); \ - __typeof__(p_->v) v_ = p_->v; \ - pthread_mutex_unlock(&mp_atomic_mutex); \ - v_; }) -#define atomic_store(p, val) \ - ({ __typeof__(val) val_ = (val); \ - __typeof__(p) p_ = (p); \ - pthread_mutex_lock(&mp_atomic_mutex); \ - p_->v = val_; \ - pthread_mutex_unlock(&mp_atomic_mutex); }) -#define atomic_fetch_op(a, b, op) \ - ({ __typeof__(a) a_ = (a); \ - __typeof__(b) b_ = (b); \ - pthread_mutex_lock(&mp_atomic_mutex); \ - __typeof__(a_->v) v_ = a_->v; \ - a_->v = v_ op b_; \ - pthread_mutex_unlock(&mp_atomic_mutex); \ - v_; }) -#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); \ - __typeof__(new) new_ = (new); \ - pthread_mutex_lock(&mp_atomic_mutex); \ - int res_ = p_->v == *old_; \ - if (res_) { \ - p_->v = new_; \ - } else { \ - *old_ = p_->v; \ - } \ - pthread_mutex_unlock(&mp_atomic_mutex); \ - res_; }) - -#define atomic_load_explicit(a, b) \ - atomic_load(a) - -#define atomic_exchange_explicit(a, b, c) \ - atomic_exchange(a, b) - -#endif /* else HAVE_STDATOMIC */ #endif |