1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-02 09:02:37 +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:
Bruce Momjian
2003-12-01 21:59:25 +00:00
parent e2ac58c7bd
commit e7ca867485
8 changed files with 153 additions and 181 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.138 2003/11/29 19:51:57 pgsql Exp $
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.139 2003/12/01 21:59:25 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -543,14 +543,14 @@ ProcQueueInit(PROC_QUEUE *queue)
* semaphore is normally zero, so when we try to acquire it, we sleep.
*/
int
ProcSleep(LOCKMETHODTABLE *lockMethodTable,
ProcSleep(LockMethod lockMethodTable,
LOCKMODE lockmode,
LOCK *lock,
PROCLOCK *proclock)
{
LWLockId masterLock = lockMethodTable->masterLock;
PROC_QUEUE *waitQueue = &(lock->waitProcs);
int myHeldLocks = MyProc->heldLocks;
LOCKMASK myHeldLocks = MyProc->heldLocks;
bool early_deadlock = false;
PGPROC *proc;
int i;
@ -575,7 +575,7 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable,
*/
if (myHeldLocks != 0)
{
int aheadRequests = 0;
LOCKMASK aheadRequests = 0;
proc = (PGPROC *) MAKE_PTR(waitQueue->links.next);
for (i = 0; i < waitQueue->size; i++)
@ -615,7 +615,7 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable,
break;
}
/* Nope, so advance to next waiter */
aheadRequests |= (1 << proc->waitLockMode);
aheadRequests |= LOCKBIT_ON(proc->waitLockMode);
proc = (PGPROC *) MAKE_PTR(proc->links.next);
}
@ -637,7 +637,7 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable,
SHMQueueInsertBefore(&(proc->links), &(MyProc->links));
waitQueue->size++;
lock->waitMask |= (1 << lockmode);
lock->waitMask |= LOCKBIT_ON(lockmode);
/* Set up wait information in PGPROC object, too */
MyProc->waitLock = lock;
@ -769,12 +769,12 @@ ProcWakeup(PGPROC *proc, int errType)
* for lock, waken any that are no longer blocked.
*/
void
ProcLockWakeup(LOCKMETHODTABLE *lockMethodTable, LOCK *lock)
ProcLockWakeup(LockMethod lockMethodTable, LOCK *lock)
{
PROC_QUEUE *waitQueue = &(lock->waitProcs);
int queue_size = waitQueue->size;
PGPROC *proc;
int aheadRequests = 0;
LOCKMASK aheadRequests = 0;
Assert(queue_size >= 0);
@ -815,7 +815,7 @@ ProcLockWakeup(LOCKMETHODTABLE *lockMethodTable, LOCK *lock)
* Cannot wake this guy. Remember his request for later
* checks.
*/
aheadRequests |= (1 << lockmode);
aheadRequests |= LOCKBIT_ON(lockmode);
proc = (PGPROC *) MAKE_PTR(proc->links.next);
}
}