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
49
static
inline
void
50
SpinLockInit
(
volatile
slock_t
*lock)
51
{
52
S_INIT_LOCK
(lock);
53
}
54
55
static
inline
void
56
SpinLockAcquire
(
volatile
slock_t
*lock)
57
{
58
S_LOCK
(lock);
59
}
60
61
static
inline
void
62
SpinLockRelease
(
volatile
slock_t
*lock)
63
{
64
S_UNLOCK
(lock);
65
}
66
67
#endif
/* SPIN_H */
fb
static int fb(int x)
Definition
preproc-init.c:92
s_lock.h
S_UNLOCK
#define S_UNLOCK(lock)
Definition
s_lock.h:689
S_INIT_LOCK
#define S_INIT_LOCK(lock)
Definition
s_lock.h:693
S_LOCK
#define S_LOCK(lock)
Definition
s_lock.h:666
SpinLockRelease
static void SpinLockRelease(volatile slock_t *lock)
Definition
spin.h:62
SpinLockAcquire
static void SpinLockAcquire(volatile slock_t *lock)
Definition
spin.h:56
SpinLockInit
static void SpinLockInit(volatile slock_t *lock)
Definition
spin.h:50
src
include
storage
spin.h
Generated on Sun Mar 1 2026 12:13:17 for PostgreSQL Source Code by
1.9.8