diff options
author | Johns <johns98@gmx.net> | 2014-06-25 15:17:00 +0200 |
---|---|---|
committer | Johns <johns98@gmx.net> | 2014-06-25 15:17:00 +0200 |
commit | 37f409cb9aae06c99a6dff910b1b1d9278190ef1 (patch) | |
tree | b9cc5937e1ab239098e0cc9bc6f6f96f89565580 /iatomic.h | |
parent | 5207af6b2da0df19a58db4932811d38526fde51b (diff) | |
download | vdr-plugin-softhddevice-37f409cb9aae06c99a6dff910b1b1d9278190ef1.tar.gz vdr-plugin-softhddevice-37f409cb9aae06c99a6dff910b1b1d9278190ef1.tar.bz2 |
Use GCC built-in functions for atomic operations.
Diffstat (limited to 'iatomic.h')
-rw-r--r-- | iatomic.h | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/iatomic.h b/iatomic.h new file mode 100644 index 0000000..59e1684 --- /dev/null +++ b/iatomic.h @@ -0,0 +1,97 @@ +/// +/// @file iatomic.h @brief Misc function header file +/// +/// Copyright (c) 2014 by Johns. All Rights Reserved. +/// +/// Contributor(s): +/// +/// License: AGPLv3 +/// +/// This program is free software: you can redistribute it and/or modify +/// it under the terms of the GNU Affero General Public License as +/// published by the Free Software Foundation, either version 3 of the +/// License. +/// +/// This program 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 Affero General Public License for more details. +/// +/// $Id$ +////////////////////////////////////////////////////////////////////////////// + +/// @addtogroup iatomic +/// @{ + +#define GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + +// gcc before 4.7 didn't support atomic builtins, +// use alsa atomic functions. +#if GCC_VERSION < 40700 + +#include <alsa/iatomic.h> + +#else + +////////////////////////////////////////////////////////////////////////////// +// Defines +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +// Declares +////////////////////////////////////////////////////////////////////////////// + +/// +/// atomic type, 24 bit useable, +/// +typedef volatile int atomic_t; + +////////////////////////////////////////////////////////////////////////////// +// Prototypes +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +// Inlines +////////////////////////////////////////////////////////////////////////////// + +/// +/// Set atomic value. +/// +#define atomic_set(ptr, val) \ + __atomic_store_n(ptr, val, __ATOMIC_SEQ_CST) + +/// +/// Read atomic value. +/// +#define atomic_read(ptr) \ + __atomic_load_n(ptr, __ATOMIC_SEQ_CST) + +/// +/// Increment atomic value. +/// +#define atomic_inc(ptr) \ + __atomic_add_fetch(ptr, 1, __ATOMIC_SEQ_CST) + +/// +/// Decrement atomic value. +/// +#define atomic_dec(ptr) \ + __atomic_sub_fetch(ptr, 1, __ATOMIC_SEQ_CST) + +/// +/// Add to atomic value. +/// +#define atomic_add(val, ptr) \ + __atomic_add_fetch(ptr, val, __ATOMIC_SEQ_CST) + +/// +/// Subtract from atomic value. +/// +#define atomic_sub(val, ptr) \ + __atomic_sub_fetch(ptr, val, __ATOMIC_SEQ_CST) + +#endif + +/// @} |