More comment improvements.

This commit is contained in:
Bruce Momjian 2001-02-22 23:02:33 +00:00
parent 4f6c49fef0
commit 82fc51e0b3
4 changed files with 102 additions and 101 deletions

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.81 2001/01/25 03:31:16 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.82 2001/02/22 23:02:33 momjian Exp $
* *
* NOTES * NOTES
* Outside modules can create a lock table and acquire/release * Outside modules can create a lock table and acquire/release
@ -157,24 +157,24 @@ SPINLOCK LockMgrLock; /* in Shmem or created in
static LOCKMASK BITS_OFF[MAX_LOCKMODES]; static LOCKMASK BITS_OFF[MAX_LOCKMODES];
static LOCKMASK BITS_ON[MAX_LOCKMODES]; static LOCKMASK BITS_ON[MAX_LOCKMODES];
/* ----------------- /*
* Disable flag * Disable flag
* ----------------- *
*/ */
static bool LockingIsDisabled; static bool LockingIsDisabled;
/* ------------------- /*
* map from lockmethod to the lock table structure * map from lockmethod to the lock table structure
* ------------------- *
*/ */
static LOCKMETHODTABLE *LockMethodTable[MAX_LOCK_METHODS]; static LOCKMETHODTABLE *LockMethodTable[MAX_LOCK_METHODS];
static int NumLockMethods; static int NumLockMethods;
/* ------------------- /*
* InitLocks -- Init the lock module. Create a private data * InitLocks -- Init the lock module. Create a private data
* structure for constructing conflict masks. * structure for constructing conflict masks.
* ------------------- *
*/ */
void void
InitLocks(void) InitLocks(void)
@ -190,9 +190,9 @@ InitLocks(void)
} }
} }
/* ------------------- /*
* LockDisable -- sets LockingIsDisabled flag to TRUE or FALSE. * LockDisable -- sets LockingIsDisabled flag to TRUE or FALSE.
* ------------------ *
*/ */
void void
LockDisable(bool status) LockDisable(bool status)
@ -200,9 +200,9 @@ LockDisable(bool status)
LockingIsDisabled = status; LockingIsDisabled = status;
} }
/* ----------------- /*
* Boolean function to determine current locking status * Boolean function to determine current locking status
* ----------------- *
*/ */
bool bool
LockingDisabled(void) LockingDisabled(void)
@ -295,16 +295,16 @@ LockMethodTableInit(char *tabName,
lockMethodTable = (LOCKMETHODTABLE *) lockMethodTable = (LOCKMETHODTABLE *)
MemoryContextAlloc(TopMemoryContext, sizeof(LOCKMETHODTABLE)); MemoryContextAlloc(TopMemoryContext, sizeof(LOCKMETHODTABLE));
/* ------------------------ /*
* find/acquire the spinlock for the table * find/acquire the spinlock for the table
* ------------------------ *
*/ */
SpinAcquire(LockMgrLock); SpinAcquire(LockMgrLock);
/* ----------------------- /*
* allocate a control structure from shared memory or attach to it * allocate a control structure from shared memory or attach to it
* if it already exists. * if it already exists.
* ----------------------- *
*/ */
sprintf(shmemName, "%s (ctl)", tabName); sprintf(shmemName, "%s (ctl)", tabName);
lockMethodTable->ctl = (LOCKMETHODCTL *) lockMethodTable->ctl = (LOCKMETHODCTL *)
@ -313,15 +313,15 @@ LockMethodTableInit(char *tabName,
if (!lockMethodTable->ctl) if (!lockMethodTable->ctl)
elog(FATAL, "LockMethodTableInit: couldn't initialize %s", tabName); elog(FATAL, "LockMethodTableInit: couldn't initialize %s", tabName);
/* ------------------- /*
* no zero-th table * no zero-th table
* ------------------- *
*/ */
NumLockMethods = 1; NumLockMethods = 1;
/* ---------------- /*
* we're first - initialize * we're first - initialize
* ---------------- *
*/ */
if (!found) if (!found)
{ {
@ -330,18 +330,18 @@ LockMethodTableInit(char *tabName,
lockMethodTable->ctl->lockmethod = NumLockMethods; lockMethodTable->ctl->lockmethod = NumLockMethods;
} }
/* -------------------- /*
* other modules refer to the lock table by a lockmethod ID * other modules refer to the lock table by a lockmethod ID
* -------------------- *
*/ */
LockMethodTable[NumLockMethods] = lockMethodTable; LockMethodTable[NumLockMethods] = lockMethodTable;
NumLockMethods++; NumLockMethods++;
Assert(NumLockMethods <= MAX_LOCK_METHODS); Assert(NumLockMethods <= MAX_LOCK_METHODS);
/* ---------------------- /*
* allocate a hash table for LOCK structs. This is used * allocate a hash table for LOCK structs. This is used
* to store per-locked-object information. * to store per-locked-object information.
* ---------------------- *
*/ */
info.keysize = SHMEM_LOCKTAB_KEYSIZE; info.keysize = SHMEM_LOCKTAB_KEYSIZE;
info.datasize = SHMEM_LOCKTAB_DATASIZE; info.datasize = SHMEM_LOCKTAB_DATASIZE;
@ -359,10 +359,10 @@ LockMethodTableInit(char *tabName,
elog(FATAL, "LockMethodTableInit: couldn't initialize %s", tabName); elog(FATAL, "LockMethodTableInit: couldn't initialize %s", tabName);
Assert(lockMethodTable->lockHash->hash == tag_hash); Assert(lockMethodTable->lockHash->hash == tag_hash);
/* ------------------------- /*
* allocate a hash table for HOLDER structs. This is used * allocate a hash table for HOLDER structs. This is used
* to store per-lock-holder information. * to store per-lock-holder information.
* ------------------------- *
*/ */
info.keysize = SHMEM_HOLDERTAB_KEYSIZE; info.keysize = SHMEM_HOLDERTAB_KEYSIZE;
info.datasize = SHMEM_HOLDERTAB_DATASIZE; info.datasize = SHMEM_HOLDERTAB_DATASIZE;
@ -528,9 +528,9 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
return FALSE; return FALSE;
} }
/* -------------------- /*
* if it's a new lock object, initialize it * if it's a new lock object, initialize it
* -------------------- *
*/ */
if (!found) if (!found)
{ {
@ -552,9 +552,9 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
Assert(lock->nGranted <= lock->nRequested); Assert(lock->nGranted <= lock->nRequested);
} }
/* ------------------ /*
* Create the hash key for the holder table. * Create the hash key for the holder table.
* ------------------ *
*/ */
MemSet(&holdertag, 0, sizeof(HOLDERTAG)); /* must clear padding, needed */ MemSet(&holdertag, 0, sizeof(HOLDERTAG)); /* must clear padding, needed */
holdertag.lock = MAKE_OFFSET(lock); holdertag.lock = MAKE_OFFSET(lock);
@ -623,20 +623,20 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
#endif /* CHECK_DEADLOCK_RISK */ #endif /* CHECK_DEADLOCK_RISK */
} }
/* ---------------- /*
* lock->nRequested and lock->requested[] count the total number of * lock->nRequested and lock->requested[] count the total number of
* requests, whether granted or waiting, so increment those immediately. * requests, whether granted or waiting, so increment those immediately.
* The other counts don't increment till we get the lock. * The other counts don't increment till we get the lock.
* ---------------- *
*/ */
lock->nRequested++; lock->nRequested++;
lock->requested[lockmode]++; lock->requested[lockmode]++;
Assert((lock->nRequested > 0) && (lock->requested[lockmode] > 0)); Assert((lock->nRequested > 0) && (lock->requested[lockmode] > 0));
/* -------------------- /*
* If I already hold one or more locks of the requested type, * If I already hold one or more locks of the requested type,
* just grant myself another one without blocking. * just grant myself another one without blocking.
* -------------------- *
*/ */
if (holder->holding[lockmode] > 0) if (holder->holding[lockmode] > 0)
{ {
@ -646,10 +646,10 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
return TRUE; return TRUE;
} }
/* -------------------- /*
* If this process (under any XID) is a holder of the lock, * If this process (under any XID) is a holder of the lock,
* also grant myself another one without blocking. * also grant myself another one without blocking.
* -------------------- *
*/ */
LockCountMyLocks(holder->tag.lock, MyProc, myHolding); LockCountMyLocks(holder->tag.lock, MyProc, myHolding);
if (myHolding[lockmode] > 0) if (myHolding[lockmode] > 0)
@ -660,11 +660,11 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
return TRUE; return TRUE;
} }
/* -------------------- /*
* If lock requested conflicts with locks requested by waiters, * If lock requested conflicts with locks requested by waiters,
* must join wait queue. Otherwise, check for conflict with * must join wait queue. Otherwise, check for conflict with
* already-held locks. (That's last because most complex check.) * already-held locks. (That's last because most complex check.)
* -------------------- *
*/ */
if (lockMethodTable->ctl->conflictTab[lockmode] & lock->waitMask) if (lockMethodTable->ctl->conflictTab[lockmode] & lock->waitMask)
status = STATUS_FOUND; status = STATUS_FOUND;
@ -760,7 +760,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
return status == STATUS_OK; return status == STATUS_OK;
} }
/* ---------------------------- /*
* LockCheckConflicts -- test whether requested lock conflicts * LockCheckConflicts -- test whether requested lock conflicts
* with those already granted * with those already granted
* *
@ -775,7 +775,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
* *
* The caller can optionally pass the process's total holding counts, if * The caller can optionally pass the process's total holding counts, if
* known. If NULL is passed then these values will be computed internally. * known. If NULL is passed then these values will be computed internally.
* ---------------------------- *
*/ */
int int
LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable, LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
@ -792,7 +792,7 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
tmpMask; tmpMask;
int localHolding[MAX_LOCKMODES]; int localHolding[MAX_LOCKMODES];
/* ---------------------------- /*
* first check for global conflicts: If no locks conflict * first check for global conflicts: If no locks conflict
* with my request, then I get the lock. * with my request, then I get the lock.
* *
@ -800,7 +800,7 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
* currently held locks. conflictTable[lockmode] has a bit * currently held locks. conflictTable[lockmode] has a bit
* set for each type of lock that conflicts with request. Bitwise * set for each type of lock that conflicts with request. Bitwise
* compare tells if there is a conflict. * compare tells if there is a conflict.
* ---------------------------- *
*/ */
if (!(lockctl->conflictTab[lockmode] & lock->grantMask)) if (!(lockctl->conflictTab[lockmode] & lock->grantMask))
{ {
@ -808,12 +808,12 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
return STATUS_OK; return STATUS_OK;
} }
/* ------------------------ /*
* Rats. Something conflicts. But it could still be my own * Rats. Something conflicts. But it could still be my own
* lock. We have to construct a conflict mask * lock. We have to construct a conflict mask
* that does not reflect our own locks. Locks held by the current * that does not reflect our own locks. Locks held by the current
* process under another XID also count as "our own locks". * process under another XID also count as "our own locks".
* ------------------------ *
*/ */
if (myHolding == NULL) if (myHolding == NULL)
{ {
@ -831,12 +831,12 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
bitmask |= tmpMask; bitmask |= tmpMask;
} }
/* ------------------------ /*
* now check again for conflicts. 'bitmask' describes the types * now check again for conflicts. 'bitmask' describes the types
* of locks held by other processes. If one of these * of locks held by other processes. If one of these
* conflicts with the kind of lock that I want, there is a * conflicts with the kind of lock that I want, there is a
* conflict and I have to sleep. * conflict and I have to sleep.
* ------------------------ *
*/ */
if (!(lockctl->conflictTab[lockmode] & bitmask)) if (!(lockctl->conflictTab[lockmode] & bitmask))
{ {
@ -935,7 +935,7 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
strcat(new_status, " waiting"); strcat(new_status, " waiting");
set_ps_display(new_status); set_ps_display(new_status);
/* ------------------- /*
* NOTE: Think not to put any lock state cleanup after the call to * NOTE: Think not to put any lock state cleanup after the call to
* ProcSleep, in either the normal or failure path. The lock state * ProcSleep, in either the normal or failure path. The lock state
* must be fully set by the lock grantor, or by HandleDeadLock if we * must be fully set by the lock grantor, or by HandleDeadLock if we
@ -944,7 +944,7 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
* after someone else grants us the lock, but before we've noticed it. * after someone else grants us the lock, but before we've noticed it.
* Hence, after granting, the locktable state must fully reflect the * Hence, after granting, the locktable state must fully reflect the
* fact that we own the lock; we can't do additional work on return. * fact that we own the lock; we can't do additional work on return.
* ------------------- *
*/ */
if (ProcSleep(lockMethodTable, if (ProcSleep(lockMethodTable,
@ -952,11 +952,11 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
lock, lock,
holder) != STATUS_OK) holder) != STATUS_OK)
{ {
/* ------------------- /*
* We failed as a result of a deadlock, see HandleDeadLock(). * We failed as a result of a deadlock, see HandleDeadLock().
* Quit now. Removal of the holder and lock objects, if no longer * Quit now. Removal of the holder and lock objects, if no longer
* needed, will happen in xact cleanup (see above for motivation). * needed, will happen in xact cleanup (see above for motivation).
* ------------------- *
*/ */
LOCK_PRINT("WaitOnLock: aborting on lock", lock, lockmode); LOCK_PRINT("WaitOnLock: aborting on lock", lock, lockmode);
SpinRelease(lockMethodTable->ctl->masterLock); SpinRelease(lockMethodTable->ctl->masterLock);
@ -1150,7 +1150,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
Assert((lock->nGranted >= 0) && (lock->granted[lockmode] >= 0)); Assert((lock->nGranted >= 0) && (lock->granted[lockmode] >= 0));
Assert(lock->nGranted <= lock->nRequested); Assert(lock->nGranted <= lock->nRequested);
/* -------------------------- /*
* We need only run ProcLockWakeup if the released lock conflicts with * We need only run ProcLockWakeup if the released lock conflicts with
* at least one of the lock types requested by waiter(s). Otherwise * at least one of the lock types requested by waiter(s). Otherwise
* whatever conflict made them wait must still exist. NOTE: before MVCC, * whatever conflict made them wait must still exist. NOTE: before MVCC,
@ -1158,18 +1158,18 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
* But that's not true anymore, because the remaining granted locks might * But that's not true anymore, because the remaining granted locks might
* belong to some waiter, who could now be awakened because he doesn't * belong to some waiter, who could now be awakened because he doesn't
* conflict with his own locks. * conflict with his own locks.
* -------------------------- *
*/ */
if (lockMethodTable->ctl->conflictTab[lockmode] & lock->waitMask) if (lockMethodTable->ctl->conflictTab[lockmode] & lock->waitMask)
wakeupNeeded = true; wakeupNeeded = true;
if (lock->nRequested == 0) if (lock->nRequested == 0)
{ {
/* ------------------ /*
* if there's no one waiting in the queue, * if there's no one waiting in the queue,
* we just released the last lock on this object. * we just released the last lock on this object.
* Delete it from the lock table. * Delete it from the lock table.
* ------------------ *
*/ */
Assert(lockMethodTable->lockHash->hash == tag_hash); Assert(lockMethodTable->lockHash->hash == tag_hash);
lock = (LOCK *) hash_search(lockMethodTable->lockHash, lock = (LOCK *) hash_search(lockMethodTable->lockHash,
@ -1297,9 +1297,9 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
Assert(holder->nHolding >= 0); Assert(holder->nHolding >= 0);
Assert(holder->nHolding <= lock->nRequested); Assert(holder->nHolding <= lock->nRequested);
/* ------------------ /*
* fix the general lock stats * fix the general lock stats
* ------------------ *
*/ */
if (lock->nRequested != holder->nHolding) if (lock->nRequested != holder->nHolding)
{ {
@ -1328,10 +1328,10 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
} }
else else
{ {
/* -------------- /*
* This holder accounts for all the requested locks on the object, * This holder accounts for all the requested locks on the object,
* so we can be lazy and just zero things out. * so we can be lazy and just zero things out.
* -------------- *
*/ */
lock->nRequested = 0; lock->nRequested = 0;
lock->nGranted = 0; lock->nGranted = 0;
@ -1368,10 +1368,10 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
if (lock->nRequested == 0) if (lock->nRequested == 0)
{ {
/* -------------------- /*
* We've just released the last lock, so garbage-collect the * We've just released the last lock, so garbage-collect the
* lock object. * lock object.
* -------------------- *
*/ */
LOCK_PRINT("LockReleaseAll: deleting", lock, 0); LOCK_PRINT("LockReleaseAll: deleting", lock, 0);
Assert(lockMethodTable->lockHash->hash == tag_hash); Assert(lockMethodTable->lockHash->hash == tag_hash);

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: nbtree.h,v 1.53 2001/02/22 21:48:49 momjian Exp $ * $Id: nbtree.h,v 1.54 2001/02/22 23:02:33 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: lmgr.h,v 1.28 2001/01/24 19:43:27 momjian Exp $ * $Id: lmgr.h,v 1.29 2001/02/22 23:02:33 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -25,11 +25,12 @@
#define AccessShareLock 1 /* SELECT */ #define AccessShareLock 1 /* SELECT */
#define RowShareLock 2 /* SELECT FOR UPDATE */ #define RowShareLock 2 /* SELECT FOR UPDATE */
#define RowExclusiveLock 3 /* INSERT, UPDATE, DELETE */ #define RowExclusiveLock 3 /* INSERT, UPDATE, DELETE */
#define ShareLock 4 #define ShareLock 4 /* CREATE INDEX */
#define ShareRowExclusiveLock 5 #define ShareRowExclusiveLock 5 /* like EXCLUSIVE MODE, allows SHARE ROW */
#define ExclusiveLock 6 #define ExclusiveLock 6 /* blocks ROW SHARE/SELECT...FOR UPDATE */
#define AccessExclusiveLock 7 #define AccessExclusiveLock 7 /* ALTER TABLE, DROP TABLE, VACUUM, and
* unqualified LOCK TABLE
*/
extern LOCKMETHOD LockTableId; extern LOCKMETHOD LockTableId;

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: lock.h,v 1.44 2001/01/25 03:31:16 tgl Exp $ * $Id: lock.h,v 1.45 2001/02/22 23:02:33 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */