1
/*-------------------------------------------------------------------------
4
* Hardware-independent implementation of spinlocks.
7
* The hardware-independent interface to spinlocks is defined by the
8
* typedef "slock_t" and these macros:
10
* void SpinLockInit(volatile slock_t *lock)
11
* Initialize a spinlock (to the unlocked state).
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.
18
* void SpinLockRelease(volatile slock_t *lock)
19
* Unlock a previously acquired lock.
21
* bool SpinLockFree(slock_t *lock)
22
* Tests if the lock is free. Returns TRUE if free, FALSE if locked.
23
* This does *not* change the state of the lock.
25
* Callers must beware that the macro argument may be evaluated multiple
28
* CAUTION: Care must be taken to ensure that loads and stores of
29
* shared memory values are not rearranged around spinlock acquire
30
* and release. This is done using the "volatile" qualifier: the C
31
* standard states that loads and stores of volatile objects cannot
32
* be rearranged *with respect to other volatile objects*. The
33
* spinlock is always written through a volatile pointer by the
34
* spinlock macros, but this is not sufficient by itself: code that
35
* protects shared data with a spinlock MUST reference that shared
36
* data through a volatile pointer.
38
* Keep in mind the coding rule that spinlocks must not be held for more
39
* than a few instructions. In particular, we assume it is not possible
40
* for a CHECK_FOR_INTERRUPTS() to occur while holding a spinlock, and so
41
* it is not necessary to do HOLD/RESUME_INTERRUPTS() in these macros.
43
* These macros are implemented in terms of hardware-dependent macros
44
* supplied by s_lock.h. There is not currently any extra functionality
45
* added by this header, but there has been in the past and may someday
49
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
50
* Portions Copyright (c) 1994, Regents of the University of California
52
* src/include/storage/spin.h
54
*-------------------------------------------------------------------------
59
#include "storage/s_lock.h"
62
#define SpinLockInit(lock) S_INIT_LOCK(lock)
64
#define SpinLockAcquire(lock) S_LOCK(lock)
66
#define SpinLockRelease(lock) S_UNLOCK(lock)
68
#define SpinLockFree(lock) S_LOCK_FREE(lock)
71
extern int SpinlockSemas(void);