Fix obsolete comment regarding FSM truncation.
[PostgreSQL.git] / src / include / storage / lwlock.h
blob5a1ca5891f952b5e0268db5ed9dba3416d093fb9
1 /*-------------------------------------------------------------------------
3 * lwlock.h
4 * Lightweight lock manager
7 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL$
12 *-------------------------------------------------------------------------
14 #ifndef LWLOCK_H
15 #define LWLOCK_H
18 * It's a bit odd to declare NUM_BUFFER_PARTITIONS and NUM_LOCK_PARTITIONS
19 * here, but we need them to set up enum LWLockId correctly, and having
20 * this file include lock.h or bufmgr.h would be backwards.
23 /* Number of partitions of the shared buffer mapping hashtable */
24 #define NUM_BUFFER_PARTITIONS 16
26 /* Number of partitions the shared lock tables are divided into */
27 #define LOG2_NUM_LOCK_PARTITIONS 4
28 #define NUM_LOCK_PARTITIONS (1 << LOG2_NUM_LOCK_PARTITIONS)
31 * We have a number of predefined LWLocks, plus a bunch of LWLocks that are
32 * dynamically assigned (e.g., for shared buffers). The LWLock structures
33 * live in shared memory (since they contain shared data) and are identified
34 * by values of this enumerated type. We abuse the notion of an enum somewhat
35 * by allowing values not listed in the enum declaration to be assigned.
36 * The extra value MaxDynamicLWLock is there to keep the compiler from
37 * deciding that the enum can be represented as char or short ...
39 * If you remove a lock, please replace it with a placeholder like was done
40 * for FreeSpaceMapLock. This retains the lock numbering, which is helpful for
41 * DTrace and other external debugging scripts.
43 typedef enum LWLockId
45 BufFreelistLock,
46 ShmemIndexLock,
47 OidGenLock,
48 XidGenLock,
49 ProcArrayLock,
50 SInvalReadLock,
51 SInvalWriteLock,
52 UnusedLock1, /* FreeSpaceMapLock used to be here */
53 WALInsertLock,
54 WALWriteLock,
55 ControlFileLock,
56 CheckpointLock,
57 CLogControlLock,
58 SubtransControlLock,
59 MultiXactGenLock,
60 MultiXactOffsetControlLock,
61 MultiXactMemberControlLock,
62 RelCacheInitLock,
63 BgWriterCommLock,
64 TwoPhaseStateLock,
65 TablespaceCreateLock,
66 BtreeVacuumLock,
67 AddinShmemInitLock,
68 AutovacuumLock,
69 AutovacuumScheduleLock,
70 SyncScanLock,
71 /* Individual lock IDs end here */
72 FirstBufMappingLock,
73 FirstLockMgrLock = FirstBufMappingLock + NUM_BUFFER_PARTITIONS,
75 /* must be last except for MaxDynamicLWLock: */
76 NumFixedLWLocks = FirstLockMgrLock + NUM_LOCK_PARTITIONS,
78 MaxDynamicLWLock = 1000000000
79 } LWLockId;
82 typedef enum LWLockMode
84 LW_EXCLUSIVE,
85 LW_SHARED
86 } LWLockMode;
89 #ifdef LOCK_DEBUG
90 extern bool Trace_lwlocks;
91 #endif
93 extern LWLockId LWLockAssign(void);
94 extern void LWLockAcquire(LWLockId lockid, LWLockMode mode);
95 extern bool LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode);
96 extern void LWLockRelease(LWLockId lockid);
97 extern void LWLockReleaseAll(void);
98 extern bool LWLockHeldByMe(LWLockId lockid);
100 extern int NumLWLocks(void);
101 extern Size LWLockShmemSize(void);
102 extern void CreateLWLocks(void);
104 extern void RequestAddinLWLocks(int n);
106 #endif /* LWLOCK_H */