PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
atomics.h File Reference
#include <limits.h>
#include "port/atomics/fallback.h"
#include "port/atomics/generic.h"
Include dependency graph for atomics.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define INSIDE_ATOMICS_H
 
#define pg_compiler_barrier()   pg_compiler_barrier_impl()
 
#define pg_memory_barrier()   pg_memory_barrier_impl()
 
#define pg_read_barrier()   pg_read_barrier_impl()
 
#define pg_write_barrier()   pg_write_barrier_impl()
 
#define pg_spin_delay()   pg_spin_delay_impl()
 

Functions

static void pg_atomic_init_flag (volatile pg_atomic_flag *ptr)
 
static bool pg_atomic_test_set_flag (volatile pg_atomic_flag *ptr)
 
static bool pg_atomic_unlocked_test_flag (volatile pg_atomic_flag *ptr)
 
static void pg_atomic_clear_flag (volatile pg_atomic_flag *ptr)
 
static void pg_atomic_init_u32 (volatile pg_atomic_uint32 *ptr, uint32 val)
 
static uint32 pg_atomic_read_u32 (volatile pg_atomic_uint32 *ptr)
 
static uint32 pg_atomic_read_membarrier_u32 (volatile pg_atomic_uint32 *ptr)
 
static void pg_atomic_write_u32 (volatile pg_atomic_uint32 *ptr, uint32 val)
 
static void pg_atomic_unlocked_write_u32 (volatile pg_atomic_uint32 *ptr, uint32 val)
 
static void pg_atomic_write_membarrier_u32 (volatile pg_atomic_uint32 *ptr, uint32 val)
 
static uint32 pg_atomic_exchange_u32 (volatile pg_atomic_uint32 *ptr, uint32 newval)
 
static bool pg_atomic_compare_exchange_u32 (volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
 
static uint32 pg_atomic_fetch_add_u32 (volatile pg_atomic_uint32 *ptr, int32 add_)
 
static uint32 pg_atomic_fetch_sub_u32 (volatile pg_atomic_uint32 *ptr, int32 sub_)
 
static uint32 pg_atomic_fetch_and_u32 (volatile pg_atomic_uint32 *ptr, uint32 and_)
 
static uint32 pg_atomic_fetch_or_u32 (volatile pg_atomic_uint32 *ptr, uint32 or_)
 
static uint32 pg_atomic_add_fetch_u32 (volatile pg_atomic_uint32 *ptr, int32 add_)
 
static uint32 pg_atomic_sub_fetch_u32 (volatile pg_atomic_uint32 *ptr, int32 sub_)
 
static void pg_atomic_init_u64 (volatile pg_atomic_uint64 *ptr, uint64 val)
 
static uint64 pg_atomic_read_u64 (volatile pg_atomic_uint64 *ptr)
 
static uint64 pg_atomic_read_membarrier_u64 (volatile pg_atomic_uint64 *ptr)
 
static void pg_atomic_write_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_exchange_u64 (volatile pg_atomic_uint64 *ptr, uint64 newval)
 
static bool pg_atomic_compare_exchange_u64 (volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
 
static uint64 pg_atomic_fetch_add_u64 (volatile pg_atomic_uint64 *ptr, int64 add_)
 
static uint64 pg_atomic_fetch_sub_u64 (volatile pg_atomic_uint64 *ptr, int64 sub_)
 
static uint64 pg_atomic_fetch_and_u64 (volatile pg_atomic_uint64 *ptr, uint64 and_)
 
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 uint64 pg_atomic_sub_fetch_u64 (volatile pg_atomic_uint64 *ptr, int64 sub_)
 
static uint64 pg_atomic_monotonic_advance_u64 (volatile pg_atomic_uint64 *ptr, uint64 target)
 

Macro Definition Documentation

◆ INSIDE_ATOMICS_H

#define INSIDE_ATOMICS_H

Definition at line 45 of file atomics.h.

◆ pg_compiler_barrier

#define pg_compiler_barrier ( )    pg_compiler_barrier_impl()

Definition at line 131 of file atomics.h.

◆ pg_memory_barrier

#define pg_memory_barrier ( )    pg_memory_barrier_impl()

Definition at line 143 of file atomics.h.

◆ pg_read_barrier

#define pg_read_barrier ( )    pg_read_barrier_impl()

Definition at line 156 of file atomics.h.

◆ pg_spin_delay

#define pg_spin_delay ( )    pg_spin_delay_impl()

Definition at line 162 of file atomics.h.

◆ pg_write_barrier

#define pg_write_barrier ( )    pg_write_barrier_impl()

Definition at line 157 of file atomics.h.

Function Documentation

◆ pg_atomic_add_fetch_u32()

static uint32 pg_atomic_add_fetch_u32 ( volatile pg_atomic_uint32 ptr,
int32  add_ 
)
inlinestatic

Definition at line 424 of file atomics.h.

425{
427 return pg_atomic_add_fetch_u32_impl(ptr, add_);
428}
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:848

References AssertPointerAlignment.

Referenced by apply_handle_stream_abort(), apply_handle_stream_start(), compute_parallel_delay(), parallel_vacuum_process_safe_indexes(), parallel_vacuum_process_unsafe_indexes(), tbm_prepare_shared_iterate(), and test_atomic_uint32().

◆ pg_atomic_add_fetch_u64()

static uint64 pg_atomic_add_fetch_u64 ( volatile pg_atomic_uint64 ptr,
int64  add_ 
)
inlinestatic

Definition at line 559 of file atomics.h.

560{
561#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
563#endif
564 return pg_atomic_add_fetch_u64_impl(ptr, add_);
565}

References AssertPointerAlignment.

Referenced by EmitProcSignalBarrier(), and test_atomic_uint64().

◆ pg_atomic_clear_flag()

static void pg_atomic_clear_flag ( volatile pg_atomic_flag *  ptr)
inlinestatic

Definition at line 207 of file atomics.h.

208{
209 pg_atomic_clear_flag_impl(ptr);
210}

Referenced by do_autovacuum(), FreeWorkerInfo(), and test_atomic_flag().

◆ pg_atomic_compare_exchange_u32()

static bool pg_atomic_compare_exchange_u32 ( volatile pg_atomic_uint32 ptr,
uint32 expected,
uint32  newval 
)
inlinestatic

Definition at line 349 of file atomics.h.

351{
353 AssertPointerAlignment(expected, 4);
354
355 return pg_atomic_compare_exchange_u32_impl(ptr, expected, newval);
356}
static bool pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
Definition: arch-ppc.h:80
#define newval

References AssertPointerAlignment, newval, and pg_atomic_compare_exchange_u32_impl().

Referenced by ClockSweepTick(), LWLockAttemptLock(), LWLockWakeup(), MarkBufferDirty(), PinBuffer(), ProcArrayGroupClearXid(), test_atomic_uint32(), TransactionGroupUpdateXidStatus(), and UnpinBufferNoOwner().

◆ pg_atomic_compare_exchange_u64()

static bool pg_atomic_compare_exchange_u64 ( volatile pg_atomic_uint64 ptr,
uint64 expected,
uint64  newval 
)
inlinestatic

Definition at line 512 of file atomics.h.

514{
515#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
517#endif
518 return pg_atomic_compare_exchange_u64_impl(ptr, expected, newval);
519}
bool pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
Definition: atomics.c:34

References AssertPointerAlignment, newval, and pg_atomic_compare_exchange_u64_impl().

Referenced by pg_atomic_monotonic_advance_u64(), and test_atomic_uint64().

◆ pg_atomic_exchange_u32()

static uint32 pg_atomic_exchange_u32 ( volatile pg_atomic_uint32 ptr,
uint32  newval 
)
inlinestatic

Definition at line 330 of file atomics.h.

331{
333
335}
static uint32 pg_atomic_exchange_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 newval)
Definition: generic-msvc.h:61

References AssertPointerAlignment, newval, and pg_atomic_exchange_u32_impl().

Referenced by pgarch_readyXlog(), ProcArrayGroupClearXid(), ProcessProcSignalBarrier(), StrategySyncStart(), test_atomic_uint32(), and TransactionGroupUpdateXidStatus().

◆ pg_atomic_exchange_u64()

static uint64 pg_atomic_exchange_u64 ( volatile pg_atomic_uint64 ptr,
uint64  newval 
)
inlinestatic

Definition at line 503 of file atomics.h.

504{
505#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
507#endif
508 return pg_atomic_exchange_u64_impl(ptr, newval);
509}

References AssertPointerAlignment, and newval.

Referenced by LWLockReleaseClearVar(), LWLockUpdateVar(), and test_atomic_uint64().

◆ pg_atomic_fetch_add_u32()

static uint32 pg_atomic_fetch_add_u32 ( volatile pg_atomic_uint32 ptr,
int32  add_ 
)
inlinestatic

◆ pg_atomic_fetch_add_u64()

static uint64 pg_atomic_fetch_add_u64 ( volatile pg_atomic_uint64 ptr,
int64  add_ 
)
inlinestatic

Definition at line 522 of file atomics.h.

523{
524#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
526#endif
527 return pg_atomic_fetch_add_u64_impl(ptr, add_);
528}
uint64 pg_atomic_fetch_add_u64_impl(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.c:62

References AssertPointerAlignment, and pg_atomic_fetch_add_u64_impl().

Referenced by GetFakeLSNForUnloggedRel(), pgstat_request_entry_refs_gc(), table_block_parallelscan_nextpage(), and test_atomic_uint64().

◆ pg_atomic_fetch_and_u32()

static uint32 pg_atomic_fetch_and_u32 ( volatile pg_atomic_uint32 ptr,
uint32  and_ 
)
inlinestatic

Definition at line 396 of file atomics.h.

397{
399 return pg_atomic_fetch_and_u32_impl(ptr, and_);
400}

References AssertPointerAlignment.

Referenced by LWLockDequeueSelf(), LWLockWaitListUnlock(), and test_atomic_uint32().

◆ pg_atomic_fetch_and_u64()

static uint64 pg_atomic_fetch_and_u64 ( volatile pg_atomic_uint64 ptr,
uint64  and_ 
)
inlinestatic

Definition at line 541 of file atomics.h.

542{
543#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
545#endif
546 return pg_atomic_fetch_and_u64_impl(ptr, and_);
547}

References AssertPointerAlignment.

Referenced by test_atomic_uint64().

◆ pg_atomic_fetch_or_u32()

static uint32 pg_atomic_fetch_or_u32 ( volatile pg_atomic_uint32 ptr,
uint32  or_ 
)
inlinestatic

Definition at line 410 of file atomics.h.

411{
413 return pg_atomic_fetch_or_u32_impl(ptr, or_);
414}

References AssertPointerAlignment.

Referenced by EmitProcSignalBarrier(), LockBufHdr(), LWLockAcquire(), LWLockDequeueSelf(), LWLockQueueSelf(), LWLockWaitForVar(), LWLockWaitListLock(), ResetProcSignalBarrierBits(), and test_atomic_uint32().

◆ pg_atomic_fetch_or_u64()

static uint64 pg_atomic_fetch_or_u64 ( volatile pg_atomic_uint64 ptr,
uint64  or_ 
)
inlinestatic

Definition at line 550 of file atomics.h.

551{
552#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
554#endif
555 return pg_atomic_fetch_or_u64_impl(ptr, or_);
556}

References AssertPointerAlignment.

Referenced by test_atomic_uint64().

◆ pg_atomic_fetch_sub_u32()

static uint32 pg_atomic_fetch_sub_u32 ( volatile pg_atomic_uint32 ptr,
int32  sub_ 
)
inlinestatic

Definition at line 381 of file atomics.h.

382{
384 Assert(sub_ != INT_MIN);
385 return pg_atomic_fetch_sub_u32_impl(ptr, sub_);
386}
#define Assert(condition)
Definition: c.h:812

References Assert, and AssertPointerAlignment.

Referenced by LWLockAcquire(), LWLockAcquireOrWait(), LWLockDequeueSelf(), LWLockWaitForVar(), pgstat_release_entry_ref(), and test_atomic_uint32().

◆ pg_atomic_fetch_sub_u64()

static uint64 pg_atomic_fetch_sub_u64 ( volatile pg_atomic_uint64 ptr,
int64  sub_ 
)
inlinestatic

Definition at line 531 of file atomics.h.

532{
533#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
535#endif
536 Assert(sub_ != PG_INT64_MIN);
537 return pg_atomic_fetch_sub_u64_impl(ptr, sub_);
538}
#define PG_INT64_MIN
Definition: c.h:545

References Assert, AssertPointerAlignment, and PG_INT64_MIN.

Referenced by test_atomic_uint64().

◆ pg_atomic_init_flag()

static void pg_atomic_init_flag ( volatile pg_atomic_flag *  ptr)
inlinestatic

Definition at line 170 of file atomics.h.

171{
172 pg_atomic_init_flag_impl(ptr);
173}

Referenced by AutoVacuumShmemInit(), and test_atomic_flag().

◆ pg_atomic_init_u32()

◆ pg_atomic_init_u64()

static void pg_atomic_init_u64 ( volatile pg_atomic_uint64 ptr,
uint64  val 
)
inlinestatic

Definition at line 453 of file atomics.h.

454{
455 /*
456 * Can't necessarily enforce alignment - and don't need it - when using
457 * the spinlock based fallback implementation. Therefore only assert when
458 * not using it.
459 */
460#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
462#endif
464}
void pg_atomic_init_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 val_)
Definition: atomics.c:24

References AssertPointerAlignment, pg_atomic_init_u64_impl(), and val.

Referenced by InitProcGlobal(), InjectionPointShmemInit(), MarkAsPreparingGuts(), ProcSignalShmemInit(), shm_mq_create(), SimpleLruInit(), StatsShmemInit(), table_block_parallelscan_initialize(), test_atomic_uint64(), WalRcvShmemInit(), XLogPrefetchShmemInit(), and XLOGShmemInit().

◆ pg_atomic_monotonic_advance_u64()

static uint64 pg_atomic_monotonic_advance_u64 ( volatile pg_atomic_uint64 ptr,
uint64  target 
)
inlinestatic

Definition at line 585 of file atomics.h.

586{
587 uint64 currval;
588
589#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
591#endif
592
593 currval = pg_atomic_read_u64_impl(ptr);
594 if (currval >= target)
595 {
597 return currval;
598 }
599
600 while (currval < target)
601 {
602 if (pg_atomic_compare_exchange_u64(ptr, &currval, target))
603 return target;
604 }
605
606 return currval;
607}
#define pg_memory_barrier()
Definition: atomics.h:143
static bool pg_atomic_compare_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
Definition: atomics.h:512
uint64_t uint64
Definition: c.h:486
static uint64 pg_atomic_read_u64_impl(volatile pg_atomic_uint64 *ptr)
Definition: generic.h:319

References AssertPointerAlignment, pg_atomic_compare_exchange_u64(), pg_atomic_read_u64_impl(), and pg_memory_barrier.

Referenced by WaitXLogInsertionsToFinish().

◆ pg_atomic_read_membarrier_u32()

static uint32 pg_atomic_read_membarrier_u32 ( volatile pg_atomic_uint32 ptr)
inlinestatic

Definition at line 258 of file atomics.h.

259{
261
262 return pg_atomic_read_membarrier_u32_impl(ptr);
263}

References AssertPointerAlignment.

◆ pg_atomic_read_membarrier_u64()

static uint64 pg_atomic_read_membarrier_u64 ( volatile pg_atomic_uint64 ptr)
inlinestatic

Definition at line 476 of file atomics.h.

477{
478#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
480#endif
481 return pg_atomic_read_membarrier_u64_impl(ptr);
482}

References AssertPointerAlignment.

Referenced by CreateCheckPoint(), and WaitXLogInsertionsToFinish().

◆ pg_atomic_read_u32()

static uint32 pg_atomic_read_u32 ( volatile pg_atomic_uint32 ptr)
inlinestatic

Definition at line 239 of file atomics.h.

240{
242 return pg_atomic_read_u32_impl(ptr);
243}
static uint32 pg_atomic_read_u32_impl(volatile pg_atomic_uint32 *ptr)
Definition: generic.h:46

References AssertPointerAlignment, and pg_atomic_read_u32_impl().

Referenced by autovac_recalculate_workers_for_balance(), AutoVacuumUpdateCostLimit(), BufferIsDirty(), BufferIsPermanent(), BufferSync(), CleanupProcSignalState(), compute_parallel_delay(), DebugPrintBufferRefcount(), DropRelationAllLocalBuffers(), DropRelationLocalBuffers(), EmitProcSignalBarrier(), ExtendBufferedRelLocal(), FlushRelationBuffers(), GetLocalVictimBuffer(), GetVictimBuffer(), InitProcess(), InjectionPointAttach(), InjectionPointDetach(), InvalidateBuffer(), InvalidateVictimBuffer(), LocalBufferAlloc(), LWLockAttemptLock(), LWLockConflictsWithVar(), LWLockDequeueSelf(), LWLockUpdateVar(), LWLockWaitListLock(), LWLockWakeup(), MarkBufferDirty(), MarkBufferDirtyHint(), MarkLocalBufferDirty(), pa_decr_and_wait_stream_block(), parallel_vacuum_process_all_indexes(), pg_buffercache_summary(), pgstat_acquire_entry_ref(), pgstat_build_snapshot(), pgstat_drop_entry_internal(), pgstat_gc_entry_refs(), pgstat_get_entry_ref_cached(), pgstat_release_entry_ref(), pgstat_write_statsfile(), PinBuffer(), PinBuffer_Locked(), PinLocalBuffer(), ProcArrayGroupClearXid(), ProcSignalInit(), ReadRecentBuffer(), SendCancelRequest(), SendProcSignal(), StrategySyncStart(), test_atomic_uint32(), TransactionGroupUpdateXidStatus(), UnpinBufferNoOwner(), WaitBufHdrUnlocked(), WaitForProcSignalBarrier(), WaitReadBuffers(), WaitReadBuffersCanStartIO(), and ZeroAndLockBuffer().

◆ pg_atomic_read_u64()

◆ pg_atomic_sub_fetch_u32()

static uint32 pg_atomic_sub_fetch_u32 ( volatile pg_atomic_uint32 ptr,
int32  sub_ 
)
inlinestatic

◆ pg_atomic_sub_fetch_u64()

static uint64 pg_atomic_sub_fetch_u64 ( volatile pg_atomic_uint64 ptr,
int64  sub_ 
)
inlinestatic

Definition at line 568 of file atomics.h.

569{
570#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
572#endif
573 Assert(sub_ != PG_INT64_MIN);
574 return pg_atomic_sub_fetch_u64_impl(ptr, sub_);
575}

References Assert, AssertPointerAlignment, and PG_INT64_MIN.

Referenced by test_atomic_uint64().

◆ pg_atomic_test_set_flag()

static bool pg_atomic_test_set_flag ( volatile pg_atomic_flag *  ptr)
inlinestatic

Definition at line 183 of file atomics.h.

184{
185 return pg_atomic_test_set_flag_impl(ptr);
186}

Referenced by do_autovacuum(), and test_atomic_flag().

◆ pg_atomic_unlocked_test_flag()

static bool pg_atomic_unlocked_test_flag ( volatile pg_atomic_flag *  ptr)
inlinestatic

Definition at line 196 of file atomics.h.

197{
198 return pg_atomic_unlocked_test_flag_impl(ptr);
199}

Referenced by autovac_recalculate_workers_for_balance(), AutoVacuumUpdateCostLimit(), test_atomic_flag(), and VacuumUpdateCosts().

◆ pg_atomic_unlocked_write_u32()

static void pg_atomic_unlocked_write_u32 ( volatile pg_atomic_uint32 ptr,
uint32  val 
)
inlinestatic

◆ pg_atomic_write_membarrier_u32()

static void pg_atomic_write_membarrier_u32 ( volatile pg_atomic_uint32 ptr,
uint32  val 
)
inlinestatic

Definition at line 315 of file atomics.h.

316{
318
319 pg_atomic_write_membarrier_u32_impl(ptr, val);
320}

References AssertPointerAlignment, and val.

Referenced by PgArchForceDirScan().

◆ pg_atomic_write_membarrier_u64()

static void pg_atomic_write_membarrier_u64 ( volatile pg_atomic_uint64 ptr,
uint64  val 
)
inlinestatic

Definition at line 494 of file atomics.h.

495{
496#ifndef PG_HAVE_ATOMIC_U64_SIMULATION
498#endif
499 pg_atomic_write_membarrier_u64_impl(ptr, val);
500}

References AssertPointerAlignment, and val.

Referenced by StartupXLOG().

◆ pg_atomic_write_u32()

static void pg_atomic_write_u32 ( volatile pg_atomic_uint32 ptr,
uint32  val 
)
inlinestatic

◆ pg_atomic_write_u64()