]> granicus.if.org Git - postgresql/blob - src/include/storage/lwlock.h
Divide the lock manager's shared state into 'partitions', so as to
[postgresql] / src / include / storage / lwlock.h
1 /*-------------------------------------------------------------------------
2  *
3  * lwlock.h
4  *        Lightweight lock manager
5  *
6  *
7  * Portions Copyright (c) 1996-2005, 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.24 2005/12/11 21:02:18 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef LWLOCK_H
15 #define LWLOCK_H
16
17 /*
18  * We have a number of predefined LWLocks, plus a bunch of LWLocks that are
19  * dynamically assigned (e.g., for shared buffers).  The LWLock structures
20  * live in shared memory (since they contain shared data) and are identified
21  * by values of this enumerated type.  We abuse the notion of an enum somewhat
22  * by allowing values not listed in the enum declaration to be assigned.
23  * The extra value MaxDynamicLWLock is there to keep the compiler from
24  * deciding that the enum can be represented as char or short ...
25  */
26 typedef enum LWLockId
27 {
28         BufMappingLock,
29         BufFreelistLock,
30         OidGenLock,
31         XidGenLock,
32         ProcArrayLock,
33         SInvalLock,
34         FreeSpaceLock,
35         WALInsertLock,
36         WALWriteLock,
37         ControlFileLock,
38         CheckpointLock,
39         CheckpointStartLock,
40         CLogControlLock,
41         SubtransControlLock,
42         MultiXactGenLock,
43         MultiXactOffsetControlLock,
44         MultiXactMemberControlLock,
45         RelCacheInitLock,
46         BgWriterCommLock,
47         TwoPhaseStateLock,
48         FirstLockMgrLock,                       /* must be last except for MaxDynamicLWLock */
49
50         MaxDynamicLWLock = 1000000000
51 } LWLockId;
52
53
54 typedef enum LWLockMode
55 {
56         LW_EXCLUSIVE,
57         LW_SHARED
58 } LWLockMode;
59
60
61 #ifdef LOCK_DEBUG
62 extern bool Trace_lwlocks;
63 #endif
64
65 extern LWLockId LWLockAssign(void);
66 extern void LWLockAcquire(LWLockId lockid, LWLockMode mode);
67 extern bool LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode);
68 extern void LWLockRelease(LWLockId lockid);
69 extern void LWLockReleaseAll(void);
70 extern bool LWLockHeldByMe(LWLockId lockid);
71
72 extern int      NumLWLocks(void);
73 extern Size LWLockShmemSize(void);
74 extern void CreateLWLocks(void);
75
76 #endif   /* LWLOCK_H */