Use GCC built-in functions for atomic operations.

This commit is contained in:
Johns 2014-06-25 15:17:00 +02:00
parent 5207af6b2d
commit 37f409cb9a
7 changed files with 104 additions and 9 deletions

View File

@ -2,6 +2,7 @@ User johns
Date: Date:
Config for automatic AES parameters. Config for automatic AES parameters.
Use GCC built-in functions for atomic operations.
User master_red User master_red
Date: Wed Jun 4 14:44:32 CEST 2014 Date: Wed Jun 4 14:44:32 CEST 2014

View File

@ -88,7 +88,7 @@
#endif #endif
#endif #endif
#include <alsa/iatomic.h> // portable atomic_t #include "iatomic.h" // portable atomic_t
#include "ringbuffer.h" #include "ringbuffer.h"
#include "misc.h" #include "misc.h"

View File

@ -58,7 +58,6 @@
#define _(str) gettext(str) ///< gettext shortcut #define _(str) gettext(str) ///< gettext shortcut
#define _N(str) str ///< gettext_noop shortcut #define _N(str) str ///< gettext_noop shortcut
#include <alsa/iatomic.h>
#include <libavcodec/avcodec.h> #include <libavcodec/avcodec.h>
#include <libavutil/mem.h> #include <libavutil/mem.h>
// support old ffmpeg versions <1.0 // support old ffmpeg versions <1.0
@ -88,6 +87,7 @@
#ifdef MAIN_H #ifdef MAIN_H
#include MAIN_H #include MAIN_H
#endif #endif
#include "iatomic.h"
#include "misc.h" #include "misc.h"
#include "video.h" #include "video.h"
#include "audio.h" #include "audio.h"

97
iatomic.h Normal file
View File

@ -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
/// @}

View File

@ -1,7 +1,7 @@
/// ///
/// @file ringbuffer.c @brief Ringbuffer module /// @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): /// Contributor(s):
/// ///
@ -30,8 +30,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <alsa/iatomic.h> #include "iatomic.h"
#include "ringbuffer.h" #include "ringbuffer.h"
/// ring buffer structure /// ring buffer structure

View File

@ -63,6 +63,7 @@
#endif #endif
#include <pthread.h> #include <pthread.h>
#include "iatomic.h" // portable atomic_t
#include "misc.h" #include "misc.h"
#include "softhddev.h" #include "softhddev.h"
@ -1307,8 +1308,6 @@ void SetVolumeDevice(int volume)
// Video // Video
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
#include <alsa/iatomic.h> // portable atomic_t
#define VIDEO_BUFFER_SIZE (512 * 1024) ///< video PES buffer default size #define VIDEO_BUFFER_SIZE (512 * 1024) ///< video PES buffer default size
#define VIDEO_PACKET_MAX 192 ///< max number of video packets #define VIDEO_PACKET_MAX 192 ///< max number of video packets

View File

@ -70,8 +70,6 @@
#define _(str) gettext(str) ///< gettext shortcut #define _(str) gettext(str) ///< gettext shortcut
#define _N(str) str ///< gettext_noop shortcut #define _N(str) str ///< gettext_noop shortcut
#include <alsa/iatomic.h> // portable atomic_t
#ifdef USE_VIDEO_THREAD #ifdef USE_VIDEO_THREAD
#ifndef __USE_GNU #ifndef __USE_GNU
#define __USE_GNU #define __USE_GNU
@ -179,6 +177,7 @@ typedef enum
#define FFMPEG_BUG1_WORKAROUND ///< get_format bug workaround #define FFMPEG_BUG1_WORKAROUND ///< get_format bug workaround
#endif #endif
#include "iatomic.h" // portable atomic_t
#include "misc.h" #include "misc.h"
#include "video.h" #include "video.h"
#include "audio.h" #include "audio.h"