summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorBruce Momjian2003-12-01 21:59:25 +0000
committerBruce Momjian2003-12-01 21:59:25 +0000
commite7ca8674858f03a1bd6222bdb4de3d829cffbcc4 (patch)
treeb0b2be89de7ab564dcf2a9fc788c90d4b95ca83b /src/include
parente2ac58c7bd3e714bdf6c140b459c94b454b7b291 (diff)
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
Diffstat (limited to 'src/include')
-rw-r--r--src/include/storage/lmgr.h7
-rw-r--r--src/include/storage/lock.h56
-rw-r--r--src/include/storage/proc.h6
3 files changed, 34 insertions, 35 deletions
diff --git a/src/include/storage/lmgr.h b/src/include/storage/lmgr.h
index cd345e08cac..fc497c72e0d 100644
--- a/src/include/storage/lmgr.h
+++ b/src/include/storage/lmgr.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/lmgr.h,v 1.41 2003/11/29 22:41:13 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/storage/lmgr.h,v 1.42 2003/12/01 21:59:25 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -40,10 +40,7 @@
* so increase that if you want to add more modes.
*/
-extern LOCKMETHOD LockTableId;
-
-
-extern LOCKMETHOD InitLockTable(int maxBackends);
+extern void InitLockTable(int maxBackends);
extern void RelationInitLockInfo(Relation relation);
/* Lock a relation */
diff --git a/src/include/storage/lock.h b/src/include/storage/lock.h
index 416ec41e329..a7d66b835eb 100644
--- a/src/include/storage/lock.h
+++ b/src/include/storage/lock.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.74 2003/11/29 22:41:13 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.75 2003/12/01 21:59:25 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -42,22 +42,23 @@ extern bool Debug_deadlocks;
typedef int LOCKMASK;
-
typedef int LOCKMODE;
-typedef int LOCKMETHOD;
-
/* MAX_LOCKMODES cannot be larger than the # of bits in LOCKMASK */
#define MAX_LOCKMODES 10
+#define LOCKBIT_ON(lockmode) (1 << (lockmode))
+#define LOCKBIT_OFF(lockmode) (~(1 << (lockmode)))
+
+typedef uint16 LOCKMETHODID;
/* MAX_LOCK_METHODS is the number of distinct lock control tables allowed */
#define MAX_LOCK_METHODS 3
-#define INVALID_TABLEID 0
-
-#define INVALID_LOCKMETHOD INVALID_TABLEID
+#define INVALID_LOCKMETHOD 0
#define DEFAULT_LOCKMETHOD 1
#define USER_LOCKMETHOD 2
+#define LockMethodIsValid(lockmethodid) ((lockmethodid) != INVALID_LOCKMETHOD)
+
/*
* There is normally only one lock method, the default one.
* If user locks are enabled, an additional lock method is present.
@@ -83,15 +84,16 @@ typedef int LOCKMETHOD;
* masterLock -- synchronizes access to the table
*
*/
-typedef struct LOCKMETHODTABLE
+typedef struct LockMethodData
{
- HTAB *lockHash;
- HTAB *proclockHash;
- LOCKMETHOD lockmethod;
- int numLockModes;
- int conflictTab[MAX_LOCKMODES];
- LWLockId masterLock;
-} LOCKMETHODTABLE;
+ HTAB *lockHash;
+ HTAB *proclockHash;
+ LOCKMETHODID lockmethodid;
+ int numLockModes;
+ LOCKMASK conflictTab[MAX_LOCKMODES];
+ LWLockId masterLock;
+} LockMethodData;
+typedef LockMethodData *LockMethod;
/*
@@ -115,7 +117,7 @@ typedef struct LOCKTAG
*/
OffsetNumber offnum;
- uint16 lockmethod; /* needed by userlocks */
+ LOCKMETHODID lockmethodid; /* needed by userlocks */
} LOCKTAG;
@@ -139,8 +141,8 @@ typedef struct LOCK
LOCKTAG tag; /* unique identifier of lockable object */
/* data */
- int grantMask; /* bitmask for lock types already granted */
- int waitMask; /* bitmask for lock types awaited */
+ LOCKMASK grantMask; /* bitmask for lock types already granted */
+ LOCKMASK waitMask; /* bitmask for lock types awaited */
SHM_QUEUE lockHolders; /* list of PROCLOCK objects assoc. with
* lock */
PROC_QUEUE waitProcs; /* list of PGPROC objects waiting on lock */
@@ -151,7 +153,7 @@ typedef struct LOCK
int nGranted; /* total of granted[] array */
} LOCK;
-#define LOCK_LOCKMETHOD(lock) ((lock).tag.lockmethod)
+#define LOCK_LOCKMETHOD(lock) ((lock).tag.lockmethodid)
/*
@@ -204,7 +206,7 @@ typedef struct PROCLOCK
} PROCLOCK;
#define PROCLOCK_LOCKMETHOD(proclock) \
- (((LOCK *) MAKE_PTR((proclock).tag.lock))->tag.lockmethod)
+ (((LOCK *) MAKE_PTR((proclock).tag.lock))->tag.lockmethodid)
/*
* This struct holds information passed from lmgr internals to the lock
@@ -227,17 +229,17 @@ typedef struct
* function prototypes
*/
extern void InitLocks(void);
-extern LOCKMETHODTABLE *GetLocksMethodTable(LOCK *lock);
-extern LOCKMETHOD LockMethodTableInit(char *tabName, LOCKMASK *conflictsP,
+extern LockMethod GetLocksMethodTable(LOCK *lock);
+extern LOCKMETHODID LockMethodTableInit(char *tabName, LOCKMASK *conflictsP,
int numModes, int maxBackends);
-extern LOCKMETHOD LockMethodTableRename(LOCKMETHOD lockmethod);
-extern bool LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
+extern LOCKMETHODID LockMethodTableRename(LOCKMETHODID lockmethodid);
+extern bool LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
TransactionId xid, LOCKMODE lockmode, bool dontWait);
-extern bool LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
+extern bool LockRelease(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
TransactionId xid, LOCKMODE lockmode);
-extern bool LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc,
+extern bool LockReleaseAll(LOCKMETHODID lockmethodid, PGPROC *proc,
bool allxids, TransactionId xid);
-extern int LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
+extern int LockCheckConflicts(LockMethod lockMethodTable,
LOCKMODE lockmode,
LOCK *lock, PROCLOCK *proclock, PGPROC *proc,
int *myHolding);
diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h
index db84a6e9397..c7283f374cf 100644
--- a/src/include/storage/proc.h
+++ b/src/include/storage/proc.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.66 2003/11/29 22:41:13 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.67 2003/12/01 21:59:25 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -106,10 +106,10 @@ extern void InitDummyProcess(int proctype);
extern void ProcReleaseLocks(bool isCommit);
extern void ProcQueueInit(PROC_QUEUE *queue);
-extern int ProcSleep(LOCKMETHODTABLE *lockMethodTable, LOCKMODE lockmode,
+extern int ProcSleep(LockMethod lockMethodTable, LOCKMODE lockmode,
LOCK *lock, PROCLOCK *proclock);
extern PGPROC *ProcWakeup(PGPROC *proc, int errType);
-extern void ProcLockWakeup(LOCKMETHODTABLE *lockMethodTable, LOCK *lock);
+extern void ProcLockWakeup(LockMethod lockMethodTable, LOCK *lock);
extern bool LockWaitCancel(void);
extern void ProcWaitForSignal(void);