1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* lmgr.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* POSTGRES lock manager definitions.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
2004-08-29 06:13:13 +02:00
|
|
|
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2004-09-16 18:58:44 +02:00
|
|
|
* $PostgreSQL: pgsql/src/include/storage/lmgr.h,v 1.44 2004/09/16 16:58:42 tgl Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef LMGR_H
|
1996-08-28 03:59:28 +02:00
|
|
|
#define LMGR_H
|
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "storage/lock.h"
|
|
|
|
#include "utils/rel.h"
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1999-09-18 21:08:25 +02:00
|
|
|
/* These are the valid values of type LOCKMODE: */
|
|
|
|
|
|
|
|
/* NoLock is not a lock mode, but a flag value meaning "don't get a lock" */
|
|
|
|
#define NoLock 0
|
|
|
|
|
1998-12-15 13:47:01 +01:00
|
|
|
#define AccessShareLock 1 /* SELECT */
|
|
|
|
#define RowShareLock 2 /* SELECT FOR UPDATE */
|
|
|
|
#define RowExclusiveLock 3 /* INSERT, UPDATE, DELETE */
|
2001-07-10 00:18:34 +02:00
|
|
|
#define ShareUpdateExclusiveLock 4 /* VACUUM (non-FULL) */
|
|
|
|
#define ShareLock 5 /* CREATE INDEX */
|
|
|
|
#define ShareRowExclusiveLock 6 /* like EXCLUSIVE MODE, but allows
|
|
|
|
* ROW SHARE */
|
|
|
|
#define ExclusiveLock 7 /* blocks ROW SHARE/SELECT...FOR
|
2001-03-22 05:01:46 +01:00
|
|
|
* UPDATE */
|
2001-10-25 07:50:21 +02:00
|
|
|
#define AccessExclusiveLock 8 /* ALTER TABLE, DROP TABLE, VACUUM
|
|
|
|
* FULL, and unqualified LOCK
|
2001-03-22 05:01:46 +01:00
|
|
|
* TABLE */
|
2001-06-22 02:04:59 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: all lock mode numbers must be less than lock.h's MAX_LOCKMODES,
|
|
|
|
* so increase that if you want to add more modes.
|
|
|
|
*/
|
|
|
|
|
Try to reduce confusion about what is a lock method identifier, a lock
method control structure, or a table of control structures.
. Use type LOCKMASK where an int is not a counter.
. Get rid of INVALID_TABLEID, use INVALID_LOCKMETHOD instead.
. Use INVALID_LOCKMETHOD instead of (LOCKMETHOD) NULL, because
LOCKMETHOD is not a pointer.
. Define and use macro LockMethodIsValid.
. Rename LOCKMETHOD to LOCKMETHODID.
. Remove global variable LongTermTableId in lmgr.c, because it is
never used.
. Make LockTableId static in lmgr.c, because it is used nowhere else.
Why not remove it and use DEFAULT_LOCKMETHOD?
. Rename the lock method control structure from LOCKMETHODTABLE to
LockMethodData. Introduce a pointer type named LockMethod.
. Remove elog(FATAL) after InitLockTable() call in
CreateSharedMemoryAndSemaphores(), because if something goes wrong,
there is elog(FATAL) in LockMethodTableInit(), and if this doesn't
help, an elog(ERROR) in InitLockTable() is promoted to FATAL.
. Make InitLockTable() void, because its only caller does not use its
return value any more.
. Rename variables in lock.c to avoid statements like
LockMethodTable[NumLockMethods] = lockMethodTable;
lockMethodTable = LockMethodTable[lockmethod];
. Change LOCKMETHODID type to uint16 to fit into struct LOCKTAG.
. Remove static variables BITS_OFF and BITS_ON from lock.c, because
I agree to this doubt:
* XXX is a fetch from a static array really faster than a shift?
. Define and use macros LOCKBIT_ON/OFF.
Manfred Koizar
2003-12-01 22:59:25 +01:00
|
|
|
extern void InitLockTable(int maxBackends);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void RelationInitLockInfo(Relation relation);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-12-22 01:51:54 +01:00
|
|
|
/* Lock a relation */
|
1998-12-15 13:47:01 +01:00
|
|
|
extern void LockRelation(Relation relation, LOCKMODE lockmode);
|
2001-06-22 02:04:59 +02:00
|
|
|
extern bool ConditionalLockRelation(Relation relation, LOCKMODE lockmode);
|
1998-12-15 13:47:01 +01:00
|
|
|
extern void UnlockRelation(Relation relation, LOCKMODE lockmode);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-12-22 01:51:54 +01:00
|
|
|
extern void LockRelationForSession(LockRelId *relid, LOCKMODE lockmode);
|
|
|
|
extern void UnlockRelationForSession(LockRelId *relid, LOCKMODE lockmode);
|
|
|
|
|
2003-09-05 00:06:27 +02:00
|
|
|
/* Lock a page (mainly used for indexes) */
|
1998-12-15 13:47:01 +01:00
|
|
|
extern void LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
|
2003-09-05 00:06:27 +02:00
|
|
|
extern bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
|
1998-12-15 13:47:01 +01:00
|
|
|
extern void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-12-22 01:51:54 +01:00
|
|
|
/* Lock an XID (used to wait for a transaction to finish) */
|
1998-12-15 13:47:01 +01:00
|
|
|
extern void XactLockTableInsert(TransactionId xid);
|
2004-09-16 18:58:44 +02:00
|
|
|
extern void XactLockTableDelete(TransactionId xid);
|
1998-12-15 13:47:01 +01:00
|
|
|
extern void XactLockTableWait(TransactionId xid);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* LMGR_H */
|