Replace OS_INLINE by inline
Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
parent
c86bda7aa4
commit
62b9b8d9dc
17 changed files with 488 additions and 766 deletions
|
@ -84,9 +84,7 @@ PREPEND(hdrs_private_ddsi "${CMAKE_CURRENT_LIST_DIR}/include/ddsi"
|
|||
q_addrset.h
|
||||
q_align.h
|
||||
q_bitset.h
|
||||
q_bitset_template.h
|
||||
q_bswap.h
|
||||
q_bswap_template.h
|
||||
q_config.h
|
||||
q_ddsi_discovery.h
|
||||
q_debmon.h
|
||||
|
@ -116,7 +114,6 @@ PREPEND(hdrs_private_ddsi "${CMAKE_CURRENT_LIST_DIR}/include/ddsi"
|
|||
q_sockwaitset.h
|
||||
q_static_assert.h
|
||||
q_thread.h
|
||||
q_thread_template.h
|
||||
q_time.h
|
||||
q_transmit.h
|
||||
q_inverse_uint32_set.h
|
||||
|
|
|
@ -15,22 +15,40 @@
|
|||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "os/os_inline.h"
|
||||
#include "ddsi/q_unused.h"
|
||||
|
||||
#if OS_HAVE_INLINE && !defined SUPPRESS_BITSET_INLINES
|
||||
#include "q_bitset_template.h"
|
||||
#else
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
int nn_bitset_isset (unsigned numbits, const unsigned *bits, unsigned idx);
|
||||
void nn_bitset_set (unsigned numbits, unsigned *bits, unsigned idx);
|
||||
void nn_bitset_clear (unsigned numbits, unsigned *bits, unsigned idx);
|
||||
void nn_bitset_zero (unsigned numbits, unsigned *bits);
|
||||
void nn_bitset_one (unsigned numbits, unsigned *bits);
|
||||
#if defined (__cplusplus)
|
||||
inline int nn_bitset_isset (unsigned numbits, const unsigned *bits, unsigned idx)
|
||||
{
|
||||
return idx < numbits && (bits[idx/32] & (1u << (31 - (idx%32))));
|
||||
}
|
||||
|
||||
inline void nn_bitset_set (UNUSED_ARG_NDEBUG (unsigned numbits), unsigned *bits, unsigned idx)
|
||||
{
|
||||
assert (idx < numbits);
|
||||
bits[idx/32] |= 1u << (31 - (idx%32));
|
||||
}
|
||||
|
||||
inline void nn_bitset_clear (UNUSED_ARG_NDEBUG (unsigned numbits), unsigned *bits, unsigned idx)
|
||||
{
|
||||
assert (idx < numbits);
|
||||
bits[idx/32] &= ~(1u << (31 - (idx%32)));
|
||||
}
|
||||
|
||||
inline void nn_bitset_zero (unsigned numbits, unsigned *bits)
|
||||
{
|
||||
memset (bits, 0, 4 * ((numbits + 31) / 32));
|
||||
}
|
||||
|
||||
inline void nn_bitset_one (unsigned numbits, unsigned *bits)
|
||||
{
|
||||
memset (bits, 0xff, 4 * ((numbits + 31) / 32));
|
||||
|
||||
/* clear bits "accidentally" set */
|
||||
{
|
||||
const unsigned k = numbits / 32;
|
||||
const unsigned n = numbits % 32;
|
||||
bits[k] &= ~(~0u >> n);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* NN_BITSET_H */
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
/* -*- c -*- */
|
||||
|
||||
#include "ddsi/q_unused.h"
|
||||
|
||||
#if defined SUPPRESS_BITSET_INLINES && defined OS_INLINE
|
||||
#undef OS_INLINE
|
||||
#define OS_INLINE
|
||||
#endif
|
||||
|
||||
OS_INLINE int nn_bitset_isset (unsigned numbits, const unsigned *bits, unsigned idx)
|
||||
{
|
||||
return idx < numbits && (bits[idx/32] & (1u << (31 - (idx%32))));
|
||||
}
|
||||
|
||||
OS_INLINE void nn_bitset_set (UNUSED_ARG_NDEBUG (unsigned numbits), unsigned *bits, unsigned idx)
|
||||
{
|
||||
assert (idx < numbits);
|
||||
bits[idx/32] |= 1u << (31 - (idx%32));
|
||||
}
|
||||
|
||||
OS_INLINE void nn_bitset_clear (UNUSED_ARG_NDEBUG (unsigned numbits), unsigned *bits, unsigned idx)
|
||||
{
|
||||
assert (idx < numbits);
|
||||
bits[idx/32] &= ~(1u << (31 - (idx%32)));
|
||||
}
|
||||
|
||||
OS_INLINE void nn_bitset_zero (unsigned numbits, unsigned *bits)
|
||||
{
|
||||
memset (bits, 0, 4 * ((numbits + 31) / 32));
|
||||
}
|
||||
|
||||
OS_INLINE void nn_bitset_one (unsigned numbits, unsigned *bits)
|
||||
{
|
||||
memset (bits, 0xff, 4 * ((numbits + 31) / 32));
|
||||
|
||||
/* clear bits "accidentally" set */
|
||||
{
|
||||
const unsigned k = numbits / 32;
|
||||
const unsigned n = numbits % 32;
|
||||
bits[k] &= ~(~0u >> n);
|
||||
}
|
||||
}
|
|
@ -21,20 +21,28 @@
|
|||
#define bswap4(x) ((int32_t) bswap4u ((uint32_t) (x)))
|
||||
#define bswap8(x) ((int64_t) bswap8u ((uint64_t) (x)))
|
||||
|
||||
#if NN_HAVE_C99_INLINE && !defined SUPPRESS_BSWAP_INLINES
|
||||
#include "q_bswap_template.h"
|
||||
#else
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
uint16_t bswap2u (uint16_t x);
|
||||
uint32_t bswap4u (uint32_t x);
|
||||
uint64_t bswap8u (uint64_t x);
|
||||
void bswapSN (nn_sequence_number_t *sn);
|
||||
#if defined (__cplusplus)
|
||||
inline uint16_t bswap2u (uint16_t x)
|
||||
{
|
||||
return (unsigned short) ((x >> 8) | (x << 8));
|
||||
}
|
||||
|
||||
inline uint32_t bswap4u (uint32_t x)
|
||||
{
|
||||
return (x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24);
|
||||
}
|
||||
|
||||
inline uint64_t bswap8u (uint64_t x)
|
||||
{
|
||||
const uint32_t newhi = bswap4u ((uint32_t) x);
|
||||
const uint32_t newlo = bswap4u ((uint32_t) (x >> 32));
|
||||
return ((uint64_t) newhi << 32) | (uint64_t) newlo;
|
||||
}
|
||||
|
||||
inline void bswapSN (nn_sequence_number_t *sn)
|
||||
{
|
||||
sn->high = bswap4 (sn->high);
|
||||
sn->low = bswap4u (sn->low);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if OS_ENDIANNESS == OS_LITTLE_ENDIAN
|
||||
#define toBE2(x) bswap2 (x)
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
/* -*- c -*- */
|
||||
|
||||
#if defined SUPPRESS_BSWAP_INLINES && defined OS_INLINE
|
||||
#undef OS_INLINE
|
||||
#define OS_INLINE
|
||||
#endif
|
||||
|
||||
OS_INLINE uint16_t bswap2u (uint16_t x)
|
||||
{
|
||||
return (unsigned short) ((x >> 8) | (x << 8));
|
||||
}
|
||||
|
||||
OS_INLINE uint32_t bswap4u (uint32_t x)
|
||||
{
|
||||
return (x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24);
|
||||
}
|
||||
|
||||
OS_INLINE uint64_t bswap8u (uint64_t x)
|
||||
{
|
||||
const uint32_t newhi = bswap4u ((uint32_t) x);
|
||||
const uint32_t newlo = bswap4u ((uint32_t) (x >> 32));
|
||||
return ((uint64_t) newhi << 32) | (uint64_t) newlo;
|
||||
}
|
||||
|
||||
OS_INLINE void bswapSN (nn_sequence_number_t *sn)
|
||||
{
|
||||
sn->high = bswap4 (sn->high);
|
||||
sn->low = bswap4u (sn->low);
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
#define Q_THREAD_H
|
||||
|
||||
#include "os/os.h"
|
||||
#include "ddsi/q_static_assert.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
|
@ -100,27 +101,88 @@ struct thread_state1 * init_thread_state (_In_z_ const char *tname);
|
|||
void reset_thread_state (_Inout_opt_ struct thread_state1 *ts1);
|
||||
int thread_exists (_In_z_ const char *name);
|
||||
|
||||
inline int vtime_awake_p (_In_ vtime_t vtime)
|
||||
{
|
||||
return (vtime % 2) == 0;
|
||||
}
|
||||
|
||||
inline int vtime_asleep_p (_In_ vtime_t vtime)
|
||||
{
|
||||
return (vtime % 2) == 1;
|
||||
}
|
||||
|
||||
inline int vtime_gt (_In_ vtime_t vtime1, _In_ vtime_t vtime0)
|
||||
{
|
||||
Q_STATIC_ASSERT_CODE (sizeof (vtime_t) == sizeof (svtime_t));
|
||||
return (svtime_t) (vtime1 - vtime0) > 0;
|
||||
}
|
||||
|
||||
inline void thread_state_asleep (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t vt = ts1->vtime;
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if (vtime_awake_p (vt))
|
||||
{
|
||||
os_atomic_fence_rel ();
|
||||
ts1->vtime = vt + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
os_atomic_fence_rel ();
|
||||
ts1->vtime = vt + 2;
|
||||
os_atomic_fence_acq ();
|
||||
}
|
||||
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 2;
|
||||
} else {
|
||||
ts1->watchdog = wd + 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline void thread_state_awake (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t vt = ts1->vtime;
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if (vtime_asleep_p (vt))
|
||||
ts1->vtime = vt + 1;
|
||||
else
|
||||
{
|
||||
os_atomic_fence_rel ();
|
||||
ts1->vtime = vt + 2;
|
||||
}
|
||||
os_atomic_fence_acq ();
|
||||
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 1;
|
||||
} else {
|
||||
ts1->watchdog = wd + 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline void thread_state_blocked (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 2;
|
||||
} else {
|
||||
ts1->watchdog = wd + 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline void thread_state_unblocked (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 1;
|
||||
} else {
|
||||
ts1->watchdog = wd + 2;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NN_HAVE_C99_INLINE && !defined SUPPRESS_THREAD_INLINES
|
||||
#include "q_thread_template.h"
|
||||
#else
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
int vtime_awake_p (_In_ vtime_t vtime);
|
||||
int vtime_asleep_p (_In_ vtime_t vtime);
|
||||
int vtime_gt (_In_ vtime_t vtime1, _In_ vtime_t vtime0);
|
||||
|
||||
void thread_state_asleep (_Inout_ struct thread_state1 *ts1);
|
||||
void thread_state_awake (_Inout_ struct thread_state1 *ts1);
|
||||
void thread_state_blocked (_Inout_ struct thread_state1 *ts1);
|
||||
void thread_state_unblocked (_Inout_ struct thread_state1 *ts1);
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* Q_THREAD_H */
|
||||
|
|
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
/* -*- c -*- */
|
||||
|
||||
#include "os/os_atomics.h"
|
||||
#include "ddsi/q_static_assert.h"
|
||||
|
||||
#if defined SUPPRESS_THREAD_INLINES && defined OS_INLINE
|
||||
#undef OS_INLINE
|
||||
#define OS_INLINE
|
||||
#endif
|
||||
|
||||
OS_INLINE int vtime_awake_p (_In_ vtime_t vtime)
|
||||
{
|
||||
return (vtime % 2) == 0;
|
||||
}
|
||||
|
||||
OS_INLINE int vtime_asleep_p (_In_ vtime_t vtime)
|
||||
{
|
||||
return (vtime % 2) == 1;
|
||||
}
|
||||
|
||||
OS_INLINE int vtime_gt (_In_ vtime_t vtime1, _In_ vtime_t vtime0)
|
||||
{
|
||||
Q_STATIC_ASSERT_CODE (sizeof (vtime_t) == sizeof (svtime_t));
|
||||
return (svtime_t) (vtime1 - vtime0) > 0;
|
||||
}
|
||||
|
||||
OS_INLINE void thread_state_asleep (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t vt = ts1->vtime;
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if (vtime_awake_p (vt))
|
||||
{
|
||||
os_atomic_fence_rel ();
|
||||
ts1->vtime = vt + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
os_atomic_fence_rel ();
|
||||
ts1->vtime = vt + 2;
|
||||
os_atomic_fence_acq ();
|
||||
}
|
||||
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 2;
|
||||
} else {
|
||||
ts1->watchdog = wd + 1;
|
||||
}
|
||||
}
|
||||
|
||||
OS_INLINE void thread_state_awake (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t vt = ts1->vtime;
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if (vtime_asleep_p (vt))
|
||||
ts1->vtime = vt + 1;
|
||||
else
|
||||
{
|
||||
os_atomic_fence_rel ();
|
||||
ts1->vtime = vt + 2;
|
||||
}
|
||||
os_atomic_fence_acq ();
|
||||
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 1;
|
||||
} else {
|
||||
ts1->watchdog = wd + 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
OS_INLINE void thread_state_blocked (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 2;
|
||||
} else {
|
||||
ts1->watchdog = wd + 1;
|
||||
}
|
||||
}
|
||||
|
||||
OS_INLINE void thread_state_unblocked (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 1;
|
||||
} else {
|
||||
ts1->watchdog = wd + 2;
|
||||
}
|
||||
}
|
|
@ -9,8 +9,11 @@
|
|||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#define SUPPRESS_BITSET_INLINES
|
||||
|
||||
#include "ddsi/q_bitset.h"
|
||||
#include "ddsi/q_bitset_template.h"
|
||||
|
||||
extern inline int nn_bitset_isset (unsigned numbits, const unsigned *bits, unsigned idx);
|
||||
extern inline void nn_bitset_set (unsigned numbits, unsigned *bits, unsigned idx);
|
||||
extern inline void nn_bitset_clear (unsigned numbits, unsigned *bits, unsigned idx);
|
||||
extern inline void nn_bitset_zero (unsigned numbits, unsigned *bits);
|
||||
extern inline void nn_bitset_one (unsigned numbits, unsigned *bits);
|
||||
|
||||
|
|
|
@ -9,7 +9,10 @@
|
|||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#define SUPPRESS_BSWAP_INLINES
|
||||
|
||||
#include "ddsi/q_bswap.h"
|
||||
#include "ddsi/q_bswap_template.h"
|
||||
|
||||
extern inline uint16_t bswap2u (uint16_t x);
|
||||
extern inline uint32_t bswap4u (uint32_t x);
|
||||
extern inline uint64_t bswap8u (uint64_t x);
|
||||
extern inline void bswapSN (nn_sequence_number_t *sn);
|
||||
|
||||
|
|
|
@ -9,7 +9,14 @@
|
|||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#define SUPPRESS_THREAD_INLINES
|
||||
|
||||
#include "ddsi/q_thread.h"
|
||||
#include "ddsi/q_thread_template.h"
|
||||
|
||||
extern inline int vtime_awake_p (_In_ vtime_t vtime);
|
||||
extern inline int vtime_asleep_p (_In_ vtime_t vtime);
|
||||
extern inline int vtime_gt (_In_ vtime_t vtime1, _In_ vtime_t vtime0);
|
||||
|
||||
extern inline void thread_state_asleep (_Inout_ struct thread_state1 *ts1);
|
||||
extern inline void thread_state_awake (_Inout_ struct thread_state1 *ts1);
|
||||
extern inline void thread_state_blocked (_Inout_ struct thread_state1 *ts1);
|
||||
extern inline void thread_state_unblocked (_Inout_ struct thread_state1 *ts1);
|
||||
|
||||
|
|
|
@ -21,24 +21,13 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Note: os_atomics_inlines.c overrules OS_HAVE_INLINE, OS_INLINE and
|
||||
OS_ATOMICS_OMIT_FUNCTIONS */
|
||||
|
||||
#if ! OS_HAVE_INLINE && ! defined OS_ATOMICS_OMIT_FUNCTIONS
|
||||
#define OS_ATOMICS_OMIT_FUNCTIONS 1
|
||||
#endif
|
||||
|
||||
#if ! OS_ATOMIC_SUPPORT && (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40100
|
||||
#include "os/os_atomics_gcc.h"
|
||||
#endif
|
||||
|
||||
#if ! OS_ATOMIC_SUPPORT && defined _WIN32
|
||||
/* Windows.h causes HUGE problems when included too early, primarily
|
||||
because you can't include only a subset and later include the rest
|
||||
*/
|
||||
#undef OS_HAVE_INLINE
|
||||
#undef OS_INLINE
|
||||
#define OS_INLINE
|
||||
/* windows.h causes HUGE problems when included too early, primarily
|
||||
because you can't include only a subset and later include the rest */
|
||||
#include "os_atomics_win32.h"
|
||||
#endif
|
||||
|
||||
|
@ -50,120 +39,6 @@ extern "C" {
|
|||
#error "No support for atomic operations on this platform"
|
||||
#endif
|
||||
|
||||
#if ! OS_HAVE_INLINE
|
||||
|
||||
/* LD, ST */
|
||||
OSAPI_EXPORT uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x);
|
||||
#endif
|
||||
OSAPI_EXPORT uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x);
|
||||
OSAPI_EXPORT void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x);
|
||||
OSAPI_EXPORT void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
OSAPI_EXPORT void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OSAPI_EXPORT void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v);
|
||||
/* INC */
|
||||
OSAPI_EXPORT void os_atomic_inc32 (volatile os_atomic_uint32_t *x);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT void os_atomic_inc64 (volatile os_atomic_uint64_t *x);
|
||||
#endif
|
||||
OSAPI_EXPORT void os_atomic_incptr (volatile os_atomic_uintptr_t *x);
|
||||
OSAPI_EXPORT uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x);
|
||||
#endif
|
||||
OSAPI_EXPORT uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x);
|
||||
/* DEC */
|
||||
OSAPI_EXPORT void os_atomic_dec32 (volatile os_atomic_uint32_t *x);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT void os_atomic_dec64 (volatile os_atomic_uint64_t *x);
|
||||
#endif
|
||||
OSAPI_EXPORT void os_atomic_decptr (volatile os_atomic_uintptr_t *x);
|
||||
OSAPI_EXPORT uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x);
|
||||
#endif
|
||||
OSAPI_EXPORT uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x);
|
||||
OSAPI_EXPORT uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x);
|
||||
#endif
|
||||
OSAPI_EXPORT uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x);
|
||||
/* ADD */
|
||||
OSAPI_EXPORT void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
OSAPI_EXPORT void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OSAPI_EXPORT void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v);
|
||||
OSAPI_EXPORT uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
OSAPI_EXPORT uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OSAPI_EXPORT void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v);
|
||||
/* SUB */
|
||||
OSAPI_EXPORT void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
OSAPI_EXPORT void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OSAPI_EXPORT void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v);
|
||||
OSAPI_EXPORT uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
OSAPI_EXPORT uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OSAPI_EXPORT void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v);
|
||||
/* AND */
|
||||
OSAPI_EXPORT void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
OSAPI_EXPORT void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OSAPI_EXPORT uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
OSAPI_EXPORT uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OSAPI_EXPORT uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
OSAPI_EXPORT uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
/* OR */
|
||||
OSAPI_EXPORT void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
OSAPI_EXPORT void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OSAPI_EXPORT uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
OSAPI_EXPORT uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OSAPI_EXPORT uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
OSAPI_EXPORT uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
/* CAS */
|
||||
OSAPI_EXPORT int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OSAPI_EXPORT int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des);
|
||||
#endif
|
||||
OSAPI_EXPORT int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des);
|
||||
OSAPI_EXPORT int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des);
|
||||
#if OS_ATOMIC_LIFO_SUPPORT
|
||||
OSAPI_EXPORT int os_atomic_casvoidp2 (volatile os_atomic_uintptr2_t *x, uintptr_t a0, uintptr_t b0, uintptr_t a1, uintptr_t b1);
|
||||
#endif
|
||||
/* FENCES */
|
||||
OSAPI_EXPORT void os_atomic_fence (void);
|
||||
OSAPI_EXPORT void os_atomic_fence_acq (void);
|
||||
OSAPI_EXPORT void os_atomic_fence_rel (void);
|
||||
/* LIFO */
|
||||
#if OS_ATOMIC_LIFO_SUPPORT
|
||||
typedef struct os_atomic_lifo {
|
||||
|
@ -174,9 +49,7 @@ OSAPI_EXPORT void os_atomic_lifo_init (os_atomic_lifo_t *head);
|
|||
OSAPI_EXPORT void os_atomic_lifo_push (os_atomic_lifo_t *head, void *elem, size_t linkoff);
|
||||
OSAPI_EXPORT void *os_atomic_lifo_pop (os_atomic_lifo_t *head, size_t linkoff);
|
||||
OSAPI_EXPORT void os_atomic_lifo_pushmany (os_atomic_lifo_t *head, void *first, void *last, size_t linkoff);
|
||||
#endif /* OS_ATOMIC_LIFO_SUPPORT */
|
||||
|
||||
#endif /* OS_HAVE_INLINE */
|
||||
#endif
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
|
|
|
@ -37,311 +37,235 @@ typedef union { uint64_t x; struct { uintptr_t a, b; } s; } os_atomic_uintptr2_t
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#if ! OS_ATOMICS_OMIT_FUNCTIONS
|
||||
|
||||
/* Eliminate C warnings */
|
||||
|
||||
#if ! defined (__cplusplus)
|
||||
OS_INLINE uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x);
|
||||
OS_INLINE uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x);
|
||||
OS_INLINE void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x);
|
||||
OS_INLINE void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
OS_INLINE void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OS_INLINE void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v);
|
||||
OS_INLINE void os_atomic_inc32 (volatile os_atomic_uint32_t *x);
|
||||
OS_INLINE void os_atomic_incptr (volatile os_atomic_uintptr_t *x);
|
||||
OS_INLINE uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x);
|
||||
OS_INLINE uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x);
|
||||
OS_INLINE void os_atomic_dec32 (volatile os_atomic_uint32_t *x);
|
||||
OS_INLINE void os_atomic_decptr (volatile os_atomic_uintptr_t *x);
|
||||
OS_INLINE uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x);
|
||||
OS_INLINE uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x);
|
||||
OS_INLINE uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x);
|
||||
OS_INLINE uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x);
|
||||
OS_INLINE void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
OS_INLINE void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OS_INLINE void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v);
|
||||
OS_INLINE uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
OS_INLINE uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OS_INLINE void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v);
|
||||
OS_INLINE void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
OS_INLINE void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OS_INLINE void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v);
|
||||
OS_INLINE uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
OS_INLINE uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OS_INLINE void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v);
|
||||
OS_INLINE void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
OS_INLINE void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OS_INLINE uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
OS_INLINE uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OS_INLINE uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
OS_INLINE uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OS_INLINE void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
OS_INLINE void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OS_INLINE uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
OS_INLINE uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OS_INLINE uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
OS_INLINE uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
OS_INLINE int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des);
|
||||
OS_INLINE int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des);
|
||||
OS_INLINE int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des);
|
||||
#if OS_ATOMIC_LIFO_SUPPORT
|
||||
OS_INLINE int os_atomic_casvoidp2 (volatile os_atomic_uintptr2_t *x, uintptr_t a0, uintptr_t b0, uintptr_t a1, uintptr_t b1);
|
||||
#endif
|
||||
OS_INLINE void os_atomic_fence (void);
|
||||
OS_INLINE void os_atomic_fence_acq (void);
|
||||
OS_INLINE void os_atomic_fence_rel (void);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x);
|
||||
OS_INLINE void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
OS_INLINE void os_atomic_inc64 (volatile os_atomic_uint64_t *x);
|
||||
OS_INLINE uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x);
|
||||
OS_INLINE void os_atomic_dec64 (volatile os_atomic_uint64_t *x);
|
||||
OS_INLINE uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x);
|
||||
OS_INLINE uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x);
|
||||
OS_INLINE void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
OS_INLINE uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
OS_INLINE void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
OS_INLINE uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
OS_INLINE void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
OS_INLINE uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
OS_INLINE uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
OS_INLINE void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
OS_INLINE uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
OS_INLINE uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
OS_INLINE int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* LD, ST */
|
||||
|
||||
OS_INLINE uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x) { return x->v; }
|
||||
inline uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x) { return x->v; }
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x) { return x->v; }
|
||||
inline uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x) { return x->v; }
|
||||
#endif
|
||||
OS_INLINE uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x) { return x->v; }
|
||||
OS_INLINE void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x) { return (void *) os_atomic_ldptr (x); }
|
||||
inline uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x) { return x->v; }
|
||||
inline void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x) { return (void *) os_atomic_ldptr (x); }
|
||||
|
||||
OS_INLINE void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v) { x->v = v; }
|
||||
inline void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v) { x->v = v; }
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v) { x->v = v; }
|
||||
inline void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v) { x->v = v; }
|
||||
#endif
|
||||
OS_INLINE void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
|
||||
OS_INLINE void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v) { os_atomic_stptr (x, (uintptr_t) v); }
|
||||
inline void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
|
||||
inline void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v) { os_atomic_stptr (x, (uintptr_t) v); }
|
||||
|
||||
/* INC */
|
||||
|
||||
OS_INLINE void os_atomic_inc32 (volatile os_atomic_uint32_t *x) {
|
||||
inline void os_atomic_inc32 (volatile os_atomic_uint32_t *x) {
|
||||
__sync_fetch_and_add (&x->v, 1);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE void os_atomic_inc64 (volatile os_atomic_uint64_t *x) {
|
||||
inline void os_atomic_inc64 (volatile os_atomic_uint64_t *x) {
|
||||
__sync_fetch_and_add (&x->v, 1);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE void os_atomic_incptr (volatile os_atomic_uintptr_t *x) {
|
||||
inline void os_atomic_incptr (volatile os_atomic_uintptr_t *x) {
|
||||
__sync_fetch_and_add (&x->v, 1);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x) {
|
||||
inline uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x) {
|
||||
return __sync_add_and_fetch (&x->v, 1);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x) {
|
||||
inline uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x) {
|
||||
return __sync_add_and_fetch (&x->v, 1);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x) {
|
||||
inline uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x) {
|
||||
return __sync_add_and_fetch (&x->v, 1);
|
||||
}
|
||||
|
||||
/* DEC */
|
||||
|
||||
OS_INLINE void os_atomic_dec32 (volatile os_atomic_uint32_t *x) {
|
||||
inline void os_atomic_dec32 (volatile os_atomic_uint32_t *x) {
|
||||
__sync_fetch_and_sub (&x->v, 1);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE void os_atomic_dec64 (volatile os_atomic_uint64_t *x) {
|
||||
inline void os_atomic_dec64 (volatile os_atomic_uint64_t *x) {
|
||||
__sync_fetch_and_sub (&x->v, 1);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE void os_atomic_decptr (volatile os_atomic_uintptr_t *x) {
|
||||
inline void os_atomic_decptr (volatile os_atomic_uintptr_t *x) {
|
||||
__sync_fetch_and_sub (&x->v, 1);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x) {
|
||||
inline uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x) {
|
||||
return __sync_sub_and_fetch (&x->v, 1);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x) {
|
||||
inline uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x) {
|
||||
return __sync_sub_and_fetch (&x->v, 1);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x) {
|
||||
inline uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x) {
|
||||
return __sync_sub_and_fetch (&x->v, 1);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x) {
|
||||
inline uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x) {
|
||||
return __sync_fetch_and_sub (&x->v, 1);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x) {
|
||||
inline uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x) {
|
||||
return __sync_fetch_and_sub (&x->v, 1);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x) {
|
||||
inline uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x) {
|
||||
return __sync_fetch_and_sub (&x->v, 1);
|
||||
}
|
||||
|
||||
/* ADD */
|
||||
|
||||
OS_INLINE void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
__sync_fetch_and_add (&x->v, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
__sync_fetch_and_add (&x->v, v);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
__sync_fetch_and_add (&x->v, v);
|
||||
}
|
||||
OS_INLINE void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
inline void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
os_atomic_addptr ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
return __sync_add_and_fetch (&x->v, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
return __sync_add_and_fetch (&x->v, v);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
return __sync_add_and_fetch (&x->v, v);
|
||||
}
|
||||
OS_INLINE void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
inline void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
return (void *) os_atomic_addptr_nv ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
|
||||
}
|
||||
|
||||
/* SUB */
|
||||
|
||||
OS_INLINE void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
__sync_fetch_and_sub (&x->v, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
__sync_fetch_and_sub (&x->v, v);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
__sync_fetch_and_sub (&x->v, v);
|
||||
}
|
||||
OS_INLINE void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
inline void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
os_atomic_subptr ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
return __sync_sub_and_fetch (&x->v, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
return __sync_sub_and_fetch (&x->v, v);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
return __sync_sub_and_fetch (&x->v, v);
|
||||
}
|
||||
OS_INLINE void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
inline void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
return (void *) os_atomic_subptr_nv ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
|
||||
}
|
||||
|
||||
/* AND */
|
||||
|
||||
OS_INLINE void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
__sync_fetch_and_and (&x->v, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
__sync_fetch_and_and (&x->v, v);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
__sync_fetch_and_and (&x->v, v);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
return __sync_fetch_and_and (&x->v, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
return __sync_fetch_and_and (&x->v, v);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
return __sync_fetch_and_and (&x->v, v);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
return __sync_and_and_fetch (&x->v, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
return __sync_and_and_fetch (&x->v, v);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
return __sync_and_and_fetch (&x->v, v);
|
||||
}
|
||||
|
||||
/* OR */
|
||||
|
||||
OS_INLINE void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
__sync_fetch_and_or (&x->v, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
__sync_fetch_and_or (&x->v, v);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
__sync_fetch_and_or (&x->v, v);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
return __sync_fetch_and_or (&x->v, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
return __sync_fetch_and_or (&x->v, v);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
return __sync_fetch_and_or (&x->v, v);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
return __sync_or_and_fetch (&x->v, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
return __sync_or_and_fetch (&x->v, v);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
return __sync_or_and_fetch (&x->v, v);
|
||||
}
|
||||
|
||||
/* CAS */
|
||||
|
||||
OS_INLINE int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
|
||||
inline int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
|
||||
return __sync_bool_compare_and_swap (&x->v, exp, des);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_INLINE int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des) {
|
||||
inline int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des) {
|
||||
return __sync_bool_compare_and_swap (&x->v, exp, des);
|
||||
}
|
||||
#endif
|
||||
OS_INLINE int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
|
||||
inline int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
|
||||
return __sync_bool_compare_and_swap (&x->v, exp, des);
|
||||
}
|
||||
OS_INLINE int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des) {
|
||||
inline int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des) {
|
||||
return os_atomic_casptr (x, (uintptr_t) exp, (uintptr_t) des);
|
||||
}
|
||||
#if OS_ATOMIC_LIFO_SUPPORT
|
||||
OS_INLINE int os_atomic_casvoidp2 (volatile os_atomic_uintptr2_t *x, uintptr_t a0, uintptr_t b0, uintptr_t a1, uintptr_t b1) {
|
||||
inline int os_atomic_casvoidp2 (volatile os_atomic_uintptr2_t *x, uintptr_t a0, uintptr_t b0, uintptr_t a1, uintptr_t b1) {
|
||||
os_atomic_uintptr2_t o, n;
|
||||
o.s.a = a0; o.s.b = b0;
|
||||
n.s.a = a1; n.s.b = b1;
|
||||
|
@ -351,22 +275,20 @@ OS_INLINE int os_atomic_casvoidp2 (volatile os_atomic_uintptr2_t *x, uintptr_t a
|
|||
|
||||
/* FENCES */
|
||||
|
||||
OS_INLINE void os_atomic_fence (void) {
|
||||
inline void os_atomic_fence (void) {
|
||||
__sync_synchronize ();
|
||||
}
|
||||
OS_INLINE void os_atomic_fence_ldld (void) {
|
||||
inline void os_atomic_fence_ldld (void) {
|
||||
#if !(defined __i386__ || defined __x86_64__ || defined _M_IX86 || defined _M_X64)
|
||||
__sync_synchronize ();
|
||||
#endif
|
||||
}
|
||||
OS_INLINE void os_atomic_fence_acq (void) {
|
||||
inline void os_atomic_fence_acq (void) {
|
||||
os_atomic_fence ();
|
||||
}
|
||||
OS_INLINE void os_atomic_fence_rel (void) {
|
||||
inline void os_atomic_fence_rel (void) {
|
||||
os_atomic_fence ();
|
||||
}
|
||||
|
||||
#endif /* not omit functions */
|
||||
|
||||
#define OS_ATOMIC_SUPPORT 1
|
||||
#endif
|
||||
|
|
|
@ -13,72 +13,70 @@
|
|||
|
||||
#define OS_ATOMIC64_SUPPORT 1
|
||||
|
||||
#if ! OS_ATOMICS_OMIT_FUNCTIONS
|
||||
|
||||
/* LD, ST */
|
||||
|
||||
OS_INLINE uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x) { return x->v; }
|
||||
OS_INLINE uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x) { return x->v; }
|
||||
OS_INLINE uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x) { return x->v; }
|
||||
OS_INLINE void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x) { return (void *) os_atomic_ldptr (x); }
|
||||
inline uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x) { return x->v; }
|
||||
inline uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x) { return x->v; }
|
||||
inline uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x) { return x->v; }
|
||||
inline void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x) { return (void *) os_atomic_ldptr (x); }
|
||||
|
||||
OS_INLINE void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v) { x->v = v; }
|
||||
OS_INLINE void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v) { x->v = v; }
|
||||
OS_INLINE void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
|
||||
OS_INLINE void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v) { os_atomic_stptr (x, (uintptr_t) v); }
|
||||
inline void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v) { x->v = v; }
|
||||
inline void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v) { x->v = v; }
|
||||
inline void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
|
||||
inline void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v) { os_atomic_stptr (x, (uintptr_t) v); }
|
||||
|
||||
/* INC */
|
||||
|
||||
OS_INLINE void os_atomic_inc32 (volatile os_atomic_uint32_t *x) {
|
||||
inline void os_atomic_inc32 (volatile os_atomic_uint32_t *x) {
|
||||
atomic_inc_32 (&x->v);
|
||||
}
|
||||
OS_INLINE void os_atomic_inc64 (volatile os_atomic_uint64_t *x) {
|
||||
inline void os_atomic_inc64 (volatile os_atomic_uint64_t *x) {
|
||||
atomic_inc_64 (&x->v);
|
||||
}
|
||||
OS_INLINE void os_atomic_incptr (volatile os_atomic_uintptr_t *x) {
|
||||
inline void os_atomic_incptr (volatile os_atomic_uintptr_t *x) {
|
||||
atomic_inc_ulong (&x->v);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x) {
|
||||
inline uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x) {
|
||||
return atomic_inc_32_nv (&x->v);
|
||||
}
|
||||
OS_INLINE uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x) {
|
||||
inline uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x) {
|
||||
return atomic_inc_64_nv (&x->v);
|
||||
}
|
||||
OS_INLINE uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x) {
|
||||
inline uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x) {
|
||||
return atomic_inc_ulong_nv (&x->v);
|
||||
}
|
||||
|
||||
/* DEC */
|
||||
|
||||
OS_INLINE void os_atomic_dec32 (volatile os_atomic_uint32_t *x) {
|
||||
inline void os_atomic_dec32 (volatile os_atomic_uint32_t *x) {
|
||||
atomic_dec_32 (&x->v);
|
||||
}
|
||||
OS_INLINE void os_atomic_dec64 (volatile os_atomic_uint64_t *x) {
|
||||
inline void os_atomic_dec64 (volatile os_atomic_uint64_t *x) {
|
||||
atomic_dec_64 (&x->v);
|
||||
}
|
||||
OS_INLINE void os_atomic_decptr (volatile os_atomic_uintptr_t *x) {
|
||||
inline void os_atomic_decptr (volatile os_atomic_uintptr_t *x) {
|
||||
atomic_dec_ulong (&x->v);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x) {
|
||||
inline uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x) {
|
||||
return atomic_dec_32_nv (&x->v);
|
||||
}
|
||||
OS_INLINE uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x) {
|
||||
inline uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x) {
|
||||
return atomic_dec_64_nv (&x->v);
|
||||
}
|
||||
OS_INLINE uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x) {
|
||||
inline uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x) {
|
||||
return atomic_dec_ulong_nv (&x->v);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x) {
|
||||
inline uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x) {
|
||||
uint32_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval - 1; } while (atomic_cas_32 (&x->v, oldval, newval) != oldval);
|
||||
return oldval;
|
||||
}
|
||||
OS_INLINE uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x) {
|
||||
inline uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x) {
|
||||
uint64_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval - 1; } while (atomic_cas_64 (&x->v, oldval, newval) != oldval);
|
||||
return oldval;
|
||||
}
|
||||
OS_INLINE uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x) {
|
||||
inline uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x) {
|
||||
uintptr_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval - 1; } while (atomic_cas_64 (&x->v, oldval, newval) != oldval);
|
||||
return oldval;
|
||||
|
@ -86,161 +84,159 @@ OS_INLINE uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x) {
|
|||
|
||||
/* ADD */
|
||||
|
||||
OS_INLINE void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
atomic_add_32 (&x->v, v);
|
||||
}
|
||||
OS_INLINE void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
atomic_add_64 (&x->v, v);
|
||||
}
|
||||
OS_INLINE void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
atomic_add_long (&x->v, v);
|
||||
}
|
||||
OS_INLINE void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
inline void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
atomic_add_ptr (&x->v, v);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
return atomic_add_32_nv (&x->v, v);
|
||||
}
|
||||
OS_INLINE uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
return atomic_add_64_nv (&x->v, v);
|
||||
}
|
||||
OS_INLINE uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
return atomic_add_long_nv (&x->v, v);
|
||||
}
|
||||
OS_INLINE void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
inline void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
return atomic_add_ptr_nv (&x->v, v);
|
||||
}
|
||||
|
||||
/* SUB */
|
||||
|
||||
OS_INLINE void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
atomic_add_32 (&x->v, -v);
|
||||
}
|
||||
OS_INLINE void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
atomic_add_64 (&x->v, -v);
|
||||
}
|
||||
OS_INLINE void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
atomic_add_long (&x->v, -v);
|
||||
}
|
||||
OS_INLINE void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
inline void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
atomic_add_ptr (&x->v, -v);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
return atomic_add_32_nv (&x->v, -v);
|
||||
}
|
||||
OS_INLINE uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
return atomic_add_64_nv (&x->v, -v);
|
||||
}
|
||||
OS_INLINE uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
return atomic_add_long_nv (&x->v, -v);
|
||||
}
|
||||
OS_INLINE void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
inline void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
return atomic_add_ptr_nv (&x->v, -v);
|
||||
}
|
||||
|
||||
/* AND */
|
||||
|
||||
OS_INLINE void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
atomic_and_32 (&x->v, v);
|
||||
}
|
||||
OS_INLINE void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
atomic_and_64 (&x->v, v);
|
||||
}
|
||||
OS_INLINE void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
atomic_and_ulong (&x->v, v);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
uint32_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval & v; } while (atomic_cas_32 (&x->v, oldval, newval) != oldval);
|
||||
return oldval;
|
||||
}
|
||||
OS_INLINE uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
uint64_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval & v; } while (atomic_cas_64 (&x->v, oldval, newval) != oldval);
|
||||
return oldval;
|
||||
}
|
||||
OS_INLINE uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
uintptr_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval & v; } while (atomic_cas_ulong (&x->v, oldval, newval) != oldval);
|
||||
return oldval;
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
return atomic_and_32_nv (&x->v, v);
|
||||
}
|
||||
OS_INLINE uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
return atomic_and_64_nv (&x->v, v);
|
||||
}
|
||||
OS_INLINE uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
return atomic_and_ulong_nv (&x->v, v);
|
||||
}
|
||||
|
||||
/* OR */
|
||||
|
||||
OS_INLINE void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
atomic_or_32 (&x->v, v);
|
||||
}
|
||||
OS_INLINE void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
atomic_or_64 (&x->v, v);
|
||||
}
|
||||
OS_INLINE void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
atomic_or_ulong (&x->v, v);
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
uint32_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval | v; } while (atomic_cas_32 (&x->v, oldval, newval) != oldval);
|
||||
return oldval;
|
||||
}
|
||||
OS_INLINE uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
uint64_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval | v; } while (atomic_cas_64 (&x->v, oldval, newval) != oldval);
|
||||
return oldval;
|
||||
}
|
||||
OS_INLINE uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
uintptr_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval | v; } while (atomic_cas_ulong (&x->v, oldval, newval) != oldval);
|
||||
return oldval;
|
||||
}
|
||||
OS_INLINE uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
return atomic_or_32_nv (&x->v, v);
|
||||
}
|
||||
OS_INLINE uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
return atomic_or_64_nv (&x->v, v);
|
||||
}
|
||||
OS_INLINE uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
return atomic_or_ulong_nv (&x->v, v);
|
||||
}
|
||||
|
||||
/* CAS */
|
||||
|
||||
OS_INLINE int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
|
||||
inline int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
|
||||
return atomic_cas_32 (&x->v, exp, des) == exp;
|
||||
}
|
||||
OS_INLINE int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des) {
|
||||
inline int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des) {
|
||||
return atomic_cas_64 (&x->v, exp, des) == exp;
|
||||
}
|
||||
OS_INLINE int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
|
||||
inline int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
|
||||
return atomic_cas_ulong (&x->v, exp, des) == exp;
|
||||
}
|
||||
OS_INLINE int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des) {
|
||||
inline int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des) {
|
||||
return atomic_cas_ptr (&x->v, exp, des) == exp;
|
||||
}
|
||||
|
||||
/* FENCES */
|
||||
|
||||
OS_INLINE void os_atomic_fence (void) {
|
||||
inline void os_atomic_fence (void) {
|
||||
membar_exit ();
|
||||
membar_enter ();
|
||||
}
|
||||
OS_INLINE void os_atomic_fence_ldld (void) {
|
||||
inline void os_atomic_fence_ldld (void) {
|
||||
membar_enter ();
|
||||
}
|
||||
OS_INLINE void os_atomic_fence_acq (void) {
|
||||
inline void os_atomic_fence_acq (void) {
|
||||
membar_enter ();
|
||||
}
|
||||
OS_INLINE void os_atomic_fence_rel (void) {
|
||||
inline void os_atomic_fence_rel (void) {
|
||||
membar_exit ();
|
||||
}
|
||||
|
||||
#endif /* not omit functions */
|
||||
|
||||
#define OS_ATOMIC_SUPPORT 1
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
#define OS_ATOMIC_PTROP(name) name
|
||||
#endif
|
||||
|
||||
#if ! OS_ATOMICS_OMIT_FUNCTIONS
|
||||
|
||||
/* Experience is that WinCE doesn't provide these, and that neither does VS8 */
|
||||
#if ! defined OS_WINCE_DEFS_H && _MSC_VER > 1400
|
||||
#if defined _M_IX86 || defined _M_ARM
|
||||
|
@ -42,140 +40,134 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#if OS_ATOMIC_HAVE_INLINE
|
||||
#define OS_ATOMIC_API_INLINE OS_ATOMIC_INLINE
|
||||
#else
|
||||
#define OS_ATOMIC_API_INLINE OSAPI_EXPORT
|
||||
#endif
|
||||
|
||||
/* LD, ST */
|
||||
|
||||
OS_ATOMIC_API_INLINE uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x) { return x->v; }
|
||||
inline uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x) { return x->v; }
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x) { return x->v; }
|
||||
inline uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x) { return x->v; }
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x) { return x->v; }
|
||||
OS_ATOMIC_API_INLINE void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x) { return (void *) os_atomic_ldptr (x); }
|
||||
inline uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x) { return x->v; }
|
||||
inline void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x) { return (void *) os_atomic_ldptr (x); }
|
||||
|
||||
OS_ATOMIC_API_INLINE void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v) { x->v = v; }
|
||||
inline void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v) { x->v = v; }
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v) { x->v = v; }
|
||||
inline void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v) { x->v = v; }
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
|
||||
OS_ATOMIC_API_INLINE void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v) { os_atomic_stptr (x, (uintptr_t) v); }
|
||||
inline void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
|
||||
inline void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v) { os_atomic_stptr (x, (uintptr_t) v); }
|
||||
|
||||
/* CAS */
|
||||
|
||||
OS_ATOMIC_API_INLINE int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
|
||||
inline int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
|
||||
return InterlockedCompareExchange (&x->v, des, exp) == exp;
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des) {
|
||||
inline int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des) {
|
||||
return InterlockedCompareExchange64 (&x->v, des, exp) == exp;
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
|
||||
inline int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
|
||||
return OS_ATOMIC_PTROP (InterlockedCompareExchange) (&x->v, des, exp) == exp;
|
||||
}
|
||||
OS_ATOMIC_API_INLINE int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des) {
|
||||
inline int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des) {
|
||||
return os_atomic_casptr ((volatile os_atomic_uintptr_t *) x, (uintptr_t) exp, (uintptr_t) des);
|
||||
}
|
||||
|
||||
/* INC */
|
||||
|
||||
OS_ATOMIC_API_INLINE void os_atomic_inc32 (volatile os_atomic_uint32_t *x) {
|
||||
inline void os_atomic_inc32 (volatile os_atomic_uint32_t *x) {
|
||||
InterlockedIncrement (&x->v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE void os_atomic_inc64 (volatile os_atomic_uint64_t *x) {
|
||||
inline void os_atomic_inc64 (volatile os_atomic_uint64_t *x) {
|
||||
InterlockedIncrement64 (&x->v);
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE void os_atomic_incptr (volatile os_atomic_uintptr_t *x) {
|
||||
inline void os_atomic_incptr (volatile os_atomic_uintptr_t *x) {
|
||||
OS_ATOMIC_PTROP (InterlockedIncrement) (&x->v);
|
||||
}
|
||||
OS_ATOMIC_API_INLINE uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x) {
|
||||
inline uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x) {
|
||||
return InterlockedIncrement (&x->v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x) {
|
||||
inline uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x) {
|
||||
return InterlockedIncrement64 (&x->v);
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x) {
|
||||
inline uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x) {
|
||||
return OS_ATOMIC_PTROP (InterlockedIncrement) (&x->v);
|
||||
}
|
||||
|
||||
/* DEC */
|
||||
|
||||
OS_ATOMIC_API_INLINE void os_atomic_dec32 (volatile os_atomic_uint32_t *x) {
|
||||
inline void os_atomic_dec32 (volatile os_atomic_uint32_t *x) {
|
||||
InterlockedDecrement (&x->v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE void os_atomic_dec64 (volatile os_atomic_uint64_t *x) {
|
||||
inline void os_atomic_dec64 (volatile os_atomic_uint64_t *x) {
|
||||
InterlockedDecrement64 (&x->v);
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE void os_atomic_decptr (volatile os_atomic_uintptr_t *x) {
|
||||
inline void os_atomic_decptr (volatile os_atomic_uintptr_t *x) {
|
||||
OS_ATOMIC_PTROP (InterlockedDecrement) (&x->v);
|
||||
}
|
||||
OS_ATOMIC_API_INLINE uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x) {
|
||||
inline uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x) {
|
||||
return InterlockedDecrement (&x->v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x) {
|
||||
inline uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x) {
|
||||
return InterlockedDecrement64 (&x->v);
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x) {
|
||||
inline uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x) {
|
||||
return OS_ATOMIC_PTROP (InterlockedDecrement) (&x->v);
|
||||
}
|
||||
OS_ATOMIC_API_INLINE uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x) {
|
||||
inline uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x) {
|
||||
return InterlockedDecrement (&x->v) + 1;
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x) {
|
||||
inline uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x) {
|
||||
return InterlockedDecrement64 (&x->v) + 1;
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x) {
|
||||
inline uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x) {
|
||||
return OS_ATOMIC_PTROP (InterlockedDecrement) (&x->v) + 1;
|
||||
}
|
||||
|
||||
/* ADD */
|
||||
|
||||
OS_ATOMIC_API_INLINE void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
InterlockedExchangeAdd (&x->v, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
InterlockedExchangeAdd64 (&x->v, v);
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
OS_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, v);
|
||||
}
|
||||
OS_ATOMIC_API_INLINE void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
inline void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
os_atomic_addptr ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
|
||||
}
|
||||
OS_ATOMIC_API_INLINE uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
return InterlockedExchangeAdd (&x->v, v) + v;
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
return InterlockedExchangeAdd64 (&x->v, v) + v;
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
return OS_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, v) + v;
|
||||
}
|
||||
OS_ATOMIC_API_INLINE void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
inline void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
return (void *) os_atomic_addptr_nv ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
|
||||
}
|
||||
|
||||
/* SUB */
|
||||
|
||||
OS_ATOMIC_API_INLINE void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
/* disable unary minus applied to unsigned type, result still unsigned */
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4146)
|
||||
|
@ -183,7 +175,7 @@ OS_ATOMIC_API_INLINE void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint3
|
|||
#pragma warning (pop)
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
/* disable unary minus applied to unsigned type, result still unsigned */
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4146)
|
||||
|
@ -191,17 +183,17 @@ OS_ATOMIC_API_INLINE void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint6
|
|||
#pragma warning (pop)
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
/* disable unary minus applied to unsigned type, result still unsigned */
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4146)
|
||||
OS_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, -v);
|
||||
#pragma warning (pop)
|
||||
}
|
||||
OS_ATOMIC_API_INLINE void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
inline void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
os_atomic_subptr ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
|
||||
}
|
||||
OS_ATOMIC_API_INLINE uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
/* disable unary minus applied to unsigned type, result still unsigned */
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4146)
|
||||
|
@ -209,7 +201,7 @@ OS_ATOMIC_API_INLINE uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x
|
|||
#pragma warning (pop)
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
/* disable unary minus applied to unsigned type, result still unsigned */
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4146)
|
||||
|
@ -217,14 +209,14 @@ OS_ATOMIC_API_INLINE uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x
|
|||
#pragma warning (pop)
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
/* disable unary minus applied to unsigned type, result still unsigned */
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4146)
|
||||
return OS_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, -v) - v;
|
||||
#pragma warning (pop)
|
||||
}
|
||||
OS_ATOMIC_API_INLINE void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
inline void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
|
||||
return (void *) os_atomic_subptr_nv ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
|
||||
}
|
||||
|
||||
|
@ -232,85 +224,85 @@ OS_ATOMIC_API_INLINE void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x,
|
|||
|
||||
#if defined OS_ATOMIC_INTERLOCKED_AND
|
||||
|
||||
OS_ATOMIC_API_INLINE void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
OS_ATOMIC_INTERLOCKED_AND (&x->v, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
InterlockedAnd64 (&x->v, v);
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
OS_ATOMIC_PTROP (OS_ATOMIC_INTERLOCKED_AND) (&x->v, v);
|
||||
}
|
||||
OS_ATOMIC_API_INLINE uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
return OS_ATOMIC_INTERLOCKED_AND (&x->v, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
return InterlockedAnd64 (&x->v, v);
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
return OS_ATOMIC_PTROP (OS_ATOMIC_INTERLOCKED_AND) (&x->v, v);
|
||||
}
|
||||
OS_ATOMIC_API_INLINE uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
return OS_ATOMIC_INTERLOCKED_AND (&x->v, v) & v;
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
return InterlockedAnd64 (&x->v, v) & v;
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
return OS_ATOMIC_PTROP (OS_ATOMIC_INTERLOCKED_AND) (&x->v, v) & v;
|
||||
}
|
||||
|
||||
#else /* synthesize via CAS */
|
||||
|
||||
OS_ATOMIC_API_INLINE uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
uint64_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval & v; } while (!os_atomic_cas32 (x, oldval, newval));
|
||||
return oldval;
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
uint64_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval & v; } while (!os_atomic_cas64 (x, oldval, newval));
|
||||
return oldval;
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
uintptr_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval & v; } while (!os_atomic_casptr (x, oldval, newval));
|
||||
return oldval;
|
||||
}
|
||||
OS_ATOMIC_API_INLINE uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
uint32_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval & v; } while (!os_atomic_cas32 (x, oldval, newval));
|
||||
return newval;
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
uint64_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval & v; } while (!os_atomic_cas64 (x, oldval, newval));
|
||||
return newval;
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
uintptr_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval & v; } while (!os_atomic_casptr (x, oldval, newval));
|
||||
return newval;
|
||||
}
|
||||
OS_ATOMIC_API_INLINE void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
(void) os_atomic_and32_nv (x, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
(void) os_atomic_and64_nv (x, v);
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
(void) os_atomic_andptr_nv (x, v);
|
||||
}
|
||||
|
||||
|
@ -320,85 +312,85 @@ OS_ATOMIC_API_INLINE void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uin
|
|||
|
||||
#if defined OS_ATOMIC_INTERLOCKED_OR
|
||||
|
||||
OS_ATOMIC_API_INLINE void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
OS_ATOMIC_INTERLOCKED_OR (&x->v, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
InterlockedOr64 (&x->v, v);
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
OS_ATOMIC_PTROP (OS_ATOMIC_INTERLOCKED_OR) (&x->v, v);
|
||||
}
|
||||
OS_ATOMIC_API_INLINE uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
return OS_ATOMIC_INTERLOCKED_OR (&x->v, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
return InterlockedOr64 (&x->v, v);
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
return OS_ATOMIC_PTROP (OS_ATOMIC_INTERLOCKED_OR) (&x->v, v);
|
||||
}
|
||||
OS_ATOMIC_API_INLINE uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
return OS_ATOMIC_INTERLOCKED_OR (&x->v, v) | v;
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
return InterlockedOr64 (&x->v, v) | v;
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
return OS_ATOMIC_PTROP (OS_ATOMIC_INTERLOCKED_OR) (&x->v, v) | v;
|
||||
}
|
||||
|
||||
#else /* synthesize via CAS */
|
||||
|
||||
OS_ATOMIC_API_INLINE uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
uint32_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval | v; } while (!os_atomic_cas32 (x, oldval, newval));
|
||||
return oldval;
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
uint64_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval | v; } while (!os_atomic_cas64 (x, oldval, newval));
|
||||
return oldval;
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
uintptr_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval | v; } while (!os_atomic_casptr (x, oldval, newval));
|
||||
return oldval;
|
||||
}
|
||||
OS_ATOMIC_API_INLINE uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
uint32_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval | v; } while (!os_atomic_cas32 (x, oldval, newval));
|
||||
return newval;
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
uint64_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval | v; } while (!os_atomic_cas64 (x, oldval, newval));
|
||||
return newval;
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
uintptr_t oldval, newval;
|
||||
do { oldval = x->v; newval = oldval | v; } while (!os_atomic_casptr (x, oldval, newval));
|
||||
return newval;
|
||||
}
|
||||
OS_ATOMIC_API_INLINE void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
inline void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
|
||||
(void) os_atomic_or32_nv (x, v);
|
||||
}
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
OS_ATOMIC_API_INLINE void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
inline void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
|
||||
(void) os_atomic_or64_nv (x, v);
|
||||
}
|
||||
#endif
|
||||
OS_ATOMIC_API_INLINE void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
inline void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
|
||||
(void) os_atomic_orptr_nv (x, v);
|
||||
}
|
||||
|
||||
|
@ -406,7 +398,7 @@ OS_ATOMIC_API_INLINE void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uint
|
|||
|
||||
/* FENCES */
|
||||
|
||||
OS_ATOMIC_API_INLINE void os_atomic_fence (void) {
|
||||
inline void os_atomic_fence (void) {
|
||||
/* 28113: accessing a local variable tmp via an Interlocked
|
||||
function: This is an unusual usage which could be reconsidered.
|
||||
It is too heavyweight, true, but it does the trick. */
|
||||
|
@ -416,15 +408,15 @@ OS_ATOMIC_API_INLINE void os_atomic_fence (void) {
|
|||
InterlockedExchange (&tmp, 0);
|
||||
#pragma warning (pop)
|
||||
}
|
||||
OS_ATOMIC_API_INLINE void os_atomic_fence_ldld (void) {
|
||||
inline void os_atomic_fence_ldld (void) {
|
||||
#if !(defined _M_IX86 || defined _M_X64)
|
||||
os_atomic_fence ();
|
||||
#endif
|
||||
}
|
||||
OS_ATOMIC_API_INLINE void os_atomic_fence_acq (void) {
|
||||
inline void os_atomic_fence_acq (void) {
|
||||
os_atomic_fence ();
|
||||
}
|
||||
OS_ATOMIC_API_INLINE void os_atomic_fence_rel (void) {
|
||||
inline void os_atomic_fence_rel (void) {
|
||||
os_atomic_fence ();
|
||||
}
|
||||
|
||||
|
@ -432,9 +424,6 @@ OS_ATOMIC_API_INLINE void os_atomic_fence_rel (void) {
|
|||
#undef OS_ATOMIC_INTERLOCKED_OR
|
||||
#undef OS_ATOMIC_INTERLOCKED_AND64
|
||||
#undef OS_ATOMIC_INTERLOCKED_OR64
|
||||
#undef OS_ATOMIC_API_INLINE
|
||||
|
||||
#endif /* not omit functions */
|
||||
|
||||
#undef OS_ATOMIC_PTROP
|
||||
#define OS_ATOMIC_SUPPORT 1
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#error "OS_ENDIANNESS not set correctly"
|
||||
#endif
|
||||
|
||||
#include "os/os_inline.h"
|
||||
#include "os/os_decl_attributes.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef OS_INLINE_H
|
||||
#define OS_INLINE_H
|
||||
|
||||
/* We want to inline these, but we don't want to emit an externally visible
|
||||
symbol for them and we don't want warnings if we don't use them.
|
||||
|
||||
It appears as if a plain "inline" will do just that in C99.
|
||||
|
||||
In traditional GCC one had to use "extern inline" to achieve that effect,
|
||||
but that will cause an externally visible symbol to be emitted by a C99
|
||||
compiler.
|
||||
|
||||
Starting with GCC 4.3, GCC conforms to the C99 standard if compiling in C99
|
||||
mode, unless -fgnu89-inline is specified. It defines __GNUC_STDC_INLINE__
|
||||
if "inline"/"extern inline" behaviour is conforming the C99 standard.
|
||||
|
||||
So: GCC >= 4.3: choose between "inline" & "extern inline" based upon
|
||||
__GNUC_STDC_INLINE__; for GCCs < 4.2, rely on the traditional GCC behaviour;
|
||||
and for other compilers assume they behave conforming the standard if they
|
||||
advertise themselves as C99 compliant (use "inline"), and assume they do not
|
||||
support the inline keywords otherwise.
|
||||
|
||||
GCC when not optimizing ignores "extern inline" functions. So we need to
|
||||
distinguish between optimizing & non-optimizing ... */
|
||||
|
||||
/* Defining OS_HAVE_INLINE is a supported way of overruling this file */
|
||||
#ifndef OS_HAVE_INLINE
|
||||
|
||||
#if __STDC_VERSION__ >= 199901L
|
||||
# /* C99, but old GCC nonetheless doesn't implement C99 semantics ... */
|
||||
# if __GNUC__ && ! defined __GNUC_STDC_INLINE__
|
||||
# define OS_HAVE_INLINE 1
|
||||
# define OS_INLINE extern __inline__
|
||||
# else
|
||||
# define OS_HAVE_INLINE 1
|
||||
# define OS_INLINE inline
|
||||
# endif
|
||||
#elif defined __STDC__ && defined __GNUC__ && ! defined __cplusplus
|
||||
# if __OPTIMIZE__
|
||||
# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
|
||||
# ifdef __GNUC_STDC_INLINE__
|
||||
# define OS_HAVE_INLINE 1
|
||||
# define OS_INLINE __inline__
|
||||
# else
|
||||
# define OS_HAVE_INLINE 1
|
||||
# define OS_INLINE extern __inline__
|
||||
# endif
|
||||
# else
|
||||
# define OS_HAVE_INLINE 1
|
||||
# define OS_INLINE extern __inline__
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if ! OS_HAVE_INLINE
|
||||
#define OS_INLINE
|
||||
#endif
|
||||
|
||||
#endif /* not defined OS_HAVE_INLINE */
|
||||
|
||||
#endif /* OS_INLINE_H */
|
|
@ -9,12 +9,123 @@
|
|||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#define OS_HAVE_INLINE 0 /* override automatic determination of inlining */
|
||||
#define OS_INLINE /* no "inline" in function defs (not really needed) */
|
||||
#define OS_ATOMICS_OMIT_FUNCTIONS 0 /* force inclusion of functions defs */
|
||||
|
||||
#include "os/os.h"
|
||||
|
||||
/* LD, ST */
|
||||
extern inline uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x);
|
||||
#endif
|
||||
extern inline uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x);
|
||||
extern inline void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x);
|
||||
extern inline void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
extern inline void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
extern inline void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v);
|
||||
/* INC */
|
||||
extern inline void os_atomic_inc32 (volatile os_atomic_uint32_t *x);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline void os_atomic_inc64 (volatile os_atomic_uint64_t *x);
|
||||
#endif
|
||||
extern inline void os_atomic_incptr (volatile os_atomic_uintptr_t *x);
|
||||
extern inline uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x);
|
||||
#endif
|
||||
extern inline uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x);
|
||||
/* DEC */
|
||||
extern inline void os_atomic_dec32 (volatile os_atomic_uint32_t *x);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline void os_atomic_dec64 (volatile os_atomic_uint64_t *x);
|
||||
#endif
|
||||
extern inline void os_atomic_decptr (volatile os_atomic_uintptr_t *x);
|
||||
extern inline uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x);
|
||||
#endif
|
||||
extern inline uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x);
|
||||
extern inline uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x);
|
||||
#endif
|
||||
extern inline uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x);
|
||||
/* ADD */
|
||||
extern inline void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
extern inline void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
extern inline void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v);
|
||||
extern inline uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
extern inline uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
extern inline void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v);
|
||||
/* SUB */
|
||||
extern inline void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
extern inline void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
extern inline void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v);
|
||||
extern inline uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
extern inline uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
extern inline void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v);
|
||||
/* AND */
|
||||
extern inline void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
extern inline void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
extern inline uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
extern inline uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
extern inline uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
extern inline uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
/* OR */
|
||||
extern inline void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
extern inline void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
extern inline uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
extern inline uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
extern inline uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
|
||||
#endif
|
||||
extern inline uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
|
||||
/* CAS */
|
||||
extern inline int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
extern inline int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des);
|
||||
#endif
|
||||
extern inline int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des);
|
||||
extern inline int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des);
|
||||
#if OS_ATOMIC_LIFO_SUPPORT
|
||||
extern inline int os_atomic_casvoidp2 (volatile os_atomic_uintptr2_t *x, uintptr_t a0, uintptr_t b0, uintptr_t a1, uintptr_t b1);
|
||||
#endif
|
||||
/* FENCES */
|
||||
extern inline void os_atomic_fence (void);
|
||||
extern inline void os_atomic_fence_ldld (void);
|
||||
extern inline void os_atomic_fence_acq (void);
|
||||
extern inline void os_atomic_fence_rel (void);
|
||||
|
||||
#if OS_ATOMIC_LIFO_SUPPORT
|
||||
void os_atomic_lifo_init (os_atomic_lifo_t *head)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue