2018-08-19 11:45:46 +02:00
|
|
|
///
|
2019-10-26 18:42:19 +02:00
|
|
|
/// @file iatomic.h @brief Misc function header file
|
2018-08-19 11:45:46 +02:00
|
|
|
///
|
2019-10-26 18:42:19 +02:00
|
|
|
/// Copyright (c) 2014 by Johns. All Rights Reserved.
|
2018-08-19 11:45:46 +02:00
|
|
|
///
|
2019-10-26 18:42:19 +02:00
|
|
|
/// Contributor(s):
|
2018-08-19 11:45:46 +02:00
|
|
|
///
|
2019-10-26 18:42:19 +02:00
|
|
|
/// License: AGPLv3
|
2018-08-19 11:45:46 +02:00
|
|
|
///
|
2019-10-26 18:42:19 +02:00
|
|
|
/// 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.
|
2018-08-19 11:45:46 +02:00
|
|
|
///
|
2019-10-26 18:42:19 +02:00
|
|
|
/// 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.
|
2018-08-19 11:45:46 +02:00
|
|
|
///
|
2019-10-26 18:42:19 +02:00
|
|
|
/// $Id: 59e1684aaa6678ecdebb6ce0df6ce5b5f461dd6e $
|
2018-08-19 11:45:46 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/// @addtogroup iatomic
|
|
|
|
/// @{
|
|
|
|
|
2021-12-27 20:02:45 +01:00
|
|
|
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
|
2018-08-19 11:45:46 +02:00
|
|
|
|
2019-10-26 18:42:19 +02:00
|
|
|
// gcc before 4.7 didn't support atomic builtins,
|
|
|
|
// use alsa atomic functions.
|
2018-08-19 11:45:46 +02:00
|
|
|
#if GCC_VERSION < 40700
|
|
|
|
|
|
|
|
#include <alsa/iatomic.h>
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2019-10-26 18:42:19 +02:00
|
|
|
// Defines
|
2018-08-19 11:45:46 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2019-10-26 18:42:19 +02:00
|
|
|
// Declares
|
2018-08-19 11:45:46 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
///
|
2019-10-26 18:42:19 +02:00
|
|
|
/// atomic type, 24 bit useable,
|
2018-08-19 11:45:46 +02:00
|
|
|
///
|
|
|
|
typedef volatile int atomic_t;
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2019-10-26 18:42:19 +02:00
|
|
|
// Prototypes
|
2018-08-19 11:45:46 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2019-10-26 18:42:19 +02:00
|
|
|
// Inlines
|
2018-08-19 11:45:46 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
///
|
2019-10-26 18:42:19 +02:00
|
|
|
/// Set atomic value.
|
2018-08-19 11:45:46 +02:00
|
|
|
///
|
2021-12-27 20:02:45 +01:00
|
|
|
#define atomic_set(ptr, val) __atomic_store_n(ptr, val, __ATOMIC_SEQ_CST)
|
2018-08-19 11:45:46 +02:00
|
|
|
|
|
|
|
///
|
2019-10-26 18:42:19 +02:00
|
|
|
/// Read atomic value.
|
2018-08-19 11:45:46 +02:00
|
|
|
///
|
2021-12-27 20:02:45 +01:00
|
|
|
#define atomic_read(ptr) __atomic_load_n(ptr, __ATOMIC_SEQ_CST)
|
2018-08-19 11:45:46 +02:00
|
|
|
|
|
|
|
///
|
2019-10-26 18:42:19 +02:00
|
|
|
/// Increment atomic value.
|
2018-08-19 11:45:46 +02:00
|
|
|
///
|
2021-12-27 20:02:45 +01:00
|
|
|
#define atomic_inc(ptr) __atomic_add_fetch(ptr, 1, __ATOMIC_SEQ_CST)
|
2018-08-19 11:45:46 +02:00
|
|
|
|
|
|
|
///
|
2019-10-26 18:42:19 +02:00
|
|
|
/// Decrement atomic value.
|
2018-08-19 11:45:46 +02:00
|
|
|
///
|
2021-12-27 20:02:45 +01:00
|
|
|
#define atomic_dec(ptr) __atomic_sub_fetch(ptr, 1, __ATOMIC_SEQ_CST)
|
2018-08-19 11:45:46 +02:00
|
|
|
|
|
|
|
///
|
2019-10-26 18:42:19 +02:00
|
|
|
/// Add to atomic value.
|
2018-08-19 11:45:46 +02:00
|
|
|
///
|
2021-12-27 20:02:45 +01:00
|
|
|
#define atomic_add(val, ptr) __atomic_add_fetch(ptr, val, __ATOMIC_SEQ_CST)
|
2018-08-19 11:45:46 +02:00
|
|
|
|
|
|
|
///
|
2019-10-26 18:42:19 +02:00
|
|
|
/// Subtract from atomic value.
|
2018-08-19 11:45:46 +02:00
|
|
|
///
|
2021-12-27 20:02:45 +01:00
|
|
|
#define atomic_sub(val, ptr) __atomic_sub_fetch(ptr, val, __ATOMIC_SEQ_CST)
|
2018-08-19 11:45:46 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/// @}
|