2001-09-29 06:02:27 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* lwlock.h
|
|
|
|
* Lightweight lock manager
|
|
|
|
*
|
|
|
|
*
|
2006-03-05 16:59:11 +01:00
|
|
|
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
2001-09-29 06:02:27 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2006-10-16 00:04:08 +02:00
|
|
|
* $PostgreSQL: pgsql/src/include/storage/lwlock.h,v 1.32 2006/10/15 22:04:07 tgl Exp $
|
2001-09-29 06:02:27 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef LWLOCK_H
|
|
|
|
#define LWLOCK_H
|
|
|
|
|
2006-07-23 05:07:58 +02:00
|
|
|
/*
|
|
|
|
* It's a bit odd to declare NUM_BUFFER_PARTITIONS and NUM_LOCK_PARTITIONS
|
|
|
|
* here, but we need them to set up enum LWLockId correctly, and having
|
|
|
|
* this file include lock.h or bufmgr.h would be backwards.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Number of partitions of the shared buffer mapping hashtable */
|
|
|
|
#define NUM_BUFFER_PARTITIONS 16
|
|
|
|
|
|
|
|
/* Number of partitions the shared lock tables are divided into */
|
2006-07-24 01:08:46 +02:00
|
|
|
#define LOG2_NUM_LOCK_PARTITIONS 4
|
|
|
|
#define NUM_LOCK_PARTITIONS (1 << LOG2_NUM_LOCK_PARTITIONS)
|
2006-07-23 05:07:58 +02:00
|
|
|
|
2001-09-29 06:02:27 +02:00
|
|
|
/*
|
|
|
|
* We have a number of predefined LWLocks, plus a bunch of LWLocks that are
|
2005-12-11 22:02:18 +01:00
|
|
|
* dynamically assigned (e.g., for shared buffers). The LWLock structures
|
|
|
|
* live in shared memory (since they contain shared data) and are identified
|
|
|
|
* by values of this enumerated type. We abuse the notion of an enum somewhat
|
2001-09-29 06:02:27 +02:00
|
|
|
* by allowing values not listed in the enum declaration to be assigned.
|
|
|
|
* The extra value MaxDynamicLWLock is there to keep the compiler from
|
|
|
|
* deciding that the enum can be represented as char or short ...
|
|
|
|
*/
|
|
|
|
typedef enum LWLockId
|
|
|
|
{
|
2005-03-04 21:21:07 +01:00
|
|
|
BufFreelistLock,
|
2006-01-04 22:06:32 +01:00
|
|
|
ShmemIndexLock,
|
2001-10-28 07:26:15 +01:00
|
|
|
OidGenLock,
|
|
|
|
XidGenLock,
|
2005-05-19 23:35:48 +02:00
|
|
|
ProcArrayLock,
|
2001-10-28 07:26:15 +01:00
|
|
|
SInvalLock,
|
|
|
|
FreeSpaceLock,
|
|
|
|
WALInsertLock,
|
|
|
|
WALWriteLock,
|
|
|
|
ControlFileLock,
|
|
|
|
CheckpointLock,
|
2004-08-11 06:07:16 +02:00
|
|
|
CheckpointStartLock,
|
2004-08-24 01:22:45 +02:00
|
|
|
CLogControlLock,
|
|
|
|
SubtransControlLock,
|
2005-04-28 23:47:18 +02:00
|
|
|
MultiXactGenLock,
|
|
|
|
MultiXactOffsetControlLock,
|
|
|
|
MultiXactMemberControlLock,
|
2002-02-19 21:11:20 +01:00
|
|
|
RelCacheInitLock,
|
2004-05-31 05:48:10 +02:00
|
|
|
BgWriterCommLock,
|
2005-06-18 00:32:51 +02:00
|
|
|
TwoPhaseStateLock,
|
2006-01-19 05:45:38 +01:00
|
|
|
TablespaceCreateLock,
|
2006-05-08 02:00:17 +02:00
|
|
|
BtreeVacuumLock,
|
2006-10-16 00:04:08 +02:00
|
|
|
AddinShmemInitLock,
|
2006-07-23 05:07:58 +02:00
|
|
|
FirstBufMappingLock,
|
|
|
|
FirstLockMgrLock = FirstBufMappingLock + NUM_BUFFER_PARTITIONS,
|
|
|
|
|
|
|
|
/* must be last except for MaxDynamicLWLock: */
|
|
|
|
NumFixedLWLocks = FirstLockMgrLock + NUM_LOCK_PARTITIONS,
|
2001-09-29 06:02:27 +02:00
|
|
|
|
2001-10-28 07:26:15 +01:00
|
|
|
MaxDynamicLWLock = 1000000000
|
2001-09-29 06:02:27 +02:00
|
|
|
} LWLockId;
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum LWLockMode
|
|
|
|
{
|
2001-10-28 07:26:15 +01:00
|
|
|
LW_EXCLUSIVE,
|
|
|
|
LW_SHARED
|
2001-09-29 06:02:27 +02:00
|
|
|
} LWLockMode;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef LOCK_DEBUG
|
|
|
|
extern bool Trace_lwlocks;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern LWLockId LWLockAssign(void);
|
|
|
|
extern void LWLockAcquire(LWLockId lockid, LWLockMode mode);
|
|
|
|
extern bool LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode);
|
|
|
|
extern void LWLockRelease(LWLockId lockid);
|
|
|
|
extern void LWLockReleaseAll(void);
|
2004-06-11 18:43:24 +02:00
|
|
|
extern bool LWLockHeldByMe(LWLockId lockid);
|
2001-09-29 06:02:27 +02:00
|
|
|
|
|
|
|
extern int NumLWLocks(void);
|
2005-08-21 01:26:37 +02:00
|
|
|
extern Size LWLockShmemSize(void);
|
2001-09-29 06:02:27 +02:00
|
|
|
extern void CreateLWLocks(void);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2006-10-16 00:04:08 +02:00
|
|
|
extern void RequestAddinLWLocks(int n);
|
2006-08-01 21:03:11 +02:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* LWLOCK_H */
|