From 591e21a2ebd105c33127d4a792d4d0e1a083fcfc Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 7 Sep 2016 11:26:25 +0200 Subject: osdep: rename atomics.h to atomic.h The standard header is stdatomic.h, so the extra "s" freaks me out every time I look at it. --- audio/out/ao_coreaudio_exclusive.c | 2 +- audio/out/ao_wasapi.h | 2 +- audio/out/internal.h | 2 +- audio/out/pull.c | 2 +- audio/out/push.c | 2 +- common/msg.c | 2 +- input/pipe-win32.c | 2 +- misc/ring.c | 2 +- options/m_config.c | 2 +- osdep/atomic.h | 132 +++++++++++++++++++++++++++++++++++++ osdep/atomics.h | 132 ------------------------------------- osdep/subprocess-win.c | 2 +- stream/stream.c | 2 +- video/out/cocoa_common.m | 2 +- video/out/w32_common.c | 2 +- video/out/x11_common.c | 1 - video/out/x11_common.h | 2 +- 17 files changed, 146 insertions(+), 147 deletions(-) create mode 100644 osdep/atomic.h delete mode 100644 osdep/atomics.h diff --git a/audio/out/ao_coreaudio_exclusive.c b/audio/out/ao_coreaudio_exclusive.c index 49f921cd4c..cc20fd9a51 100644 --- a/audio/out/ao_coreaudio_exclusive.c +++ b/audio/out/ao_coreaudio_exclusive.c @@ -41,7 +41,7 @@ #include "internal.h" #include "audio/format.h" #include "osdep/timer.h" -#include "osdep/atomics.h" +#include "osdep/atomic.h" #include "options/m_option.h" #include "common/msg.h" #include "audio/out/ao_coreaudio_chmap.h" diff --git a/audio/out/ao_wasapi.h b/audio/out/ao_wasapi.h index 3ae50159b3..6dd130b50f 100644 --- a/audio/out/ao_wasapi.h +++ b/audio/out/ao_wasapi.h @@ -29,7 +29,7 @@ #include #include "common/msg.h" -#include "osdep/atomics.h" +#include "osdep/atomic.h" #include "osdep/windows_utils.h" #include "internal.h" #include "ao.h" diff --git a/audio/out/internal.h b/audio/out/internal.h index fdbb423f52..319881b194 100644 --- a/audio/out/internal.h +++ b/audio/out/internal.h @@ -21,7 +21,7 @@ #include #include -#include "osdep/atomics.h" +#include "osdep/atomic.h" #include "audio/out/ao.h" /* global data used by ao.c and ao drivers */ diff --git a/audio/out/pull.c b/audio/out/pull.c index 2175a58db0..5dd6525fc8 100644 --- a/audio/out/pull.c +++ b/audio/out/pull.c @@ -30,7 +30,7 @@ #include "osdep/timer.h" #include "osdep/threads.h" -#include "osdep/atomics.h" +#include "osdep/atomic.h" #include "misc/ring.h" /* diff --git a/audio/out/push.c b/audio/out/push.c index bf5dde46b5..406b0da790 100644 --- a/audio/out/push.c +++ b/audio/out/push.c @@ -35,7 +35,7 @@ #include "osdep/threads.h" #include "osdep/timer.h" -#include "osdep/atomics.h" +#include "osdep/atomic.h" #include "audio/audio.h" #include "audio/audio_buffer.h" diff --git a/common/msg.c b/common/msg.c index 534ba41cb5..b109817c5b 100644 --- a/common/msg.c +++ b/common/msg.c @@ -27,7 +27,7 @@ #include "mpv_talloc.h" #include "misc/bstr.h" -#include "osdep/atomics.h" +#include "osdep/atomic.h" #include "common/common.h" #include "common/global.h" #include "misc/ring.h" diff --git a/input/pipe-win32.c b/input/pipe-win32.c index 3d47fb66c1..a0a0bfef24 100644 --- a/input/pipe-win32.c +++ b/input/pipe-win32.c @@ -19,7 +19,7 @@ #include #include "common/msg.h" -#include "osdep/atomics.h" +#include "osdep/atomic.h" #include "osdep/io.h" #include "input.h" diff --git a/misc/ring.c b/misc/ring.c index 9ba4306511..d72083475d 100644 --- a/misc/ring.c +++ b/misc/ring.c @@ -21,7 +21,7 @@ #include #include #include "mpv_talloc.h" -#include "osdep/atomics.h" +#include "osdep/atomic.h" #include "ring.h" struct mp_ring { diff --git a/options/m_config.c b/options/m_config.c index cb9835012f..695c9569e9 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -39,7 +39,7 @@ #include "common/msg.h" #include "common/msg_control.h" #include "misc/node.h" -#include "osdep/atomics.h" +#include "osdep/atomic.h" static const union m_option_value default_value; diff --git a/osdep/atomic.h b/osdep/atomic.h new file mode 100644 index 0000000000..9028a504eb --- /dev/null +++ b/osdep/atomic.h @@ -0,0 +1,132 @@ +/* + * This file is part of mpv. + * Copyright (c) 2013 Stefano Pigozzi + * + * mpv is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * mpv is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with mpv. If not, see . + */ + +#ifndef MP_ATOMIC_H +#define MP_ATOMIC_H + +#include +#include "config.h" + +#if HAVE_STDATOMIC +#include +#else + +// Emulate the parts of C11 stdatomic.h needed by mpv. +// Still relies on gcc/clang atomic builtins. + +typedef struct { volatile unsigned long v; } atomic_ulong; +typedef struct { volatile int v; } atomic_int; +typedef struct { volatile unsigned int v; } atomic_uint; +typedef struct { volatile _Bool v; } atomic_bool; +typedef struct { volatile long long v; } atomic_llong; +typedef struct { volatile uint_least32_t v; } atomic_uint_least32_t; +typedef struct { volatile unsigned long long v; } atomic_ullong; + +#define ATOMIC_VAR_INIT(x) \ + {.v = (x)} + +#define memory_order_relaxed 1 +#define memory_order_seq_cst 2 + +#define atomic_load_explicit(p, e) atomic_load(p) + +#if HAVE_ATOMIC_BUILTINS + +#define atomic_load(p) \ + __atomic_load_n(&(p)->v, __ATOMIC_SEQ_CST) +#define atomic_store(p, val) \ + __atomic_store_n(&(p)->v, val, __ATOMIC_SEQ_CST) +#define atomic_fetch_add(a, b) \ + __atomic_fetch_add(&(a)->v, b, __ATOMIC_SEQ_CST) +#define atomic_fetch_and(a, b) \ + __atomic_fetch_and(&(a)->v, b, __ATOMIC_SEQ_CST) +#define atomic_fetch_or(a, b) \ + __atomic_fetch_or(&(a)->v, b, __ATOMIC_SEQ_CST) +#define atomic_compare_exchange_strong(a, b, c) \ + __atomic_compare_exchange_n(&(a)->v, b, c, 0, __ATOMIC_SEQ_CST, \ + __ATOMIC_SEQ_CST) + +#elif HAVE_SYNC_BUILTINS + +#define atomic_load(p) \ + __sync_fetch_and_add(&(p)->v, 0) +#define atomic_store(p, val) \ + (__sync_synchronize(), (p)->v = (val), __sync_synchronize()) +#define atomic_fetch_add(a, b) \ + __sync_fetch_and_add(&(a)->v, b) +#define atomic_fetch_and(a, b) \ + __sync_fetch_and_and(&(a)->v, b) +#define atomic_fetch_or(a, b) \ + __sync_fetch_and_or(&(a)->v, b) +// Assumes __sync_val_compare_and_swap is "strong" (using the C11 meaning). +#define atomic_compare_exchange_strong(p, old, new) \ + ({ __typeof__((p)->v) val_ = __sync_val_compare_and_swap(&(p)->v, *(old), new); \ + bool ok_ = val_ == *(old); \ + if (!ok_) *(old) = val_; \ + ok_; }) + +#elif defined(__GNUC__) + +#include + +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_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; }) + +#else +# error "this should have been a configuration error, report a bug please" +#endif /* no atomics */ + +#endif /* else HAVE_STDATOMIC */ + +#endif diff --git a/osdep/atomics.h b/osdep/atomics.h deleted file mode 100644 index 1d5134f646..0000000000 --- a/osdep/atomics.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * This file is part of mpv. - * Copyright (c) 2013 Stefano Pigozzi - * - * mpv is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * mpv is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with mpv. If not, see . - */ - -#ifndef MP_ATOMICS_H -#define MP_ATOMICS_H - -#include -#include "config.h" - -#if HAVE_STDATOMIC -#include -#else - -// Emulate the parts of C11 stdatomic.h needed by mpv. -// Still relies on gcc/clang atomic builtins. - -typedef struct { volatile unsigned long v; } atomic_ulong; -typedef struct { volatile int v; } atomic_int; -typedef struct { volatile unsigned int v; } atomic_uint; -typedef struct { volatile _Bool v; } atomic_bool; -typedef struct { volatile long long v; } atomic_llong; -typedef struct { volatile uint_least32_t v; } atomic_uint_least32_t; -typedef struct { volatile unsigned long long v; } atomic_ullong; - -#define ATOMIC_VAR_INIT(x) \ - {.v = (x)} - -#define memory_order_relaxed 1 -#define memory_order_seq_cst 2 - -#define atomic_load_explicit(p, e) atomic_load(p) - -#if HAVE_ATOMIC_BUILTINS - -#define atomic_load(p) \ - __atomic_load_n(&(p)->v, __ATOMIC_SEQ_CST) -#define atomic_store(p, val) \ - __atomic_store_n(&(p)->v, val, __ATOMIC_SEQ_CST) -#define atomic_fetch_add(a, b) \ - __atomic_fetch_add(&(a)->v, b, __ATOMIC_SEQ_CST) -#define atomic_fetch_and(a, b) \ - __atomic_fetch_and(&(a)->v, b, __ATOMIC_SEQ_CST) -#define atomic_fetch_or(a, b) \ - __atomic_fetch_or(&(a)->v, b, __ATOMIC_SEQ_CST) -#define atomic_compare_exchange_strong(a, b, c) \ - __atomic_compare_exchange_n(&(a)->v, b, c, 0, __ATOMIC_SEQ_CST, \ - __ATOMIC_SEQ_CST) - -#elif HAVE_SYNC_BUILTINS - -#define atomic_load(p) \ - __sync_fetch_and_add(&(p)->v, 0) -#define atomic_store(p, val) \ - (__sync_synchronize(), (p)->v = (val), __sync_synchronize()) -#define atomic_fetch_add(a, b) \ - __sync_fetch_and_add(&(a)->v, b) -#define atomic_fetch_and(a, b) \ - __sync_fetch_and_and(&(a)->v, b) -#define atomic_fetch_or(a, b) \ - __sync_fetch_and_or(&(a)->v, b) -// Assumes __sync_val_compare_and_swap is "strong" (using the C11 meaning). -#define atomic_compare_exchange_strong(p, old, new) \ - ({ __typeof__((p)->v) val_ = __sync_val_compare_and_swap(&(p)->v, *(old), new); \ - bool ok_ = val_ == *(old); \ - if (!ok_) *(old) = val_; \ - ok_; }) - -#elif defined(__GNUC__) - -#include - -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_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; }) - -#else -# error "this should have been a configuration error, report a bug please" -#endif /* no atomics */ - -#endif /* else HAVE_STDATOMIC */ - -#endif diff --git a/osdep/subprocess-win.c b/osdep/subprocess-win.c index 614cae663f..3ac0c397aa 100644 --- a/osdep/subprocess-win.c +++ b/osdep/subprocess-win.c @@ -21,7 +21,7 @@ #include "osdep/subprocess.h" #include "osdep/io.h" -#include "osdep/atomics.h" +#include "osdep/atomic.h" #include "mpv_talloc.h" #include "common/common.h" diff --git a/stream/stream.c b/stream/stream.c index 6e45f0a549..69772f335a 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -26,7 +26,7 @@ #include #include -#include "osdep/atomics.h" +#include "osdep/atomic.h" #include "osdep/io.h" #include "mpv_talloc.h" diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index 7cb30cc49d..18e6860e7d 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -30,7 +30,7 @@ #import "video/out/cocoa/mpvadapter.h" #include "osdep/threads.h" -#include "osdep/atomics.h" +#include "osdep/atomic.h" #include "osdep/macosx_compat.h" #include "osdep/macosx_events_objc.h" diff --git a/video/out/w32_common.c b/video/out/w32_common.c index 46e9052e43..0dff2643b1 100644 --- a/video/out/w32_common.c +++ b/video/out/w32_common.c @@ -40,7 +40,7 @@ #include "osdep/io.h" #include "osdep/threads.h" #include "osdep/w32_keyboard.h" -#include "osdep/atomics.h" +#include "osdep/atomic.h" #include "misc/dispatch.h" #include "misc/rendezvous.h" #include "mpv_talloc.h" diff --git a/video/out/x11_common.c b/video/out/x11_common.c index aa2185315e..32f5c6c723 100644 --- a/video/out/x11_common.c +++ b/video/out/x11_common.c @@ -40,7 +40,6 @@ #include "vo.h" #include "win_state.h" -#include "osdep/atomics.h" #include "osdep/io.h" #include "osdep/timer.h" #include "osdep/subprocess.h" diff --git a/video/out/x11_common.h b/video/out/x11_common.h index 213d517205..de2a805efd 100644 --- a/video/out/x11_common.h +++ b/video/out/x11_common.h @@ -24,7 +24,7 @@ #include #include -#include "osdep/atomics.h" +#include "osdep/atomic.h" #include "osdep/semaphore.h" #include "common/common.h" -- cgit v1.2.3