]> granicus.if.org Git - postgresql/blob - src/include/storage/lwlock.h
Replace the pg_listener-based LISTEN/NOTIFY mechanism with an in-memory queue.
[postgresql] / src / include / storage / lwlock.h
1 /*-------------------------------------------------------------------------
2  *
3  * lwlock.h
4  *        Lightweight lock manager
5  *
6  *
7  * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/storage/lwlock.h,v 1.45 2010/02/16 22:34:57 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef LWLOCK_H
15 #define LWLOCK_H
16
17 /*
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.
21  */
22
23 /* Number of partitions of the shared buffer mapping hashtable */
24 #define NUM_BUFFER_PARTITIONS  16
25
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)
29
30 /*
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 ...
38  *
39  * If you remove a lock, please replace it with a placeholder. This retains
40  * the lock numbering, which is helpful for DTrace and other external
41  * debugging scripts.
42  */
43 typedef enum LWLockId
44 {
45         BufFreelistLock,
46         ShmemIndexLock,
47         OidGenLock,
48         XidGenLock,
49         ProcArrayLock,
50         SInvalReadLock,
51         SInvalWriteLock,
52         WALInsertLock,
53         WALWriteLock,
54         ControlFileLock,
55         CheckpointLock,
56         CLogControlLock,
57         SubtransControlLock,
58         MultiXactGenLock,
59         MultiXactOffsetControlLock,
60         MultiXactMemberControlLock,
61         RelCacheInitLock,
62         BgWriterCommLock,
63         TwoPhaseStateLock,
64         TablespaceCreateLock,
65         BtreeVacuumLock,
66         AddinShmemInitLock,
67         AutovacuumLock,
68         AutovacuumScheduleLock,
69         SyncScanLock,
70         RelationMappingLock,
71         AsyncCtlLock,
72         AsyncQueueLock,
73         /* Individual lock IDs end here */
74         FirstBufMappingLock,
75         FirstLockMgrLock = FirstBufMappingLock + NUM_BUFFER_PARTITIONS,
76
77         /* must be last except for MaxDynamicLWLock: */
78         NumFixedLWLocks = FirstLockMgrLock + NUM_LOCK_PARTITIONS,
79
80         MaxDynamicLWLock = 1000000000
81 } LWLockId;
82
83
84 typedef enum LWLockMode
85 {
86         LW_EXCLUSIVE,
87         LW_SHARED
88 } LWLockMode;
89
90
91 #ifdef LOCK_DEBUG
92 extern bool Trace_lwlocks;
93 #endif
94
95 extern LWLockId LWLockAssign(void);
96 extern void LWLockAcquire(LWLockId lockid, LWLockMode mode);
97 extern bool LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode);
98 extern void LWLockRelease(LWLockId lockid);
99 extern void LWLockReleaseAll(void);
100 extern bool LWLockHeldByMe(LWLockId lockid);
101
102 extern int      NumLWLocks(void);
103 extern Size LWLockShmemSize(void);
104 extern void CreateLWLocks(void);
105
106 extern void RequestAddinLWLocks(int n);
107
108 #endif   /* LWLOCK_H */