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

Referenced by shm_mq_send_bytes().

◆ pg_memory_barrier

◆ pg_read_barrier

◆ pg_spin_delay

#define pg_spin_delay ( )    pg_spin_delay_impl()

Definition at line 167 of file atomics.h.

◆ pg_write_barrier

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

References AssertPointerAlignment.

Referenced by tbm_prepare_shared_iterate(), and test_atomic_uint32().

390 {
391  AssertPointerAlignment(ptr, 4);
392  return pg_atomic_add_fetch_u32_impl(ptr, add_);
393 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736

◆ pg_atomic_add_fetch_u64()

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

Definition at line 507 of file atomics.h.

References AssertPointerAlignment.

Referenced by test_atomic_uint64().

508 {
509 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
510  AssertPointerAlignment(ptr, 8);
511 #endif
512  return pg_atomic_add_fetch_u64_impl(ptr, add_);
513 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736

◆ pg_atomic_clear_flag()

static void pg_atomic_clear_flag ( volatile pg_atomic_flag ptr)
inlinestatic

Definition at line 212 of file atomics.h.

References pg_atomic_clear_flag_impl().

Referenced by test_atomic_flag().

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

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

References AssertPointerAlignment, and pg_atomic_compare_exchange_u32_impl().

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

316 {
317  AssertPointerAlignment(ptr, 4);
318  AssertPointerAlignment(expected, 4);
319 
320  return pg_atomic_compare_exchange_u32_impl(ptr, expected, newval);
321 }
bool pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
Definition: atomics.c:137
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736
#define newval

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

References AssertPointerAlignment, and pg_atomic_compare_exchange_u64_impl().

Referenced by test_atomic_uint64().

461 {
462 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
463  AssertPointerAlignment(ptr, 8);
464  AssertPointerAlignment(expected, 8);
465 #endif
466  return pg_atomic_compare_exchange_u64_impl(ptr, expected, newval);
467 }
bool pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
Definition: atomics.c:200
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736
#define newval

◆ pg_atomic_exchange_u32()

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

Definition at line 295 of file atomics.h.

References AssertPointerAlignment.

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

296 {
297  AssertPointerAlignment(ptr, 4);
298 
299  return pg_atomic_exchange_u32_impl(ptr, newval);
300 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736
#define newval

◆ pg_atomic_exchange_u64()

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

Definition at line 450 of file atomics.h.

References AssertPointerAlignment.

Referenced by test_atomic_uint64().

451 {
452 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
453  AssertPointerAlignment(ptr, 8);
454 #endif
455  return pg_atomic_exchange_u64_impl(ptr, newval);
456 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736
#define newval

◆ pg_atomic_fetch_add_u32()

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

Definition at line 331 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_fetch_add_u32_impl().

Referenced by ClockSweepTick(), ExecParallelHashJoinNewBatch(), find_or_make_matching_shared_tupledesc(), LWLockQueueSelf(), StrategyGetBuffer(), and test_atomic_uint32().

332 {
333  AssertPointerAlignment(ptr, 4);
334  return pg_atomic_fetch_add_u32_impl(ptr, add_);
335 }
uint32 pg_atomic_fetch_add_u32_impl(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.c:165
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736

◆ pg_atomic_fetch_add_u64()

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

Definition at line 470 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_fetch_add_u64_impl().

Referenced by heap_parallelscan_nextpage(), and test_atomic_uint64().

471 {
472 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
473  AssertPointerAlignment(ptr, 8);
474 #endif
475  return pg_atomic_fetch_add_u64_impl(ptr, add_);
476 }
uint64 pg_atomic_fetch_add_u64_impl(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.c:228
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736

◆ pg_atomic_fetch_and_u32()

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

Definition at line 361 of file atomics.h.

References AssertPointerAlignment.

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

362 {
363  AssertPointerAlignment(ptr, 4);
364  return pg_atomic_fetch_and_u32_impl(ptr, and_);
365 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736

◆ pg_atomic_fetch_and_u64()

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

Definition at line 489 of file atomics.h.

References AssertPointerAlignment.

Referenced by test_atomic_uint64().

490 {
491 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
492  AssertPointerAlignment(ptr, 8);
493 #endif
494  return pg_atomic_fetch_and_u64_impl(ptr, and_);
495 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736

◆ pg_atomic_fetch_or_u32()

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

Definition at line 375 of file atomics.h.

References AssertPointerAlignment.

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

376 {
377  AssertPointerAlignment(ptr, 4);
378  return pg_atomic_fetch_or_u32_impl(ptr, or_);
379 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736

◆ pg_atomic_fetch_or_u64()

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

Definition at line 498 of file atomics.h.

References AssertPointerAlignment.

Referenced by test_atomic_uint64().

499 {
500 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
501  AssertPointerAlignment(ptr, 8);
502 #endif
503  return pg_atomic_fetch_or_u64_impl(ptr, or_);
504 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736

◆ pg_atomic_fetch_sub_u32()

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

Definition at line 346 of file atomics.h.

References Assert, and AssertPointerAlignment.

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

347 {
348  AssertPointerAlignment(ptr, 4);
349  Assert(sub_ != INT_MIN);
350  return pg_atomic_fetch_sub_u32_impl(ptr, sub_);
351 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736
#define Assert(condition)
Definition: c.h:732

◆ pg_atomic_fetch_sub_u64()

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

Definition at line 479 of file atomics.h.

References Assert, AssertPointerAlignment, and PG_INT64_MIN.

Referenced by test_atomic_uint64().

480 {
481 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
482  AssertPointerAlignment(ptr, 8);
483 #endif
484  Assert(sub_ != PG_INT64_MIN);
485  return pg_atomic_fetch_sub_u64_impl(ptr, sub_);
486 }
#define PG_INT64_MIN
Definition: c.h:443
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736
#define Assert(condition)
Definition: c.h:732

◆ pg_atomic_init_flag()

static void pg_atomic_init_flag ( volatile pg_atomic_flag ptr)
inlinestatic

Definition at line 175 of file atomics.h.

References pg_atomic_init_flag_impl().

Referenced by test_atomic_flag().

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

◆ pg_atomic_init_u32()

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

Definition at line 226 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_init_u32_impl().

Referenced by ExecHashJoinInitializeDSM(), InitBufferPool(), InitProcGlobal(), LWLockInitialize(), SharedRecordTypmodRegistryInit(), StrategyInitialize(), tbm_prepare_shared_iterate(), and test_atomic_uint32().

227 {
228  AssertPointerAlignment(ptr, 4);
229 
231 }
void pg_atomic_init_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 val_)
Definition: atomics.c:106
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736
long val
Definition: informix.c:689

◆ pg_atomic_init_u64()

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

Definition at line 418 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_init_u64_impl().

Referenced by heap_parallelscan_initialize(), shm_mq_create(), and test_atomic_uint64().

419 {
420  /*
421  * Can't necessarily enforce alignment - and don't need it - when using
422  * the spinlock based fallback implementation. Therefore only assert when
423  * not using it.
424  */
425 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
426  AssertPointerAlignment(ptr, 8);
427 #endif
429 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736
void pg_atomic_init_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 val_)
Definition: atomics.c:182
long val
Definition: informix.c:689

◆ pg_atomic_read_u32()

◆ pg_atomic_read_u64()

static uint64 pg_atomic_read_u64 ( volatile pg_atomic_uint64 ptr)
inlinestatic

Definition at line 432 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_read_u64_impl().

Referenced by shm_mq_inc_bytes_read(), shm_mq_inc_bytes_written(), shm_mq_receive_bytes(), shm_mq_send_bytes(), and test_atomic_uint64().

433 {
434 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
435  AssertPointerAlignment(ptr, 8);
436 #endif
437  return pg_atomic_read_u64_impl(ptr);
438 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736
static uint64 pg_atomic_read_u64_impl(volatile pg_atomic_uint64 *ptr)
Definition: generic.h:311

◆ pg_atomic_sub_fetch_u32()

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

Definition at line 404 of file atomics.h.

References Assert, and AssertPointerAlignment.

Referenced by LWLockRelease(), tbm_free_shared_area(), and test_atomic_uint32().

405 {
406  AssertPointerAlignment(ptr, 4);
407  Assert(sub_ != INT_MIN);
408  return pg_atomic_sub_fetch_u32_impl(ptr, sub_);
409 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736
#define Assert(condition)
Definition: c.h:732

◆ pg_atomic_sub_fetch_u64()

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

Definition at line 516 of file atomics.h.

References Assert, AssertPointerAlignment, and PG_INT64_MIN.

Referenced by test_atomic_uint64().

517 {
518 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
519  AssertPointerAlignment(ptr, 8);
520 #endif
521  Assert(sub_ != PG_INT64_MIN);
522  return pg_atomic_sub_fetch_u64_impl(ptr, sub_);
523 }
#define PG_INT64_MIN
Definition: c.h:443
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736
#define Assert(condition)
Definition: c.h:732

◆ pg_atomic_test_set_flag()

static bool pg_atomic_test_set_flag ( volatile pg_atomic_flag ptr)
inlinestatic

Definition at line 188 of file atomics.h.

References pg_atomic_test_set_flag_impl().

Referenced by test_atomic_flag().

189 {
190  return pg_atomic_test_set_flag_impl(ptr);
191 }
bool pg_atomic_test_set_flag_impl(volatile pg_atomic_flag *ptr)
Definition: atomics.c:76

◆ pg_atomic_unlocked_test_flag()

static bool pg_atomic_unlocked_test_flag ( volatile pg_atomic_flag ptr)
inlinestatic

Definition at line 201 of file atomics.h.

References pg_atomic_unlocked_test_flag_impl().

Referenced by test_atomic_flag().

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

◆ pg_atomic_unlocked_write_u32()

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

Definition at line 280 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_unlocked_write_u32_impl().

Referenced by DropRelFileNodeAllLocalBuffers(), DropRelFileNodeLocalBuffers(), FlushRelationBuffers(), LocalBufferAlloc(), MarkLocalBufferDirty(), and ReadBuffer_common().

281 {
282  AssertPointerAlignment(ptr, 4);
283 
285 }
static void pg_atomic_unlocked_write_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: generic.h:64
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736
long val
Definition: informix.c:689

◆ pg_atomic_write_u32()

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

Definition at line 261 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_write_u32_impl().

Referenced by ProcArrayGroupClearXid(), test_atomic_uint32(), and TransactionGroupUpdateXidStatus().

262 {
263  AssertPointerAlignment(ptr, 4);
264 
266 }
void pg_atomic_write_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.c:124
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736
long val
Definition: informix.c:689

◆ pg_atomic_write_u64()

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

Definition at line 441 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_write_u64_impl().

Referenced by heap_parallelscan_reinitialize(), shm_mq_inc_bytes_read(), shm_mq_inc_bytes_written(), and test_atomic_uint64().

442 {
443 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
444  AssertPointerAlignment(ptr, 8);
445 #endif
447 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:736
static void pg_atomic_write_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: generic.h:280
long val
Definition: informix.c:689