rcutils  master
C API providing common utilities and data structures.
Macros | Typedefs | Enumerations | Functions
stdatomic.h File Reference
#include <Windows.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <rcutils/logging_macros.h>
Include dependency graph for stdatomic.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _Atomic(T)   struct { T __val; }
 
#define ATOMIC_VAR_INIT(value)   {.__val = (value)}
 
#define atomic_init(obj, value)
 
#define __ATOMIC_RELAXED   0
 
#define __ATOMIC_CONSUME   1
 
#define __ATOMIC_ACQUIRE   2
 
#define __ATOMIC_RELEASE   3
 
#define __ATOMIC_ACQ_REL   4
 
#define __ATOMIC_SEQ_CST   5
 
#define atomic_thread_fence(order)   MemoryBarrier()
 
#define atomic_signal_fence(order)   _ReadWriteBarrier()
 
#define atomic_is_lock_free(obj)   (sizeof((obj)->__val) <= sizeof(void *))
 
#define _RCUTILS_PACKAGE_NAME   "<Unknown Package>"
 
#define rcutils_win32_atomic_compare_exchange_strong(object, out, expected, desired)
 
#define rcutils_win32_atomic_compare_exchange_weak(object, out, expected, desired)   rcutils_win32_atomic_compare_exchange_strong(object, out, expected, desired)
 
#define rcutils_win32_atomic_exchange(object, out, desired)
 
#define rcutils_win32_atomic_fetch_add(object, out, operand)
 
#define rcutils_win32_atomic_fetch_and(object, out, operand)
 
#define rcutils_win32_atomic_fetch_or(object, out, operand)
 
#define rcutils_win32_atomic_fetch_sub(object, out, operand)   rcutils_win32_atomic_fetch_add(object, out, -(operand))
 
#define rcutils_win32_atomic_fetch_xor(object, out, operand)
 
#define rcutils_win32_atomic_load(object, out)
 
#define rcutils_win32_atomic_store(object, desired)
 

Typedefs

typedef enum memory_order memory_order
 

Enumerations

enum  memory_order {
  memory_order_relaxed = __ATOMIC_RELAXED, memory_order_consume = __ATOMIC_CONSUME, memory_order_acquire = __ATOMIC_ACQUIRE, memory_order_release = __ATOMIC_RELEASE,
  memory_order_acq_rel = __ATOMIC_ACQ_REL, memory_order_seq_cst = __ATOMIC_SEQ_CST, memory_order_relaxed = __ATOMIC_RELAXED, memory_order_consume = __ATOMIC_CONSUME,
  memory_order_acquire = __ATOMIC_ACQUIRE, memory_order_release = __ATOMIC_RELEASE, memory_order_acq_rel = __ATOMIC_ACQ_REL, memory_order_seq_cst = __ATOMIC_SEQ_CST
}
 

Functions

typedef _Atomic (_Bool) atomic_bool
 
typedef _Atomic (char) atomic_char
 
typedef _Atomic (signed char) atomic_schar
 
typedef _Atomic (unsigned char) atomic_uchar
 
typedef _Atomic (short) atomic_short
 
typedef _Atomic (int) atomic_int
 
typedef _Atomic (long) atomic_long
 
typedef _Atomic (unsigned long) atomic_ulong
 
typedef _Atomic (long long) atomic_llong
 
typedef _Atomic (unsigned long long) atomic_ullong
 
typedef _Atomic (int_least16_t) atomic_int_least16_t
 
typedef _Atomic (uint_least16_t) atomic_uint_least16_t
 
typedef _Atomic (int_least32_t) atomic_int_least32_t
 
typedef _Atomic (uint_least32_t) atomic_uint_least32_t
 
typedef _Atomic (int_least64_t) atomic_int_least64_t
 
typedef _Atomic (uint_least64_t) atomic_uint_least64_t
 
typedef _Atomic (int_fast16_t) atomic_int_fast16_t
 
typedef _Atomic (uint_fast16_t) atomic_uint_fast16_t
 
typedef _Atomic (int_fast32_t) atomic_int_fast32_t
 
typedef _Atomic (uint_fast32_t) atomic_uint_fast32_t
 
typedef _Atomic (int_fast64_t) atomic_int_fast64_t
 
typedef _Atomic (uint_fast64_t) atomic_uint_fast64_t
 
typedef _Atomic (intptr_t) atomic_intptr_t
 
typedef _Atomic (uintptr_t) atomic_uintptr_t
 
typedef _Atomic (size_t) atomic_size_t
 
typedef _Atomic (ptrdiff_t) atomic_ptrdiff_t
 
typedef _Atomic (intmax_t) atomic_intmax_t
 
typedef _Atomic (uintmax_t) atomic_uintmax_t
 

Macro Definition Documentation

◆ _Atomic

#define _Atomic (   T)    struct { T __val; }

◆ ATOMIC_VAR_INIT

#define ATOMIC_VAR_INIT (   value)    {.__val = (value)}

◆ atomic_init

#define atomic_init (   obj,
  value 
)
Value:
do { \
(obj)->__val = (value); \
} while (0)

◆ __ATOMIC_RELAXED

#define __ATOMIC_RELAXED   0

◆ __ATOMIC_CONSUME

#define __ATOMIC_CONSUME   1

◆ __ATOMIC_ACQUIRE

#define __ATOMIC_ACQUIRE   2

◆ __ATOMIC_RELEASE

#define __ATOMIC_RELEASE   3

◆ __ATOMIC_ACQ_REL

#define __ATOMIC_ACQ_REL   4

◆ __ATOMIC_SEQ_CST

#define __ATOMIC_SEQ_CST   5

◆ atomic_thread_fence

#define atomic_thread_fence (   order)    MemoryBarrier()

◆ atomic_signal_fence

#define atomic_signal_fence (   order)    _ReadWriteBarrier()

◆ atomic_is_lock_free

#define atomic_is_lock_free (   obj)    (sizeof((obj)->__val) <= sizeof(void *))

◆ _RCUTILS_PACKAGE_NAME

#define _RCUTILS_PACKAGE_NAME   "<Unknown Package>"

◆ rcutils_win32_atomic_compare_exchange_strong

#define rcutils_win32_atomic_compare_exchange_strong (   object,
  out,
  expected,
  desired 
)
Value:
__pragma(warning(push)) \
__pragma(warning(disable: 4244)) \
__pragma(warning(disable: 4047)) \
__pragma(warning(disable: 4024)) \
do { \
switch (sizeof(out)) { \
case sizeof(uint64_t): \
out = _InterlockedCompareExchange64((LONGLONG *) object, desired, *expected); \
break; \
case sizeof(uint32_t): \
out = _InterlockedCompareExchange((LONG *) object, desired, *expected); \
break; \
case sizeof(uint16_t): \
out = _InterlockedCompareExchange16((SHORT *) object, desired, *expected); \
break; \
case sizeof(uint8_t): \
out = _InterlockedCompareExchange8((char *) object, desired, *expected); \
break; \
default: \
RCUTILS_LOG_ERROR_NAMED( \
_RCUTILS_PACKAGE_NAME, "Unsupported integer type in atomic_compare_exchange_strong"); \
exit(-1); \
break; \
} \
} while (0); \
__pragma(warning(pop))
#define _RCUTILS_PACKAGE_NAME
Definition: stdatomic.h:192

◆ rcutils_win32_atomic_compare_exchange_weak

#define rcutils_win32_atomic_compare_exchange_weak (   object,
  out,
  expected,
  desired 
)    rcutils_win32_atomic_compare_exchange_strong(object, out, expected, desired)

◆ rcutils_win32_atomic_exchange

#define rcutils_win32_atomic_exchange (   object,
  out,
  desired 
)
Value:
__pragma(warning(push)) \
__pragma(warning(disable: 4244)) \
__pragma(warning(disable: 4047)) \
__pragma(warning(disable: 4024)) \
do { \
switch (sizeof(out)) { \
case sizeof(uint64_t): \
out = _InterlockedExchange64((LONGLONG *) object, desired); \
break; \
case sizeof(uint32_t): \
out = _InterlockedExchange((LONG *) object, desired); \
break; \
case sizeof(uint16_t): \
out = _InterlockedExchange16((SHORT *) object, desired); \
break; \
case sizeof(uint8_t): \
out = _InterlockedExchange8((char *) object, desired); \
break; \
default: \
RCUTILS_LOG_ERROR_NAMED( \
_RCUTILS_PACKAGE_NAME, "Unsupported integer type in atomic_exchange_strong"); \
exit(-1); \
break; \
} \
} while (0); \
__pragma(warning(pop))
#define _RCUTILS_PACKAGE_NAME
Definition: stdatomic.h:192

◆ rcutils_win32_atomic_fetch_add

#define rcutils_win32_atomic_fetch_add (   object,
  out,
  operand 
)
Value:
__pragma(warning(push)) \
__pragma(warning(disable: 4244)) \
__pragma(warning(disable: 4047)) \
__pragma(warning(disable: 4024)) \
do { \
switch (sizeof(out)) { \
case sizeof(uint64_t): \
out = _InterlockedExchangeAdd64((LONGLONG *) object, operand); \
break; \
case sizeof(uint32_t): \
out = _InterlockedExchangeAdd((LONG *) object, operand); \
break; \
case sizeof(uint16_t): \
out = _InterlockedExchangeAdd16((SHORT *) object, operand); \
break; \
case sizeof(uint8_t): \
out = _InterlockedExchangeAdd8((char *) object, operand); \
break; \
default: \
RCUTILS_LOG_ERROR_NAMED( \
_RCUTILS_PACKAGE_NAME, "Unsupported integer type in atomic_fetch_add"); \
exit(-1); \
break; \
} \
} while (0); \
__pragma(warning(pop))
#define _RCUTILS_PACKAGE_NAME
Definition: stdatomic.h:192

◆ rcutils_win32_atomic_fetch_and

#define rcutils_win32_atomic_fetch_and (   object,
  out,
  operand 
)
Value:
__pragma(warning(push)) \
__pragma(warning(disable: 4244)) \
__pragma(warning(disable: 4047)) \
__pragma(warning(disable: 4024)) \
do { \
switch (sizeof(out)) { \
case sizeof(uint64_t): \
out = _InterlockedAnd64((LONGLONG *) object, operand); \
break; \
case sizeof(uint32_t): \
out = _InterlockedAnd((LONG *) object, operand); \
break; \
case sizeof(uint16_t): \
out = _InterlockedAnd16((SHORT *) object, operand); \
break; \
case sizeof(uint8_t): \
out = _InterlockedAnd8((char *) object, operand); \
break; \
default: \
RCUTILS_LOG_ERROR_NAMED( \
_RCUTILS_PACKAGE_NAME, "Unsupported integer type in atomic_fetch_and"); \
exit(-1); \
break; \
} \
} while (0); \
__pragma(warning(pop))
#define _RCUTILS_PACKAGE_NAME
Definition: stdatomic.h:192

◆ rcutils_win32_atomic_fetch_or

#define rcutils_win32_atomic_fetch_or (   object,
  out,
  operand 
)
Value:
__pragma(warning(push)) \
__pragma(warning(disable: 4244)) \
__pragma(warning(disable: 4047)) \
__pragma(warning(disable: 4024)) \
do { \
switch (sizeof(out)) { \
case sizeof(uint64_t): \
out = _InterlockedOr64((LONGLONG *) object, operand); \
break; \
case sizeof(uint32_t): \
out = _InterlockedOr((LONG *) object, operand); \
break; \
case sizeof(uint16_t): \
out = _InterlockedOr16((SHORT *) object, operand); \
break; \
case sizeof(uint8_t): \
out = _InterlockedOr8((char *) object, operand); \
break; \
default: \
RCUTILS_LOG_ERROR_NAMED( \
_RCUTILS_PACKAGE_NAME, "Unsupported integer type in atomic_fetch_or"); \
exit(-1); \
break; \
} \
} while (0); \
__pragma(warning(pop))
#define _RCUTILS_PACKAGE_NAME
Definition: stdatomic.h:192

◆ rcutils_win32_atomic_fetch_sub

#define rcutils_win32_atomic_fetch_sub (   object,
  out,
  operand 
)    rcutils_win32_atomic_fetch_add(object, out, -(operand))

◆ rcutils_win32_atomic_fetch_xor

#define rcutils_win32_atomic_fetch_xor (   object,
  out,
  operand 
)
Value:
__pragma(warning(push)) \
__pragma(warning(disable: 4244)) \
__pragma(warning(disable: 4047)) \
__pragma(warning(disable: 4024)) \
do { \
switch (sizeof(out)) { \
case sizeof(uint64_t): \
out = _InterlockedXor64((LONGLONG *) object, operand); \
break; \
case sizeof(uint32_t): \
out = _InterlockedXor((LONG *) object, operand); \
break; \
case sizeof(uint16_t): \
out = _InterlockedXor16((SHORT *) object, operand); \
break; \
case sizeof(uint8_t): \
out = _InterlockedXor8((char *) object, operand); \
break; \
default: \
RCUTILS_LOG_ERROR_NAMED( \
_RCUTILS_PACKAGE_NAME, "Unsupported integer type in atomic_fetch_xor"); \
exit(-1); \
break; \
} \
} while (0); \
__pragma(warning(pop))
#define _RCUTILS_PACKAGE_NAME
Definition: stdatomic.h:192

◆ rcutils_win32_atomic_load

#define rcutils_win32_atomic_load (   object,
  out 
)
Value:
__pragma(warning(push)) \
__pragma(warning(disable: 4244)) \
__pragma(warning(disable: 4047)) \
__pragma(warning(disable: 4024)) \
do { \
switch (sizeof(out)) { \
case sizeof(uint64_t): \
out = _InterlockedExchangeAdd64((LONGLONG *) object, 0); \
break; \
case sizeof(uint32_t): \
out = _InterlockedExchangeAdd((LONG *) object, 0); \
break; \
case sizeof(uint16_t): \
out = _InterlockedExchangeAdd16((SHORT *) object, 0); \
break; \
case sizeof(uint8_t): \
out = _InterlockedExchangeAdd8((char *) object, 0); \
break; \
default: \
RCUTILS_LOG_ERROR_NAMED( \
_RCUTILS_PACKAGE_NAME, "Unsupported integer type in atomic_load"); \
exit(-1); \
break; \
} \
} while (0); \
__pragma(warning(pop))
#define _RCUTILS_PACKAGE_NAME
Definition: stdatomic.h:192

◆ rcutils_win32_atomic_store

#define rcutils_win32_atomic_store (   object,
  desired 
)
Value:
do { \
MemoryBarrier(); \
(object)->__val = (desired); \
MemoryBarrier(); \
} while (0)

Typedef Documentation

◆ memory_order

typedef enum memory_order memory_order

Enumeration Type Documentation

◆ memory_order

Enumerator
memory_order_relaxed 
memory_order_consume 
memory_order_acquire 
memory_order_release 
memory_order_acq_rel 
memory_order_seq_cst 
memory_order_relaxed 
memory_order_consume 
memory_order_acquire 
memory_order_release 
memory_order_acq_rel 
memory_order_seq_cst 

Function Documentation

◆ _Atomic() [1/28]

typedef _Atomic ( _Bool  )

◆ _Atomic() [2/28]

typedef _Atomic ( char  )

◆ _Atomic() [3/28]

typedef _Atomic ( signed  char)

◆ _Atomic() [4/28]

typedef _Atomic ( unsigned  char)

◆ _Atomic() [5/28]

typedef _Atomic ( short  )

◆ _Atomic() [6/28]

typedef _Atomic ( int  )

◆ _Atomic() [7/28]

typedef _Atomic ( long  )

◆ _Atomic() [8/28]

typedef _Atomic ( unsigned  long)

◆ _Atomic() [9/28]

typedef _Atomic ( long  long)

◆ _Atomic() [10/28]

typedef _Atomic ( unsigned long  long)

◆ _Atomic() [11/28]

typedef _Atomic ( int_least16_t  )

◆ _Atomic() [12/28]

typedef _Atomic ( uint_least16_t  )

◆ _Atomic() [13/28]

typedef _Atomic ( int_least32_t  )

◆ _Atomic() [14/28]

typedef _Atomic ( uint_least32_t  )

◆ _Atomic() [15/28]

typedef _Atomic ( int_least64_t  )

◆ _Atomic() [16/28]

typedef _Atomic ( uint_least64_t  )

◆ _Atomic() [17/28]

typedef _Atomic ( int_fast16_t  )

◆ _Atomic() [18/28]

typedef _Atomic ( uint_fast16_t  )

◆ _Atomic() [19/28]

typedef _Atomic ( int_fast32_t  )

◆ _Atomic() [20/28]

typedef _Atomic ( uint_fast32_t  )

◆ _Atomic() [21/28]

typedef _Atomic ( int_fast64_t  )

◆ _Atomic() [22/28]

typedef _Atomic ( uint_fast64_t  )

◆ _Atomic() [23/28]

typedef _Atomic ( intptr_t  )

◆ _Atomic() [24/28]

typedef _Atomic ( uintptr_t  )

◆ _Atomic() [25/28]

typedef _Atomic ( size_t  )

◆ _Atomic() [26/28]

typedef _Atomic ( ptrdiff_t  )

◆ _Atomic() [27/28]

typedef _Atomic ( intmax_t  )

◆ _Atomic() [28/28]

typedef _Atomic ( uintmax_t  )