mirror of
https://github.com/postgres/postgres.git
synced 2025-11-12 05:01:15 +03:00
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
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.61 2003/11/29 19:51:56 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.62 2003/12/01 21:59:25 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -65,26 +65,24 @@ static LOCKMASK LockConflicts[] = {
|
||||
|
||||
};
|
||||
|
||||
LOCKMETHOD LockTableId = (LOCKMETHOD) NULL;
|
||||
LOCKMETHOD LongTermTableId = (LOCKMETHOD) NULL;
|
||||
static LOCKMETHODID LockTableId = INVALID_LOCKMETHOD;
|
||||
|
||||
/*
|
||||
* Create the lock table described by LockConflicts
|
||||
*/
|
||||
LOCKMETHOD
|
||||
void
|
||||
InitLockTable(int maxBackends)
|
||||
{
|
||||
int lockmethod;
|
||||
LOCKMETHODID LongTermTableId;
|
||||
|
||||
/* number of lock modes is lengthof()-1 because of dummy zero */
|
||||
lockmethod = LockMethodTableInit("LockTable",
|
||||
LockConflicts,
|
||||
lengthof(LockConflicts) - 1,
|
||||
maxBackends);
|
||||
LockTableId = lockmethod;
|
||||
|
||||
if (!(LockTableId))
|
||||
LockTableId = LockMethodTableInit("LockTable",
|
||||
LockConflicts,
|
||||
lengthof(LockConflicts) - 1,
|
||||
maxBackends);
|
||||
if (!LockMethodIsValid(LockTableId))
|
||||
elog(ERROR, "could not initialize lock table");
|
||||
Assert(LockTableId == DEFAULT_LOCKMETHOD);
|
||||
|
||||
#ifdef USER_LOCKS
|
||||
|
||||
@@ -92,11 +90,10 @@ InitLockTable(int maxBackends)
|
||||
* Allocate another tableId for long-term locks
|
||||
*/
|
||||
LongTermTableId = LockMethodTableRename(LockTableId);
|
||||
if (!(LongTermTableId))
|
||||
if (!LockMethodIsValid(LongTermTableId))
|
||||
elog(ERROR, "could not rename long-term lock table");
|
||||
Assert(LongTermTableId == USER_LOCKMETHOD);
|
||||
#endif
|
||||
|
||||
return LockTableId;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user