PostgreSQL Source Code  git master
fallback.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pg_atomic_uint64
 

Macros

#define PG_HAVE_ATOMIC_U64_SIMULATION
 
#define PG_HAVE_ATOMIC_U64_SUPPORT
 
#define PG_HAVE_ATOMIC_INIT_U64
 
#define PG_HAVE_ATOMIC_COMPARE_EXCHANGE_U64
 
#define PG_HAVE_ATOMIC_FETCH_ADD_U64
 

Typedefs

typedef struct pg_atomic_uint64 pg_atomic_uint64
 

Functions

void pg_atomic_init_u64_impl (volatile pg_atomic_uint64 *ptr, uint64 val_)
 
bool pg_atomic_compare_exchange_u64_impl (volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
 
uint64 pg_atomic_fetch_add_u64_impl (volatile pg_atomic_uint64 *ptr, int64 add_)
 

Macro Definition Documentation

◆ PG_HAVE_ATOMIC_COMPARE_EXCHANGE_U64

#define PG_HAVE_ATOMIC_COMPARE_EXCHANGE_U64

Definition at line 35 of file fallback.h.

◆ PG_HAVE_ATOMIC_FETCH_ADD_U64

#define PG_HAVE_ATOMIC_FETCH_ADD_U64

Definition at line 39 of file fallback.h.

◆ PG_HAVE_ATOMIC_INIT_U64

#define PG_HAVE_ATOMIC_INIT_U64

Definition at line 32 of file fallback.h.

◆ PG_HAVE_ATOMIC_U64_SIMULATION

#define PG_HAVE_ATOMIC_U64_SIMULATION

Definition at line 23 of file fallback.h.

◆ PG_HAVE_ATOMIC_U64_SUPPORT

#define PG_HAVE_ATOMIC_U64_SUPPORT

Definition at line 25 of file fallback.h.

Typedef Documentation

◆ pg_atomic_uint64

Function Documentation

◆ pg_atomic_compare_exchange_u64_impl()

bool pg_atomic_compare_exchange_u64_impl ( volatile pg_atomic_uint64 ptr,
uint64 *  expected,
uint64  newval 
)

Definition at line 34 of file atomics.c.

36 {
37  bool ret;
38 
39  /*
40  * Do atomic op under a spinlock. It might look like we could just skip
41  * the cmpxchg if the lock isn't available, but that'd just emulate a
42  * 'weak' compare and swap. I.e. one that allows spurious failures. Since
43  * several algorithms rely on a strong variant and that is efficiently
44  * implementable on most major architectures let's emulate it here as
45  * well.
46  */
47  SpinLockAcquire((slock_t *) &ptr->sema);
48 
49  /* perform compare/exchange logic */
50  ret = ptr->value == *expected;
51  *expected = ptr->value;
52  if (ret)
53  ptr->value = newval;
54 
55  /* and release lock */
56  SpinLockRelease((slock_t *) &ptr->sema);
57 
58  return ret;
59 }
#define newval
#define SpinLockRelease(lock)
Definition: spin.h:61
#define SpinLockAcquire(lock)
Definition: spin.h:59

References newval, pg_atomic_uint64::sema, SpinLockAcquire, SpinLockRelease, and pg_atomic_uint64::value.

Referenced by pg_atomic_compare_exchange_u64(), and pg_atomic_read_u64_impl().

◆ pg_atomic_fetch_add_u64_impl()

uint64 pg_atomic_fetch_add_u64_impl ( volatile pg_atomic_uint64 ptr,
int64  add_ 
)

Definition at line 62 of file atomics.c.

63 {
64  uint64 oldval;
65 
66  SpinLockAcquire((slock_t *) &ptr->sema);
67  oldval = ptr->value;
68  ptr->value += add_;
69  SpinLockRelease((slock_t *) &ptr->sema);
70  return oldval;
71 }

References pg_atomic_uint64::sema, SpinLockAcquire, SpinLockRelease, and pg_atomic_uint64::value.

Referenced by pg_atomic_fetch_add_u64().

◆ pg_atomic_init_u64_impl()

void pg_atomic_init_u64_impl ( volatile pg_atomic_uint64 ptr,
uint64  val_ 
)

Definition at line 24 of file atomics.c.

25 {
26  StaticAssertDecl(sizeof(ptr->sema) >= sizeof(slock_t),
27  "size mismatch of atomic_uint64 vs slock_t");
28 
29  SpinLockInit((slock_t *) &ptr->sema);
30  ptr->value = val_;
31 }
#define StaticAssertDecl(condition, errmessage)
Definition: c.h:939
#define SpinLockInit(lock)
Definition: spin.h:57

References pg_atomic_uint64::sema, SpinLockInit, StaticAssertDecl, and pg_atomic_uint64::value.

Referenced by pg_atomic_init_u64().