42#error "atomics.h may not be included from frontend code"
45#define INSIDE_ATOMICS_H
66#if defined(__arm__) || defined(__arm) || defined(__aarch64__)
68#elif defined(__i386__) || defined(__i386) || defined(__x86_64__)
70#elif defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__) || defined(__powerpc64__)
87#if defined(__GNUC__) || defined(__INTEL_COMPILER)
89#elif defined(_MSC_VER)
96#if !defined(PG_HAVE_ATOMIC_U32_SUPPORT)
97#error "could not find an implementation of pg_atomic_uint32"
99#if !defined(pg_compiler_barrier_impl)
100#error "could not find an implementation of pg_compiler_barrier"
102#if !defined(pg_memory_barrier_impl)
103#error "could not find an implementation of pg_memory_barrier_impl"
129#define pg_compiler_barrier() pg_compiler_barrier_impl()
141#define pg_memory_barrier() pg_memory_barrier_impl()
154#define pg_read_barrier() pg_read_barrier_impl()
155#define pg_write_barrier() pg_write_barrier_impl()
160#define pg_spin_delay() pg_spin_delay_impl()
170 pg_atomic_init_flag_impl(ptr);
183 return pg_atomic_test_set_flag_impl(ptr);
196 return pg_atomic_unlocked_test_flag_impl(ptr);
207 pg_atomic_clear_flag_impl(ptr);
260 return pg_atomic_read_membarrier_u32_impl(ptr);
317 pg_atomic_write_membarrier_u32_impl(ptr,
val);
383 return pg_atomic_fetch_sub_u32_impl(ptr, sub_);
397 return pg_atomic_fetch_and_u32_impl(ptr, and_);
411 return pg_atomic_fetch_or_u32_impl(ptr, or_);
425 return pg_atomic_add_fetch_u32_impl(ptr, add_);
441 return pg_atomic_sub_fetch_u32_impl(ptr, sub_);
458#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
467#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
476#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
479 return pg_atomic_read_membarrier_u64_impl(ptr);
485#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
494#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
497 pg_atomic_write_membarrier_u64_impl(ptr,
val);
503#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
506 return pg_atomic_exchange_u64_impl(ptr,
newval);
513#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
522#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
531#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
535 return pg_atomic_fetch_sub_u64_impl(ptr, sub_);
541#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
544 return pg_atomic_fetch_and_u64_impl(ptr, and_);
550#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
553 return pg_atomic_fetch_or_u64_impl(ptr, or_);
559#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
562 return pg_atomic_add_fetch_u64_impl(ptr, add_);
568#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
572 return pg_atomic_sub_fetch_u64_impl(ptr, sub_);
587#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
592 if (currval >= target)
598 while (currval < target)
607#undef INSIDE_ATOMICS_H
static bool pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
static uint32 pg_atomic_fetch_add_u32_impl(volatile pg_atomic_uint32 *ptr, int32 add_)
uint64 pg_atomic_fetch_add_u64_impl(volatile pg_atomic_uint64 *ptr, int64 add_)
void pg_atomic_init_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 val_)
bool pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
static uint32 pg_atomic_fetch_and_u32(volatile pg_atomic_uint32 *ptr, uint32 and_)
static bool pg_atomic_compare_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
static void pg_atomic_clear_flag(volatile pg_atomic_flag *ptr)
static uint32 pg_atomic_fetch_or_u32(volatile pg_atomic_uint32 *ptr, uint32 or_)
static uint32 pg_atomic_sub_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
#define pg_memory_barrier()
static uint32 pg_atomic_read_membarrier_u32(volatile pg_atomic_uint32 *ptr)
static uint32 pg_atomic_fetch_sub_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
static bool pg_atomic_compare_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
static void pg_atomic_unlocked_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
static uint64 pg_atomic_read_membarrier_u64(volatile pg_atomic_uint64 *ptr)
static uint32 pg_atomic_fetch_add_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
static uint32 pg_atomic_add_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
static uint64 pg_atomic_monotonic_advance_u64(volatile pg_atomic_uint64 *ptr, uint64 target)
static uint64 pg_atomic_fetch_add_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
static bool pg_atomic_test_set_flag(volatile pg_atomic_flag *ptr)
static uint64 pg_atomic_sub_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
static bool pg_atomic_unlocked_test_flag(volatile pg_atomic_flag *ptr)
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
static void pg_atomic_write_membarrier_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
static uint64 pg_atomic_fetch_and_u64(volatile pg_atomic_uint64 *ptr, uint64 and_)
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
static uint64 pg_atomic_fetch_or_u64(volatile pg_atomic_uint64 *ptr, uint64 or_)
static uint64 pg_atomic_add_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
static void pg_atomic_write_membarrier_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
static uint64 pg_atomic_fetch_sub_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
static uint64 pg_atomic_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 newval)
static void pg_atomic_init_flag(volatile pg_atomic_flag *ptr)
#define AssertPointerAlignment(ptr, bndr)
static uint32 pg_atomic_exchange_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 newval)
static void pg_atomic_unlocked_write_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 val)
static uint64 pg_atomic_read_u64_impl(volatile pg_atomic_uint64 *ptr)
static void pg_atomic_write_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 val)
static void pg_atomic_write_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 val)
static uint32 pg_atomic_read_u32_impl(volatile pg_atomic_uint32 *ptr)
static void pg_atomic_init_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 val_)
Assert(PointerIsAligned(start, uint64))