PostgreSQL Source Code  git master
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 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 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 void pg_atomic_write_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_)
 

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 128 of file atomics.h.

◆ pg_memory_barrier

#define pg_memory_barrier ( )    pg_memory_barrier_impl()

Definition at line 140 of file atomics.h.

◆ pg_read_barrier

#define pg_read_barrier ( )    pg_read_barrier_impl()

Definition at line 153 of file atomics.h.

◆ pg_spin_delay

#define pg_spin_delay ( )    pg_spin_delay_impl()

Definition at line 159 of file atomics.h.

◆ pg_write_barrier

#define pg_write_barrier ( )    pg_write_barrier_impl()

Definition at line 154 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 381 of file atomics.h.

382 {
383  AssertPointerAlignment(ptr, 4);
384  return pg_atomic_add_fetch_u32_impl(ptr, add_);
385 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:830

References AssertPointerAlignment.

Referenced by 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 499 of file atomics.h.

500 {
501 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
502  AssertPointerAlignment(ptr, 8);
503 #endif
504  return pg_atomic_add_fetch_u64_impl(ptr, add_);
505 }

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 204 of file atomics.h.

205 {
207 }
void pg_atomic_clear_flag_impl(volatile pg_atomic_flag *ptr)
Definition: atomics.c:89

References pg_atomic_clear_flag_impl().

Referenced by 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 306 of file atomics.h.

308 {
309  AssertPointerAlignment(ptr, 4);
310  AssertPointerAlignment(expected, 4);
311 
312  return pg_atomic_compare_exchange_u32_impl(ptr, expected, newval);
313 }
bool pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
Definition: atomics.c:137
#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 UnpinBuffer().

◆ 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 451 of file atomics.h.

453 {
454 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
455  AssertPointerAlignment(ptr, 8);
456  AssertPointerAlignment(expected, 8);
457 #endif
458  return pg_atomic_compare_exchange_u64_impl(ptr, expected, newval);
459 }
bool pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
Definition: atomics.c:200

References AssertPointerAlignment, newval, and pg_atomic_compare_exchange_u64_impl().

Referenced by test_atomic_uint64().

◆ pg_atomic_exchange_u32()

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

Definition at line 287 of file atomics.h.

288 {
289  AssertPointerAlignment(ptr, 4);
290 
291  return pg_atomic_exchange_u32_impl(ptr, newval);
292 }

References AssertPointerAlignment, and newval.

Referenced by 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 442 of file atomics.h.

443 {
444 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
445  AssertPointerAlignment(ptr, 8);
446 #endif
447  return pg_atomic_exchange_u64_impl(ptr, newval);
448 }

References AssertPointerAlignment, and newval.

Referenced by 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 462 of file atomics.h.

463 {
464 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
465  AssertPointerAlignment(ptr, 8);
466 #endif
467  return pg_atomic_fetch_add_u64_impl(ptr, add_);
468 }
uint64 pg_atomic_fetch_add_u64_impl(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.c:228

References AssertPointerAlignment, and pg_atomic_fetch_add_u64_impl().

Referenced by pgstat_request_entry_refs_gc(), table_block_parallelscan_nextpage(), test_atomic_spin_nest(), 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 353 of file atomics.h.

354 {
355  AssertPointerAlignment(ptr, 4);
356  return pg_atomic_fetch_and_u32_impl(ptr, and_);
357 }

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 481 of file atomics.h.

482 {
483 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
484  AssertPointerAlignment(ptr, 8);
485 #endif
486  return pg_atomic_fetch_and_u64_impl(ptr, and_);
487 }

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 367 of file atomics.h.

368 {
369  AssertPointerAlignment(ptr, 4);
370  return pg_atomic_fetch_or_u32_impl(ptr, or_);
371 }

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 490 of file atomics.h.

491 {
492 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
493  AssertPointerAlignment(ptr, 8);
494 #endif
495  return pg_atomic_fetch_or_u64_impl(ptr, or_);
496 }

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 338 of file atomics.h.

339 {
340  AssertPointerAlignment(ptr, 4);
341  Assert(sub_ != INT_MIN);
342  return pg_atomic_fetch_sub_u32_impl(ptr, sub_);
343 }
Assert(fmt[strlen(fmt) - 1] !='\n')

References Assert(), and AssertPointerAlignment.

Referenced by LWLockAcquire(), LWLockAcquireOrWait(), LWLockDequeueSelf(), LWLockWaitForVar(), pgstat_release_entry_ref(), test_atomic_spin_nest(), 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 471 of file atomics.h.

472 {
473 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
474  AssertPointerAlignment(ptr, 8);
475 #endif
476  Assert(sub_ != PG_INT64_MIN);
477  return pg_atomic_fetch_sub_u64_impl(ptr, sub_);
478 }
#define PG_INT64_MIN
Definition: c.h:527

References Assert(), AssertPointerAlignment, and PG_INT64_MIN.

Referenced by test_atomic_spin_nest(), and test_atomic_uint64().

◆ pg_atomic_init_flag()

static void pg_atomic_init_flag ( volatile pg_atomic_flag ptr)
inlinestatic

Definition at line 167 of file atomics.h.

168 {
170 }
void pg_atomic_init_flag_impl(volatile pg_atomic_flag *ptr)
Definition: atomics.c:55

References pg_atomic_init_flag_impl().

Referenced by test_atomic_flag().

◆ pg_atomic_init_u32()

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

◆ pg_atomic_init_u64()

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

Definition at line 410 of file atomics.h.

411 {
412  /*
413  * Can't necessarily enforce alignment - and don't need it - when using
414  * the spinlock based fallback implementation. Therefore only assert when
415  * not using it.
416  */
417 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
418  AssertPointerAlignment(ptr, 8);
419 #endif
421 }
void pg_atomic_init_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 val_)
Definition: atomics.c:182

References AssertPointerAlignment, pg_atomic_init_u64_impl(), and val.

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

◆ pg_atomic_read_u32()

◆ pg_atomic_read_u64()

◆ pg_atomic_sub_fetch_u32()

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

Definition at line 396 of file atomics.h.

397 {
398  AssertPointerAlignment(ptr, 4);
399  Assert(sub_ != INT_MIN);
400  return pg_atomic_sub_fetch_u32_impl(ptr, sub_);
401 }

References Assert(), and AssertPointerAlignment.

Referenced by compute_parallel_delay(), LWLockRelease(), parallel_vacuum_process_safe_indexes(), parallel_vacuum_process_unsafe_indexes(), pgstat_drop_entry_internal(), tbm_free_shared_area(), and test_atomic_uint32().

◆ pg_atomic_sub_fetch_u64()

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

Definition at line 508 of file atomics.h.

509 {
510 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
511  AssertPointerAlignment(ptr, 8);
512 #endif
513  Assert(sub_ != PG_INT64_MIN);
514  return pg_atomic_sub_fetch_u64_impl(ptr, sub_);
515 }

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 180 of file atomics.h.

181 {
182  return pg_atomic_test_set_flag_impl(ptr);
183 }
bool pg_atomic_test_set_flag_impl(volatile pg_atomic_flag *ptr)
Definition: atomics.c:76

References pg_atomic_test_set_flag_impl().

Referenced by test_atomic_flag().

◆ pg_atomic_unlocked_test_flag()

static bool pg_atomic_unlocked_test_flag ( volatile pg_atomic_flag ptr)
inlinestatic

Definition at line 193 of file atomics.h.

194 {
196 }
bool pg_atomic_unlocked_test_flag_impl(volatile pg_atomic_flag *ptr)
Definition: atomics.c:97

References pg_atomic_unlocked_test_flag_impl().

Referenced by test_atomic_flag().

◆ pg_atomic_unlocked_write_u32()

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

Definition at line 272 of file atomics.h.

273 {
274  AssertPointerAlignment(ptr, 4);
275 
277 }
static void pg_atomic_unlocked_write_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: generic.h:64

References AssertPointerAlignment, pg_atomic_unlocked_write_u32_impl(), and val.

Referenced by DropRelationAllLocalBuffers(), DropRelationLocalBuffers(), FlushRelationBuffers(), LocalBufferAlloc(), MarkLocalBufferDirty(), ReadBuffer_common(), and ReadRecentBuffer().

◆ pg_atomic_write_u32()

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

Definition at line 253 of file atomics.h.

254 {
255  AssertPointerAlignment(ptr, 4);
256 
258 }
void pg_atomic_write_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.c:124

References AssertPointerAlignment, pg_atomic_write_u32_impl(), and val.

Referenced by parallel_vacuum_process_all_indexes(), ProcArrayGroupClearXid(), ProcSignalInit(), test_atomic_uint32(), TransactionGroupUpdateXidStatus(), and UnlockBufHdr().

◆ pg_atomic_write_u64()

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