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 133 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 164 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 386 of file atomics.h.

References AssertPointerAlignment.

Referenced by tbm_prepare_shared_iterate(), and test_atomic_uint32().

387 {
388  AssertPointerAlignment(ptr, 4);
389  return pg_atomic_add_fetch_u32_impl(ptr, add_);
390 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743

◆ pg_atomic_add_fetch_u64()

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

Definition at line 504 of file atomics.h.

References AssertPointerAlignment.

Referenced by test_atomic_uint64().

505 {
506 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
507  AssertPointerAlignment(ptr, 8);
508 #endif
509  return pg_atomic_add_fetch_u64_impl(ptr, add_);
510 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743

◆ pg_atomic_clear_flag()

static void pg_atomic_clear_flag ( volatile pg_atomic_flag ptr)
inlinestatic

Definition at line 209 of file atomics.h.

References pg_atomic_clear_flag_impl().

Referenced by test_atomic_flag().

210 {
212 }
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 311 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().

313 {
314  AssertPointerAlignment(ptr, 4);
315  AssertPointerAlignment(expected, 4);
316 
317  return pg_atomic_compare_exchange_u32_impl(ptr, expected, newval);
318 }
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:743
#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 456 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_compare_exchange_u64_impl().

Referenced by test_atomic_uint64().

458 {
459 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
460  AssertPointerAlignment(ptr, 8);
461  AssertPointerAlignment(expected, 8);
462 #endif
463  return pg_atomic_compare_exchange_u64_impl(ptr, expected, newval);
464 }
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:743
#define newval

◆ pg_atomic_exchange_u32()

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

Definition at line 292 of file atomics.h.

References AssertPointerAlignment.

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

293 {
294  AssertPointerAlignment(ptr, 4);
295 
296  return pg_atomic_exchange_u32_impl(ptr, newval);
297 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743
#define newval

◆ pg_atomic_exchange_u64()

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

Definition at line 447 of file atomics.h.

References AssertPointerAlignment.

Referenced by test_atomic_uint64().

448 {
449 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
450  AssertPointerAlignment(ptr, 8);
451 #endif
452  return pg_atomic_exchange_u64_impl(ptr, newval);
453 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743
#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 328 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().

329 {
330  AssertPointerAlignment(ptr, 4);
331  return pg_atomic_fetch_add_u32_impl(ptr, add_);
332 }
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:743

◆ pg_atomic_fetch_add_u64()

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

Definition at line 467 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_fetch_add_u64_impl().

Referenced by table_block_parallelscan_nextpage(), and test_atomic_uint64().

468 {
469 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
470  AssertPointerAlignment(ptr, 8);
471 #endif
472  return pg_atomic_fetch_add_u64_impl(ptr, add_);
473 }
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:743

◆ pg_atomic_fetch_and_u32()

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

Definition at line 358 of file atomics.h.

References AssertPointerAlignment.

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

359 {
360  AssertPointerAlignment(ptr, 4);
361  return pg_atomic_fetch_and_u32_impl(ptr, and_);
362 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743

◆ pg_atomic_fetch_and_u64()

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

Definition at line 486 of file atomics.h.

References AssertPointerAlignment.

Referenced by test_atomic_uint64().

487 {
488 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
489  AssertPointerAlignment(ptr, 8);
490 #endif
491  return pg_atomic_fetch_and_u64_impl(ptr, and_);
492 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743

◆ pg_atomic_fetch_or_u32()

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

Definition at line 372 of file atomics.h.

References AssertPointerAlignment.

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

373 {
374  AssertPointerAlignment(ptr, 4);
375  return pg_atomic_fetch_or_u32_impl(ptr, or_);
376 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743

◆ pg_atomic_fetch_or_u64()

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

Definition at line 495 of file atomics.h.

References AssertPointerAlignment.

Referenced by test_atomic_uint64().

496 {
497 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
498  AssertPointerAlignment(ptr, 8);
499 #endif
500  return pg_atomic_fetch_or_u64_impl(ptr, or_);
501 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743

◆ pg_atomic_fetch_sub_u32()

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

Definition at line 343 of file atomics.h.

References Assert, and AssertPointerAlignment.

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

344 {
345  AssertPointerAlignment(ptr, 4);
346  Assert(sub_ != INT_MIN);
347  return pg_atomic_fetch_sub_u32_impl(ptr, sub_);
348 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743
#define Assert(condition)
Definition: c.h:739

◆ pg_atomic_fetch_sub_u64()

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

Definition at line 476 of file atomics.h.

References Assert, AssertPointerAlignment, and PG_INT64_MIN.

Referenced by test_atomic_uint64().

477 {
478 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
479  AssertPointerAlignment(ptr, 8);
480 #endif
481  Assert(sub_ != PG_INT64_MIN);
482  return pg_atomic_fetch_sub_u64_impl(ptr, sub_);
483 }
#define PG_INT64_MIN
Definition: c.h:444
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743
#define Assert(condition)
Definition: c.h:739

◆ pg_atomic_init_flag()

static void pg_atomic_init_flag ( volatile pg_atomic_flag ptr)
inlinestatic

Definition at line 172 of file atomics.h.

References pg_atomic_init_flag_impl().

Referenced by test_atomic_flag().

173 {
175 }
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 223 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().

224 {
225  AssertPointerAlignment(ptr, 4);
226 
228 }
void pg_atomic_init_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 val_)
Definition: atomics.c:106
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743
long val
Definition: informix.c:664

◆ pg_atomic_init_u64()

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

Definition at line 415 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_init_u64_impl().

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

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

◆ pg_atomic_read_u32()

◆ pg_atomic_read_u64()

static uint64 pg_atomic_read_u64 ( volatile pg_atomic_uint64 ptr)
inlinestatic

Definition at line 429 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().

430 {
431 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
432  AssertPointerAlignment(ptr, 8);
433 #endif
434  return pg_atomic_read_u64_impl(ptr);
435 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743
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 401 of file atomics.h.

References Assert, and AssertPointerAlignment.

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

402 {
403  AssertPointerAlignment(ptr, 4);
404  Assert(sub_ != INT_MIN);
405  return pg_atomic_sub_fetch_u32_impl(ptr, sub_);
406 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743
#define Assert(condition)
Definition: c.h:739

◆ pg_atomic_sub_fetch_u64()

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

Definition at line 513 of file atomics.h.

References Assert, AssertPointerAlignment, and PG_INT64_MIN.

Referenced by test_atomic_uint64().

514 {
515 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
516  AssertPointerAlignment(ptr, 8);
517 #endif
518  Assert(sub_ != PG_INT64_MIN);
519  return pg_atomic_sub_fetch_u64_impl(ptr, sub_);
520 }
#define PG_INT64_MIN
Definition: c.h:444
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743
#define Assert(condition)
Definition: c.h:739

◆ pg_atomic_test_set_flag()

static bool pg_atomic_test_set_flag ( volatile pg_atomic_flag ptr)
inlinestatic

Definition at line 185 of file atomics.h.

References pg_atomic_test_set_flag_impl().

Referenced by test_atomic_flag().

186 {
187  return pg_atomic_test_set_flag_impl(ptr);
188 }
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 198 of file atomics.h.

References pg_atomic_unlocked_test_flag_impl().

Referenced by test_atomic_flag().

199 {
201 }
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 277 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_unlocked_write_u32_impl().

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

278 {
279  AssertPointerAlignment(ptr, 4);
280 
282 }
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:743
long val
Definition: informix.c:664

◆ pg_atomic_write_u32()

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

Definition at line 258 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_write_u32_impl().

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

259 {
260  AssertPointerAlignment(ptr, 4);
261 
263 }
void pg_atomic_write_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.c:124
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743
long val
Definition: informix.c:664

◆ pg_atomic_write_u64()

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

Definition at line 438 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_write_u64_impl().

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

439 {
440 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
441  AssertPointerAlignment(ptr, 8);
442 #endif
444 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:743
static void pg_atomic_write_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: generic.h:280
long val
Definition: informix.c:664