]> granicus.if.org Git - postgresql/blob - src/include/storage/lwlock.h
First phase of project to use fixed OIDs for all system catalogs and
[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.17 2005/03/04 20:21:07 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 (for shared buffers).  The LWLock structures live
20  * in shared memory (since they contain shared data) and are identified by
21  * 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         LockMgrLock,
31         OidGenLock,
32         XidGenLock,
33         SInvalLock,
34         FreeSpaceLock,
35         MMCacheLock,
36         WALInsertLock,
37         WALWriteLock,
38         ControlFileLock,
39         CheckpointLock,
40         CheckpointStartLock,
41         CLogControlLock,
42         SubtransControlLock,
43         RelCacheInitLock,
44         BgWriterCommLock,
45
46         NumFixedLWLocks,                        /* must be last except for
47                                                                  * MaxDynamicLWLock */
48
49         MaxDynamicLWLock = 1000000000
50 } LWLockId;
51
52
53 typedef enum LWLockMode
54 {
55         LW_EXCLUSIVE,
56         LW_SHARED
57 } LWLockMode;
58
59
60 #ifdef LOCK_DEBUG
61 extern bool Trace_lwlocks;
62 #endif
63
64 extern LWLockId LWLockAssign(void);
65 extern void LWLockAcquire(LWLockId lockid, LWLockMode mode);
66 extern bool LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode);
67 extern void LWLockRelease(LWLockId lockid);
68 extern void LWLockReleaseAll(void);
69 extern bool LWLockHeldByMe(LWLockId lockid);
70
71 extern int      NumLWLocks(void);
72 extern int      LWLockShmemSize(void);
73 extern void CreateLWLocks(void);
74
75 #endif   /* LWLOCK_H */