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.

◆ pg_memory_barrier

#define pg_memory_barrier ( )    pg_memory_barrier_impl()

◆ pg_read_barrier

#define pg_read_barrier ( )    pg_read_barrier_impl()

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

References AssertPointerAlignment.

Referenced by tbm_prepare_shared_iterate(), and test_atomic_uint32().

398 {
399  AssertPointerAlignment(ptr, 4);
400  return pg_atomic_add_fetch_u32_impl(ptr, add_);
401 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674

◆ pg_atomic_add_fetch_u64()

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

Definition at line 515 of file atomics.h.

References AssertPointerAlignment.

Referenced by test_atomic_uint64().

516 {
517 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
518  AssertPointerAlignment(ptr, 8);
519 #endif
520  return pg_atomic_add_fetch_u64_impl(ptr, add_);
521 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674

◆ pg_atomic_clear_flag()

static void pg_atomic_clear_flag ( volatile pg_atomic_flag ptr)
inlinestatic

Definition at line 218 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_clear_flag_impl().

Referenced by wait_pid().

219 {
220  AssertPointerAlignment(ptr, sizeof(*ptr));
221 
223 }
void pg_atomic_clear_flag_impl(volatile pg_atomic_flag *ptr)
Definition: atomics.c:80
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674

◆ 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 322 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().

324 {
325  AssertPointerAlignment(ptr, 4);
326  AssertPointerAlignment(expected, 4);
327 
328  return pg_atomic_compare_exchange_u32_impl(ptr, expected, newval);
329 }
bool pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
Definition: atomics.c:120
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674
#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 467 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_compare_exchange_u64_impl().

Referenced by test_atomic_uint64().

469 {
470 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
471  AssertPointerAlignment(ptr, 8);
472  AssertPointerAlignment(expected, 8);
473 #endif
474  return pg_atomic_compare_exchange_u64_impl(ptr, expected, newval);
475 }
bool pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
Definition: atomics.c:183
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674
#define newval

◆ pg_atomic_exchange_u32()

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

Definition at line 303 of file atomics.h.

References AssertPointerAlignment.

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

304 {
305  AssertPointerAlignment(ptr, 4);
306 
307  return pg_atomic_exchange_u32_impl(ptr, newval);
308 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674
#define newval

◆ pg_atomic_exchange_u64()

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

Definition at line 458 of file atomics.h.

References AssertPointerAlignment.

Referenced by test_atomic_uint64().

459 {
460 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
461  AssertPointerAlignment(ptr, 8);
462 #endif
463  return pg_atomic_exchange_u64_impl(ptr, newval);
464 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674
#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 339 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_fetch_add_u32_impl().

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

340 {
341  AssertPointerAlignment(ptr, 4);
342  return pg_atomic_fetch_add_u32_impl(ptr, add_);
343 }
uint32 pg_atomic_fetch_add_u32_impl(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.c:148
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674

◆ pg_atomic_fetch_add_u64()

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

Definition at line 478 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_fetch_add_u64_impl().

Referenced by heap_parallelscan_nextpage(), and test_atomic_uint64().

479 {
480 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
481  AssertPointerAlignment(ptr, 8);
482 #endif
483  return pg_atomic_fetch_add_u64_impl(ptr, add_);
484 }
uint64 pg_atomic_fetch_add_u64_impl(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.c:211
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674

◆ pg_atomic_fetch_and_u32()

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

Definition at line 369 of file atomics.h.

References AssertPointerAlignment.

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

370 {
371  AssertPointerAlignment(ptr, 4);
372  return pg_atomic_fetch_and_u32_impl(ptr, and_);
373 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674

◆ pg_atomic_fetch_and_u64()

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

Definition at line 497 of file atomics.h.

References AssertPointerAlignment.

Referenced by test_atomic_uint64().

498 {
499 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
500  AssertPointerAlignment(ptr, 8);
501 #endif
502  return pg_atomic_fetch_and_u64_impl(ptr, and_);
503 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674

◆ pg_atomic_fetch_or_u32()

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

Definition at line 383 of file atomics.h.

References AssertPointerAlignment.

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

384 {
385  AssertPointerAlignment(ptr, 4);
386  return pg_atomic_fetch_or_u32_impl(ptr, or_);
387 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674

◆ pg_atomic_fetch_or_u64()

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

Definition at line 506 of file atomics.h.

References AssertPointerAlignment.

Referenced by test_atomic_uint64().

507 {
508 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
509  AssertPointerAlignment(ptr, 8);
510 #endif
511  return pg_atomic_fetch_or_u64_impl(ptr, or_);
512 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674

◆ pg_atomic_fetch_sub_u32()

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

Definition at line 354 of file atomics.h.

References Assert, and AssertPointerAlignment.

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

355 {
356  AssertPointerAlignment(ptr, 4);
357  Assert(sub_ != INT_MIN);
358  return pg_atomic_fetch_sub_u32_impl(ptr, sub_);
359 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674
#define Assert(condition)
Definition: c.h:670

◆ pg_atomic_fetch_sub_u64()

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

Definition at line 487 of file atomics.h.

References Assert, AssertPointerAlignment, and PG_INT64_MIN.

Referenced by test_atomic_uint64().

488 {
489 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
490  AssertPointerAlignment(ptr, 8);
491 #endif
492  Assert(sub_ != PG_INT64_MIN);
493  return pg_atomic_fetch_sub_u64_impl(ptr, sub_);
494 }
#define PG_INT64_MIN
Definition: c.h:381
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674
#define Assert(condition)
Definition: c.h:670

◆ 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 AssertPointerAlignment, and pg_atomic_init_flag_impl().

Referenced by wait_pid().

176 {
177  AssertPointerAlignment(ptr, sizeof(*ptr));
178 
180 }
void pg_atomic_init_flag_impl(volatile pg_atomic_flag *ptr)
Definition: atomics.c:55
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674

◆ pg_atomic_init_u32()

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

Definition at line 234 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_init_u32_impl().

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

235 {
236  AssertPointerAlignment(ptr, 4);
237 
239 }
void pg_atomic_init_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 val_)
Definition: atomics.c:89
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674
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 426 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_init_u64_impl().

Referenced by heap_parallelscan_initialize(), and test_atomic_uint64().

427 {
428  /*
429  * Can't necessarily enforce alignment - and don't need it - when using
430  * the spinlock based fallback implementation. Therefore only assert when
431  * not using it.
432  */
433 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
434  AssertPointerAlignment(ptr, 8);
435 #endif
437 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674
void pg_atomic_init_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 val_)
Definition: atomics.c:165
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 440 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_read_u64_impl().

Referenced by test_atomic_uint64().

441 {
442 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
443  AssertPointerAlignment(ptr, 8);
444 #endif
445  return pg_atomic_read_u64_impl(ptr);
446 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674
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 412 of file atomics.h.

References Assert, and AssertPointerAlignment.

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

413 {
414  AssertPointerAlignment(ptr, 4);
415  Assert(sub_ != INT_MIN);
416  return pg_atomic_sub_fetch_u32_impl(ptr, sub_);
417 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674
#define Assert(condition)
Definition: c.h:670

◆ pg_atomic_sub_fetch_u64()

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

Definition at line 524 of file atomics.h.

References Assert, AssertPointerAlignment, and PG_INT64_MIN.

Referenced by test_atomic_uint64().

525 {
526 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
527  AssertPointerAlignment(ptr, 8);
528 #endif
529  Assert(sub_ != PG_INT64_MIN);
530  return pg_atomic_sub_fetch_u64_impl(ptr, sub_);
531 }
#define PG_INT64_MIN
Definition: c.h:381
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674
#define Assert(condition)
Definition: c.h:670

◆ pg_atomic_test_set_flag()

static bool pg_atomic_test_set_flag ( volatile pg_atomic_flag ptr)
inlinestatic

Definition at line 190 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_test_set_flag_impl().

Referenced by wait_pid().

191 {
192  AssertPointerAlignment(ptr, sizeof(*ptr));
193 
194  return pg_atomic_test_set_flag_impl(ptr);
195 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674
bool pg_atomic_test_set_flag_impl(volatile pg_atomic_flag *ptr)
Definition: atomics.c:74

◆ pg_atomic_unlocked_test_flag()

static bool pg_atomic_unlocked_test_flag ( volatile pg_atomic_flag ptr)
inlinestatic

Definition at line 205 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_unlocked_test_flag_impl().

Referenced by wait_pid().

206 {
207  AssertPointerAlignment(ptr, sizeof(*ptr));
208 
210 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674
static bool pg_atomic_unlocked_test_flag_impl(volatile pg_atomic_flag *ptr)
Definition: fallback.h:136

◆ pg_atomic_unlocked_write_u32()

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

Definition at line 288 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_unlocked_write_u32_impl().

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

289 {
290  AssertPointerAlignment(ptr, 4);
291 
293 }
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:674
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 269 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_write_u32_impl().

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

270 {
271  AssertPointerAlignment(ptr, 4);
272 
274 }
void pg_atomic_write_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.c:107
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674
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 449 of file atomics.h.

References AssertPointerAlignment, and pg_atomic_write_u64_impl().

Referenced by heap_parallelscan_reinitialize(), and test_atomic_uint64().

450 {
451 #ifndef PG_HAVE_ATOMIC_U64_SIMULATION
452  AssertPointerAlignment(ptr, 8);
453 #endif
455 }
#define AssertPointerAlignment(ptr, bndr)
Definition: c.h:674
static void pg_atomic_write_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: generic.h:280
long val
Definition: informix.c:689