summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohns <johns98@gmx.net>2014-06-25 15:17:00 +0200
committerJohns <johns98@gmx.net>2014-06-25 15:17:00 +0200
commit37f409cb9aae06c99a6dff910b1b1d9278190ef1 (patch)
treeb9cc5937e1ab239098e0cc9bc6f6f96f89565580
parent5207af6b2da0df19a58db4932811d38526fde51b (diff)
downloadvdr-plugin-softhddevice-37f409cb9aae06c99a6dff910b1b1d9278190ef1.tar.gz
vdr-plugin-softhddevice-37f409cb9aae06c99a6dff910b1b1d9278190ef1.tar.bz2
Use GCC built-in functions for atomic operations.
-rw-r--r--ChangeLog1
-rw-r--r--audio.c2
-rw-r--r--codec.c2
-rw-r--r--iatomic.h97
-rw-r--r--ringbuffer.c5
-rw-r--r--softhddev.c3
-rw-r--r--video.c3
7 files changed, 104 insertions, 9 deletions
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 <alsa/iatomic.h> // 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 <alsa/iatomic.h>
#include <libavcodec/avcodec.h>
#include <libavutil/mem.h>
// 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 <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
+
+/// @}
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 <stdlib.h>
#include <string.h>
-#include <alsa/iatomic.h>
-
+#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 <pthread.h>
+#include "iatomic.h" // portable atomic_t
#include "misc.h"
#include "softhddev.h"
@@ -1307,8 +1308,6 @@ void SetVolumeDevice(int volume)
// Video
//////////////////////////////////////////////////////////////////////////////
-#include <alsa/iatomic.h> // 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 <alsa/iatomic.h> // 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"