Header And Logo

PostgreSQL
| The world's most advanced open source database.

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
lwlock.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * lwlock.h
4  * Lightweight lock manager
5  *
6  *
7  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/storage/lwlock.h
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 /* Number of partitions the shared predicate lock tables are divided into */
31 #define LOG2_NUM_PREDICATELOCK_PARTITIONS 4
32 #define NUM_PREDICATELOCK_PARTITIONS (1 << LOG2_NUM_PREDICATELOCK_PARTITIONS)
33 
34 /*
35  * We have a number of predefined LWLocks, plus a bunch of LWLocks that are
36  * dynamically assigned (e.g., for shared buffers). The LWLock structures
37  * live in shared memory (since they contain shared data) and are identified
38  * by values of this enumerated type. We abuse the notion of an enum somewhat
39  * by allowing values not listed in the enum declaration to be assigned.
40  * The extra value MaxDynamicLWLock is there to keep the compiler from
41  * deciding that the enum can be represented as char or short ...
42  *
43  * If you remove a lock, please replace it with a placeholder. This retains
44  * the lock numbering, which is helpful for DTrace and other external
45  * debugging scripts.
46  */
47 typedef enum LWLockId
48 {
82  /* Individual lock IDs end here */
86 
87  /* must be last except for MaxDynamicLWLock: */
89 
90  MaxDynamicLWLock = 1000000000
91 } LWLockId;
92 
93 
94 typedef enum LWLockMode
95 {
98  LW_WAIT_UNTIL_FREE /* A special mode used in PGPROC->lwlockMode,
99  * when waiting for lock to become free. Not
100  * to be used as LWLockAcquire argument */
101 } LWLockMode;
102 
103 
104 #ifdef LOCK_DEBUG
105 extern bool Trace_lwlocks;
106 #endif
107 
108 extern LWLockId LWLockAssign(void);
109 extern void LWLockAcquire(LWLockId lockid, LWLockMode mode);
110 extern bool LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode);
111 extern bool LWLockAcquireOrWait(LWLockId lockid, LWLockMode mode);
112 extern void LWLockRelease(LWLockId lockid);
113 extern void LWLockReleaseAll(void);
114 extern bool LWLockHeldByMe(LWLockId lockid);
115 
116 extern int NumLWLocks(void);
117 extern Size LWLockShmemSize(void);
118 extern void CreateLWLocks(void);
119 
120 extern void RequestAddinLWLocks(int n);
121 
122 #endif /* LWLOCK_H */