Line data Source code
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 :
49 : static inline void
50 18400606 : SpinLockInit(volatile slock_t *lock)
51 : {
52 18400606 : S_INIT_LOCK(lock);
53 18400606 : }
54 :
55 : static inline void
56 58398803 : SpinLockAcquire(volatile slock_t *lock)
57 : {
58 58398803 : S_LOCK(lock);
59 58398803 : }
60 :
61 : static inline void
62 58398803 : SpinLockRelease(volatile slock_t *lock)
63 : {
64 58398803 : S_UNLOCK(lock);
65 58398803 : }
66 :
67 : #endif /* SPIN_H */
|