From 37f409cb9aae06c99a6dff910b1b1d9278190ef1 Mon Sep 17 00:00:00 2001 From: Johns Date: Wed, 25 Jun 2014 15:17:00 +0200 Subject: [PATCH] Use GCC built-in functions for atomic operations. --- ChangeLog | 1 + audio.c | 2 +- codec.c | 2 +- iatomic.h | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ringbuffer.c | 5 ++- softhddev.c | 3 +- video.c | 3 +- 7 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 iatomic.h diff --git a/ChangeLog b/ChangeLog index 4ec785e..a611b32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ User johns Date: Config for automatic AES parameters. + Use GCC built-in functions for atomic operations. User master_red Date: Wed Jun 4 14:44:32 CEST 2014 diff --git a/audio.c b/audio.c index 8746bb5..6ca3df1 100644 --- a/audio.c +++ b/audio.c @@ -88,7 +88,7 @@ #endif #endif -#include // portable atomic_t +#include "iatomic.h" // portable atomic_t #include "ringbuffer.h" #include "misc.h" diff --git a/codec.c b/codec.c index b6f9fba..03ba028 100644 --- a/codec.c +++ b/codec.c @@ -58,7 +58,6 @@ #define _(str) gettext(str) ///< gettext shortcut #define _N(str) str ///< gettext_noop shortcut -#include #include #include // support old ffmpeg versions <1.0 @@ -88,6 +87,7 @@ #ifdef MAIN_H #include MAIN_H #endif +#include "iatomic.h" #include "misc.h" #include "video.h" #include "audio.h" 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 + +#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 + +/// @} diff --git a/ringbuffer.c b/ringbuffer.c index 9466852..c9497b1 100644 --- a/ringbuffer.c +++ b/ringbuffer.c @@ -1,7 +1,7 @@ /// /// @file ringbuffer.c @brief Ringbuffer module /// -/// Copyright (c) 2009, 2011 by Johns. All Rights Reserved. +/// Copyright (c) 2009, 2011, 2014 by Johns. All Rights Reserved. /// /// Contributor(s): /// @@ -30,8 +30,7 @@ #include #include -#include - +#include "iatomic.h" #include "ringbuffer.h" /// ring buffer structure diff --git a/softhddev.c b/softhddev.c index 2f873c0..1759109 100644 --- a/softhddev.c +++ b/softhddev.c @@ -63,6 +63,7 @@ #endif #include +#include "iatomic.h" // portable atomic_t #include "misc.h" #include "softhddev.h" @@ -1307,8 +1308,6 @@ void SetVolumeDevice(int volume) // Video ////////////////////////////////////////////////////////////////////////////// -#include // portable atomic_t - #define VIDEO_BUFFER_SIZE (512 * 1024) ///< video PES buffer default size #define VIDEO_PACKET_MAX 192 ///< max number of video packets diff --git a/video.c b/video.c index 01bde83..a5b3a5a 100644 --- a/video.c +++ b/video.c @@ -70,8 +70,6 @@ #define _(str) gettext(str) ///< gettext shortcut #define _N(str) str ///< gettext_noop shortcut -#include // portable atomic_t - #ifdef USE_VIDEO_THREAD #ifndef __USE_GNU #define __USE_GNU @@ -179,6 +177,7 @@ typedef enum #define FFMPEG_BUG1_WORKAROUND ///< get_format bug workaround #endif +#include "iatomic.h" // portable atomic_t #include "misc.h" #include "video.h" #include "audio.h"