PostgreSQL Source Code git master
Loading...
Searching...
No Matches
spin.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * spin.h
4 * API for spinlocks.
5 *
6 *
7 * The interface to spinlocks is defined by the typedef "slock_t" and
8 * these functions:
9 *
10 * void SpinLockInit(volatile slock_t *lock)
11 * Initialize a spinlock (to the unlocked state).
12 *
13 * void SpinLockAcquire(volatile slock_t *lock)
14 * Acquire a spinlock, waiting if necessary.
15 * Time out and abort() if unable to acquire the lock in a
16 * "reasonable" amount of time --- typically ~ 1 minute.
17 *
18 * void SpinLockRelease(volatile slock_t *lock)
19 * Unlock a previously acquired lock.
20 *
21 * Load and store operations in calling code are guaranteed not to be
22 * reordered with respect to these operations, because they include a
23 * compiler barrier. (Before PostgreSQL 9.5, callers needed to use a
24 * volatile qualifier to access data protected by spinlocks.)
25 *
26 * Keep in mind the coding rule that spinlocks must not be held for more
27 * than a few instructions. In particular, we assume it is not possible
28 * for a CHECK_FOR_INTERRUPTS() to occur while holding a spinlock, and so
29 * it is not necessary to do HOLD/RESUME_INTERRUPTS() in these functions.
30 *
31 * These functions are implemented in terms of hardware-dependent macros
32 * supplied by s_lock.h. There is not currently any extra functionality
33 * added by this header, but there has been in the past and may someday
34 * be again.
35 *
36 *
37 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
38 * Portions Copyright (c) 1994, Regents of the University of California
39 *
40 * src/include/storage/spin.h
41 *
42 *-------------------------------------------------------------------------
43 */
44#ifndef SPIN_H
45#define SPIN_H
46
47#include "storage/s_lock.h"
48
49static inline void
50SpinLockInit(volatile slock_t *lock)
51{
52 S_INIT_LOCK(lock);
53}
54
55static inline void
56SpinLockAcquire(volatile slock_t *lock)
57{
58 S_LOCK(lock);
59}
60
61static inline void
62SpinLockRelease(volatile slock_t *lock)
63{
64 S_UNLOCK(lock);
65}
66
67#endif /* SPIN_H */
static int fb(int x)
#define S_UNLOCK(lock)
Definition s_lock.h:689
#define S_INIT_LOCK(lock)
Definition s_lock.h:693
#define S_LOCK(lock)
Definition s_lock.h:666
static void SpinLockRelease(volatile slock_t *lock)
Definition spin.h:62
static void SpinLockAcquire(volatile slock_t *lock)
Definition spin.h:56
static void SpinLockInit(volatile slock_t *lock)
Definition spin.h:50