Header And Logo

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

lwlock.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * lwlock.h
00004  *    Lightweight lock manager
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/storage/lwlock.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef LWLOCK_H
00015 #define LWLOCK_H
00016 
00017 /*
00018  * It's a bit odd to declare NUM_BUFFER_PARTITIONS and NUM_LOCK_PARTITIONS
00019  * here, but we need them to set up enum LWLockId correctly, and having
00020  * this file include lock.h or bufmgr.h would be backwards.
00021  */
00022 
00023 /* Number of partitions of the shared buffer mapping hashtable */
00024 #define NUM_BUFFER_PARTITIONS  16
00025 
00026 /* Number of partitions the shared lock tables are divided into */
00027 #define LOG2_NUM_LOCK_PARTITIONS  4
00028 #define NUM_LOCK_PARTITIONS  (1 << LOG2_NUM_LOCK_PARTITIONS)
00029 
00030 /* Number of partitions the shared predicate lock tables are divided into */
00031 #define LOG2_NUM_PREDICATELOCK_PARTITIONS  4
00032 #define NUM_PREDICATELOCK_PARTITIONS  (1 << LOG2_NUM_PREDICATELOCK_PARTITIONS)
00033 
00034 /*
00035  * We have a number of predefined LWLocks, plus a bunch of LWLocks that are
00036  * dynamically assigned (e.g., for shared buffers).  The LWLock structures
00037  * live in shared memory (since they contain shared data) and are identified
00038  * by values of this enumerated type.  We abuse the notion of an enum somewhat
00039  * by allowing values not listed in the enum declaration to be assigned.
00040  * The extra value MaxDynamicLWLock is there to keep the compiler from
00041  * deciding that the enum can be represented as char or short ...
00042  *
00043  * If you remove a lock, please replace it with a placeholder. This retains
00044  * the lock numbering, which is helpful for DTrace and other external
00045  * debugging scripts.
00046  */
00047 typedef enum LWLockId
00048 {
00049     BufFreelistLock,
00050     ShmemIndexLock,
00051     OidGenLock,
00052     XidGenLock,
00053     ProcArrayLock,
00054     SInvalReadLock,
00055     SInvalWriteLock,
00056     WALInsertLock,
00057     WALWriteLock,
00058     ControlFileLock,
00059     CheckpointLock,
00060     CLogControlLock,
00061     SubtransControlLock,
00062     MultiXactGenLock,
00063     MultiXactOffsetControlLock,
00064     MultiXactMemberControlLock,
00065     RelCacheInitLock,
00066     CheckpointerCommLock,
00067     TwoPhaseStateLock,
00068     TablespaceCreateLock,
00069     BtreeVacuumLock,
00070     AddinShmemInitLock,
00071     AutovacuumLock,
00072     AutovacuumScheduleLock,
00073     SyncScanLock,
00074     RelationMappingLock,
00075     AsyncCtlLock,
00076     AsyncQueueLock,
00077     SerializableXactHashLock,
00078     SerializableFinishedListLock,
00079     SerializablePredicateLockListLock,
00080     OldSerXidLock,
00081     SyncRepLock,
00082     /* Individual lock IDs end here */
00083     FirstBufMappingLock,
00084     FirstLockMgrLock = FirstBufMappingLock + NUM_BUFFER_PARTITIONS,
00085     FirstPredicateLockMgrLock = FirstLockMgrLock + NUM_LOCK_PARTITIONS,
00086 
00087     /* must be last except for MaxDynamicLWLock: */
00088     NumFixedLWLocks = FirstPredicateLockMgrLock + NUM_PREDICATELOCK_PARTITIONS,
00089 
00090     MaxDynamicLWLock = 1000000000
00091 } LWLockId;
00092 
00093 
00094 typedef enum LWLockMode
00095 {
00096     LW_EXCLUSIVE,
00097     LW_SHARED,
00098     LW_WAIT_UNTIL_FREE          /* A special mode used in PGPROC->lwlockMode,
00099                                  * when waiting for lock to become free. Not
00100                                  * to be used as LWLockAcquire argument */
00101 } LWLockMode;
00102 
00103 
00104 #ifdef LOCK_DEBUG
00105 extern bool Trace_lwlocks;
00106 #endif
00107 
00108 extern LWLockId LWLockAssign(void);
00109 extern void LWLockAcquire(LWLockId lockid, LWLockMode mode);
00110 extern bool LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode);
00111 extern bool LWLockAcquireOrWait(LWLockId lockid, LWLockMode mode);
00112 extern void LWLockRelease(LWLockId lockid);
00113 extern void LWLockReleaseAll(void);
00114 extern bool LWLockHeldByMe(LWLockId lockid);
00115 
00116 extern int  NumLWLocks(void);
00117 extern Size LWLockShmemSize(void);
00118 extern void CreateLWLocks(void);
00119 
00120 extern void RequestAddinLWLocks(int n);
00121 
00122 #endif   /* LWLOCK_H */