Commit 32cc6cbe authored by Bruce Momjian's avatar Bruce Momjian

Rename 'holder' references to 'proclock' for PROCLOCK references, for

consistency.
parent cf55ee57
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/deadlock.c,v 1.16 2003/01/16 21:01:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/deadlock.c,v 1.17 2003/02/18 02:13:24 momjian Exp $
* *
* Interface: * Interface:
* *
...@@ -425,7 +425,7 @@ FindLockCycleRecurse(PGPROC *checkProc, ...@@ -425,7 +425,7 @@ FindLockCycleRecurse(PGPROC *checkProc,
{ {
PGPROC *proc; PGPROC *proc;
LOCK *lock; LOCK *lock;
PROCLOCK *holder; PROCLOCK *proclock;
SHM_QUEUE *lockHolders; SHM_QUEUE *lockHolders;
LOCKMETHODTABLE *lockMethodTable; LOCKMETHODTABLE *lockMethodTable;
PROC_QUEUE *waitQueue; PROC_QUEUE *waitQueue;
...@@ -484,19 +484,19 @@ FindLockCycleRecurse(PGPROC *checkProc, ...@@ -484,19 +484,19 @@ FindLockCycleRecurse(PGPROC *checkProc,
*/ */
lockHolders = &(lock->lockHolders); lockHolders = &(lock->lockHolders);
holder = (PROCLOCK *) SHMQueueNext(lockHolders, lockHolders, proclock = (PROCLOCK *) SHMQueueNext(lockHolders, lockHolders,
offsetof(PROCLOCK, lockLink)); offsetof(PROCLOCK, lockLink));
while (holder) while (proclock)
{ {
proc = (PGPROC *) MAKE_PTR(holder->tag.proc); proc = (PGPROC *) MAKE_PTR(proclock->tag.proc);
/* A proc never blocks itself */ /* A proc never blocks itself */
if (proc != checkProc) if (proc != checkProc)
{ {
for (lm = 1; lm <= numLockModes; lm++) for (lm = 1; lm <= numLockModes; lm++)
{ {
if (holder->holding[lm] > 0 && if (proclock->holding[lm] > 0 &&
((1 << lm) & conflictMask) != 0) ((1 << lm) & conflictMask) != 0)
{ {
/* This proc hard-blocks checkProc */ /* This proc hard-blocks checkProc */
...@@ -512,13 +512,13 @@ FindLockCycleRecurse(PGPROC *checkProc, ...@@ -512,13 +512,13 @@ FindLockCycleRecurse(PGPROC *checkProc,
return true; return true;
} }
/* If no deadlock, we're done looking at this holder */ /* If no deadlock, we're done looking at this proclock */
break; break;
} }
} }
} }
holder = (PROCLOCK *) SHMQueueNext(lockHolders, &holder->lockLink, proclock = (PROCLOCK *) SHMQueueNext(lockHolders, &proclock->lockLink,
offsetof(PROCLOCK, lockLink)); offsetof(PROCLOCK, lockLink));
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.119 2003/01/16 21:01:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.120 2003/02/18 02:13:24 momjian Exp $
* *
* NOTES * NOTES
* Outside modules can create a lock table and acquire/release * Outside modules can create a lock table and acquire/release
...@@ -47,7 +47,7 @@ int max_locks_per_xact; /* set by guc.c */ ...@@ -47,7 +47,7 @@ int max_locks_per_xact; /* set by guc.c */
static int WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode, static int WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
LOCK *lock, PROCLOCK *holder); LOCK *lock, PROCLOCK *proclock);
static void LockCountMyLocks(SHMEM_OFFSET lockOffset, PGPROC *proc, static void LockCountMyLocks(SHMEM_OFFSET lockOffset, PGPROC *proc,
int *myHolding); int *myHolding);
...@@ -124,28 +124,28 @@ LOCK_PRINT(const char *where, const LOCK *lock, LOCKMODE type) ...@@ -124,28 +124,28 @@ LOCK_PRINT(const char *where, const LOCK *lock, LOCKMODE type)
inline static void inline static void
PROCLOCK_PRINT(const char *where, const PROCLOCK *holderP) PROCLOCK_PRINT(const char *where, const PROCLOCK *proclockP)
{ {
if ( if (
(((PROCLOCK_LOCKMETHOD(*holderP) == DEFAULT_LOCKMETHOD && Trace_locks) (((PROCLOCK_LOCKMETHOD(*proclockP) == DEFAULT_LOCKMETHOD && Trace_locks)
|| (PROCLOCK_LOCKMETHOD(*holderP) == USER_LOCKMETHOD && Trace_userlocks)) || (PROCLOCK_LOCKMETHOD(*proclockP) == USER_LOCKMETHOD && Trace_userlocks))
&& (((LOCK *) MAKE_PTR(holderP->tag.lock))->tag.relId >= (Oid) Trace_lock_oidmin)) && (((LOCK *) MAKE_PTR(proclockP->tag.lock))->tag.relId >= (Oid) Trace_lock_oidmin))
|| (Trace_lock_table && (((LOCK *) MAKE_PTR(holderP->tag.lock))->tag.relId == Trace_lock_table)) || (Trace_lock_table && (((LOCK *) MAKE_PTR(proclockP->tag.lock))->tag.relId == Trace_lock_table))
) )
elog(LOG, elog(LOG,
"%s: holder(%lx) lock(%lx) tbl(%d) proc(%lx) xid(%u) hold(%d,%d,%d,%d,%d,%d,%d)=%d", "%s: proclock(%lx) lock(%lx) tbl(%d) proc(%lx) xid(%u) hold(%d,%d,%d,%d,%d,%d,%d)=%d",
where, MAKE_OFFSET(holderP), holderP->tag.lock, where, MAKE_OFFSET(proclockP), proclockP->tag.lock,
PROCLOCK_LOCKMETHOD(*(holderP)), PROCLOCK_LOCKMETHOD(*(proclockP)),
holderP->tag.proc, holderP->tag.xid, proclockP->tag.proc, proclockP->tag.xid,
holderP->holding[1], holderP->holding[2], holderP->holding[3], proclockP->holding[1], proclockP->holding[2], proclockP->holding[3],
holderP->holding[4], holderP->holding[5], holderP->holding[6], proclockP->holding[4], proclockP->holding[5], proclockP->holding[6],
holderP->holding[7], holderP->nHolding); proclockP->holding[7], proclockP->nHolding);
} }
#else /* not LOCK_DEBUG */ #else /* not LOCK_DEBUG */
#define LOCK_PRINT(where, lock, type) #define LOCK_PRINT(where, lock, type)
#define PROCLOCK_PRINT(where, holderP) #define PROCLOCK_PRINT(where, proclockP)
#endif /* not LOCK_DEBUG */ #endif /* not LOCK_DEBUG */
...@@ -312,21 +312,21 @@ LockMethodTableInit(char *tabName, ...@@ -312,21 +312,21 @@ LockMethodTableInit(char *tabName,
/* /*
* allocate a hash table for PROCLOCK structs. This is used to store * allocate a hash table for PROCLOCK structs. This is used to store
* per-lock-holder information. * per-lock-proclock information.
*/ */
info.keysize = sizeof(PROCLOCKTAG); info.keysize = sizeof(PROCLOCKTAG);
info.entrysize = sizeof(PROCLOCK); info.entrysize = sizeof(PROCLOCK);
info.hash = tag_hash; info.hash = tag_hash;
hash_flags = (HASH_ELEM | HASH_FUNCTION); hash_flags = (HASH_ELEM | HASH_FUNCTION);
sprintf(shmemName, "%s (holder hash)", tabName); sprintf(shmemName, "%s (proclock hash)", tabName);
lockMethodTable->holderHash = ShmemInitHash(shmemName, lockMethodTable->proclockHash = ShmemInitHash(shmemName,
init_table_size, init_table_size,
max_table_size, max_table_size,
&info, &info,
hash_flags); hash_flags);
if (!lockMethodTable->holderHash) if (!lockMethodTable->proclockHash)
elog(FATAL, "LockMethodTableInit: couldn't initialize %s", tabName); elog(FATAL, "LockMethodTableInit: couldn't initialize %s", tabName);
/* init data structures */ /* init data structures */
...@@ -421,7 +421,7 @@ LockMethodTableRename(LOCKMETHOD lockmethod) ...@@ -421,7 +421,7 @@ LockMethodTableRename(LOCKMETHOD lockmethod)
* tag.objId block id lock id2 * tag.objId block id lock id2
* or xact id * or xact id
* tag.offnum 0 lock id1 * tag.offnum 0 lock id1
* holder.xid xid or 0 0 * proclock.xid xid or 0 0
* persistence transaction user or backend * persistence transaction user or backend
* or backend * or backend
* *
...@@ -435,9 +435,9 @@ bool ...@@ -435,9 +435,9 @@ bool
LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
TransactionId xid, LOCKMODE lockmode, bool dontWait) TransactionId xid, LOCKMODE lockmode, bool dontWait)
{ {
PROCLOCK *holder; PROCLOCK *proclock;
PROCLOCKTAG holdertag; PROCLOCKTAG proclocktag;
HTAB *holderTable; HTAB *proclockTable;
bool found; bool found;
LOCK *lock; LOCK *lock;
LWLockId masterLock; LWLockId masterLock;
...@@ -506,25 +506,25 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -506,25 +506,25 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
} }
/* /*
* Create the hash key for the holder table. * Create the hash key for the proclock table.
*/ */
MemSet(&holdertag, 0, sizeof(PROCLOCKTAG)); /* must clear padding, MemSet(&proclocktag, 0, sizeof(PROCLOCKTAG)); /* must clear padding,
* needed */ * needed */
holdertag.lock = MAKE_OFFSET(lock); proclocktag.lock = MAKE_OFFSET(lock);
holdertag.proc = MAKE_OFFSET(MyProc); proclocktag.proc = MAKE_OFFSET(MyProc);
TransactionIdStore(xid, &holdertag.xid); TransactionIdStore(xid, &proclocktag.xid);
/* /*
* Find or create a holder entry with this tag * Find or create a proclock entry with this tag
*/ */
holderTable = lockMethodTable->holderHash; proclockTable = lockMethodTable->proclockHash;
holder = (PROCLOCK *) hash_search(holderTable, proclock = (PROCLOCK *) hash_search(proclockTable,
(void *) &holdertag, (void *) &proclocktag,
HASH_ENTER, &found); HASH_ENTER, &found);
if (!holder) if (!proclock)
{ {
LWLockRelease(masterLock); LWLockRelease(masterLock);
elog(ERROR, "LockAcquire: holder table out of memory"); elog(ERROR, "LockAcquire: proclock table out of memory");
return FALSE; return FALSE;
} }
...@@ -533,18 +533,18 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -533,18 +533,18 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
*/ */
if (!found) if (!found)
{ {
holder->nHolding = 0; proclock->nHolding = 0;
MemSet((char *) holder->holding, 0, sizeof(int) * MAX_LOCKMODES); MemSet((char *) proclock->holding, 0, sizeof(int) * MAX_LOCKMODES);
/* Add holder to appropriate lists */ /* Add proclock to appropriate lists */
SHMQueueInsertBefore(&lock->lockHolders, &holder->lockLink); SHMQueueInsertBefore(&lock->lockHolders, &proclock->lockLink);
SHMQueueInsertBefore(&MyProc->procHolders, &holder->procLink); SHMQueueInsertBefore(&MyProc->procHolders, &proclock->procLink);
PROCLOCK_PRINT("LockAcquire: new", holder); PROCLOCK_PRINT("LockAcquire: new", proclock);
} }
else else
{ {
PROCLOCK_PRINT("LockAcquire: found", holder); PROCLOCK_PRINT("LockAcquire: found", proclock);
Assert((holder->nHolding >= 0) && (holder->holding[lockmode] >= 0)); Assert((proclock->nHolding >= 0) && (proclock->holding[lockmode] >= 0));
Assert(holder->nHolding <= lock->nGranted); Assert(proclock->nHolding <= lock->nGranted);
#ifdef CHECK_DEADLOCK_RISK #ifdef CHECK_DEADLOCK_RISK
...@@ -565,7 +565,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -565,7 +565,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
*/ */
for (i = lockMethodTable->numLockModes; i > 0; i--) for (i = lockMethodTable->numLockModes; i > 0; i--)
{ {
if (holder->holding[i] > 0) if (proclock->holding[i] > 0)
{ {
if (i >= (int) lockmode) if (i >= (int) lockmode)
break; /* safe: we have a lock >= req level */ break; /* safe: we have a lock >= req level */
...@@ -592,23 +592,23 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -592,23 +592,23 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
* If I already hold one or more locks of the requested type, just * If I already hold one or more locks of the requested type, just
* grant myself another one without blocking. * grant myself another one without blocking.
*/ */
if (holder->holding[lockmode] > 0) if (proclock->holding[lockmode] > 0)
{ {
GrantLock(lock, holder, lockmode); GrantLock(lock, proclock, lockmode);
PROCLOCK_PRINT("LockAcquire: owning", holder); PROCLOCK_PRINT("LockAcquire: owning", proclock);
LWLockRelease(masterLock); LWLockRelease(masterLock);
return TRUE; return TRUE;
} }
/* /*
* If this process (under any XID) is a holder of the lock, also grant * If this process (under any XID) is a proclock of the lock, also grant
* myself another one without blocking. * myself another one without blocking.
*/ */
LockCountMyLocks(holder->tag.lock, MyProc, myHolding); LockCountMyLocks(proclock->tag.lock, MyProc, myHolding);
if (myHolding[lockmode] > 0) if (myHolding[lockmode] > 0)
{ {
GrantLock(lock, holder, lockmode); GrantLock(lock, proclock, lockmode);
PROCLOCK_PRINT("LockAcquire: my other XID owning", holder); PROCLOCK_PRINT("LockAcquire: my other XID owning", proclock);
LWLockRelease(masterLock); LWLockRelease(masterLock);
return TRUE; return TRUE;
} }
...@@ -622,13 +622,13 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -622,13 +622,13 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
status = STATUS_FOUND; status = STATUS_FOUND;
else else
status = LockCheckConflicts(lockMethodTable, lockmode, status = LockCheckConflicts(lockMethodTable, lockmode,
lock, holder, lock, proclock,
MyProc, myHolding); MyProc, myHolding);
if (status == STATUS_OK) if (status == STATUS_OK)
{ {
/* No conflict with held or previously requested locks */ /* No conflict with held or previously requested locks */
GrantLock(lock, holder, lockmode); GrantLock(lock, proclock, lockmode);
} }
else else
{ {
...@@ -636,23 +636,23 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -636,23 +636,23 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
/* /*
* We can't acquire the lock immediately. If caller specified no * We can't acquire the lock immediately. If caller specified no
* blocking, remove the holder entry and return FALSE without * blocking, remove the proclock entry and return FALSE without
* waiting. * waiting.
*/ */
if (dontWait) if (dontWait)
{ {
if (holder->nHolding == 0) if (proclock->nHolding == 0)
{ {
SHMQueueDelete(&holder->lockLink); SHMQueueDelete(&proclock->lockLink);
SHMQueueDelete(&holder->procLink); SHMQueueDelete(&proclock->procLink);
holder = (PROCLOCK *) hash_search(holderTable, proclock = (PROCLOCK *) hash_search(proclockTable,
(void *) holder, (void *) proclock,
HASH_REMOVE, NULL); HASH_REMOVE, NULL);
if (!holder) if (!proclock)
elog(WARNING, "LockAcquire: remove holder, table corrupted"); elog(WARNING, "LockAcquire: remove proclock, table corrupted");
} }
else else
PROCLOCK_PRINT("LockAcquire: NHOLDING", holder); PROCLOCK_PRINT("LockAcquire: NHOLDING", proclock);
lock->nRequested--; lock->nRequested--;
lock->requested[lockmode]--; lock->requested[lockmode]--;
LOCK_PRINT("LockAcquire: conditional lock failed", lock, lockmode); LOCK_PRINT("LockAcquire: conditional lock failed", lock, lockmode);
...@@ -682,7 +682,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -682,7 +682,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
/* /*
* Sleep till someone wakes me up. * Sleep till someone wakes me up.
*/ */
status = WaitOnLock(lockmethod, lockmode, lock, holder); status = WaitOnLock(lockmethod, lockmode, lock, proclock);
/* /*
* NOTE: do not do any material change of state between here and * NOTE: do not do any material change of state between here and
...@@ -692,18 +692,18 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -692,18 +692,18 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
*/ */
/* /*
* Check the holder entry status, in case something in the ipc * Check the proclock entry status, in case something in the ipc
* communication doesn't work correctly. * communication doesn't work correctly.
*/ */
if (!((holder->nHolding > 0) && (holder->holding[lockmode] > 0))) if (!((proclock->nHolding > 0) && (proclock->holding[lockmode] > 0)))
{ {
PROCLOCK_PRINT("LockAcquire: INCONSISTENT", holder); PROCLOCK_PRINT("LockAcquire: INCONSISTENT", proclock);
LOCK_PRINT("LockAcquire: INCONSISTENT", lock, lockmode); LOCK_PRINT("LockAcquire: INCONSISTENT", lock, lockmode);
/* Should we retry ? */ /* Should we retry ? */
LWLockRelease(masterLock); LWLockRelease(masterLock);
return FALSE; return FALSE;
} }
PROCLOCK_PRINT("LockAcquire: granted", holder); PROCLOCK_PRINT("LockAcquire: granted", proclock);
LOCK_PRINT("LockAcquire: granted", lock, lockmode); LOCK_PRINT("LockAcquire: granted", lock, lockmode);
} }
...@@ -732,7 +732,7 @@ int ...@@ -732,7 +732,7 @@ int
LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable, LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
LOCKMODE lockmode, LOCKMODE lockmode,
LOCK *lock, LOCK *lock,
PROCLOCK *holder, PROCLOCK *proclock,
PGPROC *proc, PGPROC *proc,
int *myHolding) /* myHolding[] array or NULL */ int *myHolding) /* myHolding[] array or NULL */
{ {
...@@ -753,7 +753,7 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable, ...@@ -753,7 +753,7 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
*/ */
if (!(lockMethodTable->conflictTab[lockmode] & lock->grantMask)) if (!(lockMethodTable->conflictTab[lockmode] & lock->grantMask))
{ {
PROCLOCK_PRINT("LockCheckConflicts: no conflict", holder); PROCLOCK_PRINT("LockCheckConflicts: no conflict", proclock);
return STATUS_OK; return STATUS_OK;
} }
...@@ -766,7 +766,7 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable, ...@@ -766,7 +766,7 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
if (myHolding == NULL) if (myHolding == NULL)
{ {
/* Caller didn't do calculation of total holding for me */ /* Caller didn't do calculation of total holding for me */
LockCountMyLocks(holder->tag.lock, proc, localHolding); LockCountMyLocks(proclock->tag.lock, proc, localHolding);
myHolding = localHolding; myHolding = localHolding;
} }
...@@ -787,11 +787,11 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable, ...@@ -787,11 +787,11 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
if (!(lockMethodTable->conflictTab[lockmode] & bitmask)) if (!(lockMethodTable->conflictTab[lockmode] & bitmask))
{ {
/* no conflict. OK to get the lock */ /* no conflict. OK to get the lock */
PROCLOCK_PRINT("LockCheckConflicts: resolved", holder); PROCLOCK_PRINT("LockCheckConflicts: resolved", proclock);
return STATUS_OK; return STATUS_OK;
} }
PROCLOCK_PRINT("LockCheckConflicts: conflicting", holder); PROCLOCK_PRINT("LockCheckConflicts: conflicting", proclock);
return STATUS_FOUND; return STATUS_FOUND;
} }
...@@ -809,36 +809,36 @@ static void ...@@ -809,36 +809,36 @@ static void
LockCountMyLocks(SHMEM_OFFSET lockOffset, PGPROC *proc, int *myHolding) LockCountMyLocks(SHMEM_OFFSET lockOffset, PGPROC *proc, int *myHolding)
{ {
SHM_QUEUE *procHolders = &(proc->procHolders); SHM_QUEUE *procHolders = &(proc->procHolders);
PROCLOCK *holder; PROCLOCK *proclock;
int i; int i;
MemSet(myHolding, 0, MAX_LOCKMODES * sizeof(int)); MemSet(myHolding, 0, MAX_LOCKMODES * sizeof(int));
holder = (PROCLOCK *) SHMQueueNext(procHolders, procHolders, proclock = (PROCLOCK *) SHMQueueNext(procHolders, procHolders,
offsetof(PROCLOCK, procLink)); offsetof(PROCLOCK, procLink));
while (holder) while (proclock)
{ {
if (lockOffset == holder->tag.lock) if (lockOffset == proclock->tag.lock)
{ {
for (i = 1; i < MAX_LOCKMODES; i++) for (i = 1; i < MAX_LOCKMODES; i++)
myHolding[i] += holder->holding[i]; myHolding[i] += proclock->holding[i];
} }
holder = (PROCLOCK *) SHMQueueNext(procHolders, &holder->procLink, proclock = (PROCLOCK *) SHMQueueNext(procHolders, &proclock->procLink,
offsetof(PROCLOCK, procLink)); offsetof(PROCLOCK, procLink));
} }
} }
/* /*
* GrantLock -- update the lock and holder data structures to show * GrantLock -- update the lock and proclock data structures to show
* the lock request has been granted. * the lock request has been granted.
* *
* NOTE: if proc was blocked, it also needs to be removed from the wait list * NOTE: if proc was blocked, it also needs to be removed from the wait list
* and have its waitLock/waitHolder fields cleared. That's not done here. * and have its waitLock/waitHolder fields cleared. That's not done here.
*/ */
void void
GrantLock(LOCK *lock, PROCLOCK *holder, LOCKMODE lockmode) GrantLock(LOCK *lock, PROCLOCK *proclock, LOCKMODE lockmode)
{ {
lock->nGranted++; lock->nGranted++;
lock->granted[lockmode]++; lock->granted[lockmode]++;
...@@ -848,9 +848,9 @@ GrantLock(LOCK *lock, PROCLOCK *holder, LOCKMODE lockmode) ...@@ -848,9 +848,9 @@ GrantLock(LOCK *lock, PROCLOCK *holder, LOCKMODE lockmode)
LOCK_PRINT("GrantLock", lock, lockmode); LOCK_PRINT("GrantLock", lock, lockmode);
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);
holder->holding[lockmode]++; proclock->holding[lockmode]++;
holder->nHolding++; proclock->nHolding++;
Assert((holder->nHolding > 0) && (holder->holding[lockmode] > 0)); Assert((proclock->nHolding > 0) && (proclock->holding[lockmode] > 0));
} }
/* /*
...@@ -863,7 +863,7 @@ GrantLock(LOCK *lock, PROCLOCK *holder, LOCKMODE lockmode) ...@@ -863,7 +863,7 @@ GrantLock(LOCK *lock, PROCLOCK *holder, LOCKMODE lockmode)
*/ */
static int static int
WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode, WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
LOCK *lock, PROCLOCK *holder) LOCK *lock, PROCLOCK *proclock)
{ {
LOCKMETHODTABLE *lockMethodTable = LockMethodTable[lockmethod]; LOCKMETHODTABLE *lockMethodTable = LockMethodTable[lockmethod];
char *new_status, char *new_status,
...@@ -896,11 +896,11 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode, ...@@ -896,11 +896,11 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
if (ProcSleep(lockMethodTable, if (ProcSleep(lockMethodTable,
lockmode, lockmode,
lock, lock,
holder) != STATUS_OK) proclock) != STATUS_OK)
{ {
/* /*
* We failed as a result of a deadlock, see CheckDeadLock(). Quit * We failed as a result of a deadlock, see CheckDeadLock(). Quit
* now. Removal of the holder and lock objects, if no longer * now. Removal of the proclock 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);
...@@ -930,7 +930,7 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode, ...@@ -930,7 +930,7 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
* *
* Locktable lock must be held by caller. * Locktable lock must be held by caller.
* *
* NB: this does not remove the process' holder object, nor the lock object, * NB: this does not remove the process' proclock object, nor the lock object,
* even though their counts might now have gone to zero. That will happen * even though their counts might now have gone to zero. That will happen
* during a subsequent LockReleaseAll call, which we expect will happen * during a subsequent LockReleaseAll call, which we expect will happen
* during transaction cleanup. (Removal of a proc from its wait queue by * during transaction cleanup. (Removal of a proc from its wait queue by
...@@ -986,9 +986,9 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -986,9 +986,9 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
LOCK *lock; LOCK *lock;
LWLockId masterLock; LWLockId masterLock;
LOCKMETHODTABLE *lockMethodTable; LOCKMETHODTABLE *lockMethodTable;
PROCLOCK *holder; PROCLOCK *proclock;
PROCLOCKTAG holdertag; PROCLOCKTAG proclocktag;
HTAB *holderTable; HTAB *proclockTable;
bool wakeupNeeded = false; bool wakeupNeeded = false;
#ifdef LOCK_DEBUG #ifdef LOCK_DEBUG
...@@ -1031,19 +1031,19 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -1031,19 +1031,19 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
LOCK_PRINT("LockRelease: found", lock, lockmode); LOCK_PRINT("LockRelease: found", lock, lockmode);
/* /*
* Find the holder entry for this holder. * Find the proclock entry for this proclock.
*/ */
MemSet(&holdertag, 0, sizeof(PROCLOCKTAG)); /* must clear padding, MemSet(&proclocktag, 0, sizeof(PROCLOCKTAG)); /* must clear padding,
* needed */ * needed */
holdertag.lock = MAKE_OFFSET(lock); proclocktag.lock = MAKE_OFFSET(lock);
holdertag.proc = MAKE_OFFSET(MyProc); proclocktag.proc = MAKE_OFFSET(MyProc);
TransactionIdStore(xid, &holdertag.xid); TransactionIdStore(xid, &proclocktag.xid);
holderTable = lockMethodTable->holderHash; proclockTable = lockMethodTable->proclockHash;
holder = (PROCLOCK *) hash_search(holderTable, proclock = (PROCLOCK *) hash_search(proclockTable,
(void *) &holdertag, (void *) &proclocktag,
HASH_FIND_SAVE, NULL); HASH_FIND_SAVE, NULL);
if (!holder) if (!proclock)
{ {
LWLockRelease(masterLock); LWLockRelease(masterLock);
#ifdef USER_LOCKS #ifdef USER_LOCKS
...@@ -1051,25 +1051,25 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -1051,25 +1051,25 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
elog(WARNING, "LockRelease: no lock with this tag"); elog(WARNING, "LockRelease: no lock with this tag");
else else
#endif #endif
elog(WARNING, "LockRelease: holder table corrupted"); elog(WARNING, "LockRelease: proclock table corrupted");
return FALSE; return FALSE;
} }
PROCLOCK_PRINT("LockRelease: found", holder); PROCLOCK_PRINT("LockRelease: found", proclock);
/* /*
* Check that we are actually holding a lock of the type we want to * Check that we are actually holding a lock of the type we want to
* release. * release.
*/ */
if (!(holder->holding[lockmode] > 0)) if (!(proclock->holding[lockmode] > 0))
{ {
PROCLOCK_PRINT("LockRelease: WRONGTYPE", holder); PROCLOCK_PRINT("LockRelease: WRONGTYPE", proclock);
Assert(holder->holding[lockmode] >= 0); Assert(proclock->holding[lockmode] >= 0);
LWLockRelease(masterLock); LWLockRelease(masterLock);
elog(WARNING, "LockRelease: you don't own a lock of type %s", elog(WARNING, "LockRelease: you don't own a lock of type %s",
lock_mode_names[lockmode]); lock_mode_names[lockmode]);
return FALSE; return FALSE;
} }
Assert(holder->nHolding > 0); Assert(proclock->nHolding > 0);
Assert((lock->nRequested > 0) && (lock->requested[lockmode] > 0)); Assert((lock->nRequested > 0) && (lock->requested[lockmode] > 0));
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);
...@@ -1126,29 +1126,29 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -1126,29 +1126,29 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
} }
/* /*
* Now fix the per-holder lock stats. * Now fix the per-proclock lock stats.
*/ */
holder->holding[lockmode]--; proclock->holding[lockmode]--;
holder->nHolding--; proclock->nHolding--;
PROCLOCK_PRINT("LockRelease: updated", holder); PROCLOCK_PRINT("LockRelease: updated", proclock);
Assert((holder->nHolding >= 0) && (holder->holding[lockmode] >= 0)); Assert((proclock->nHolding >= 0) && (proclock->holding[lockmode] >= 0));
/* /*
* If this was my last hold on this lock, delete my entry in the * If this was my last hold on this lock, delete my entry in the
* holder table. * proclock table.
*/ */
if (holder->nHolding == 0) if (proclock->nHolding == 0)
{ {
PROCLOCK_PRINT("LockRelease: deleting", holder); PROCLOCK_PRINT("LockRelease: deleting", proclock);
SHMQueueDelete(&holder->lockLink); SHMQueueDelete(&proclock->lockLink);
SHMQueueDelete(&holder->procLink); SHMQueueDelete(&proclock->procLink);
holder = (PROCLOCK *) hash_search(holderTable, proclock = (PROCLOCK *) hash_search(proclockTable,
(void *) &holder, (void *) &proclock,
HASH_REMOVE_SAVED, NULL); HASH_REMOVE_SAVED, NULL);
if (!holder) if (!proclock)
{ {
LWLockRelease(masterLock); LWLockRelease(masterLock);
elog(WARNING, "LockRelease: remove holder, table corrupted"); elog(WARNING, "LockRelease: remove proclock, table corrupted");
return FALSE; return FALSE;
} }
} }
...@@ -1179,7 +1179,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, ...@@ -1179,7 +1179,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc,
bool allxids, TransactionId xid) bool allxids, TransactionId xid)
{ {
SHM_QUEUE *procHolders = &(proc->procHolders); SHM_QUEUE *procHolders = &(proc->procHolders);
PROCLOCK *holder; PROCLOCK *proclock;
PROCLOCK *nextHolder; PROCLOCK *nextHolder;
LWLockId masterLock; LWLockId masterLock;
LOCKMETHODTABLE *lockMethodTable; LOCKMETHODTABLE *lockMethodTable;
...@@ -1206,49 +1206,49 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, ...@@ -1206,49 +1206,49 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc,
LWLockAcquire(masterLock, LW_EXCLUSIVE); LWLockAcquire(masterLock, LW_EXCLUSIVE);
holder = (PROCLOCK *) SHMQueueNext(procHolders, procHolders, proclock = (PROCLOCK *) SHMQueueNext(procHolders, procHolders,
offsetof(PROCLOCK, procLink)); offsetof(PROCLOCK, procLink));
while (holder) while (proclock)
{ {
bool wakeupNeeded = false; bool wakeupNeeded = false;
/* Get link first, since we may unlink/delete this holder */ /* Get link first, since we may unlink/delete this proclock */
nextHolder = (PROCLOCK *) SHMQueueNext(procHolders, &holder->procLink, nextHolder = (PROCLOCK *) SHMQueueNext(procHolders, &proclock->procLink,
offsetof(PROCLOCK, procLink)); offsetof(PROCLOCK, procLink));
Assert(holder->tag.proc == MAKE_OFFSET(proc)); Assert(proclock->tag.proc == MAKE_OFFSET(proc));
lock = (LOCK *) MAKE_PTR(holder->tag.lock); lock = (LOCK *) MAKE_PTR(proclock->tag.lock);
/* Ignore items that are not of the lockmethod to be removed */ /* Ignore items that are not of the lockmethod to be removed */
if (LOCK_LOCKMETHOD(*lock) != lockmethod) if (LOCK_LOCKMETHOD(*lock) != lockmethod)
goto next_item; goto next_item;
/* If not allxids, ignore items that are of the wrong xid */ /* If not allxids, ignore items that are of the wrong xid */
if (!allxids && !TransactionIdEquals(xid, holder->tag.xid)) if (!allxids && !TransactionIdEquals(xid, proclock->tag.xid))
goto next_item; goto next_item;
PROCLOCK_PRINT("LockReleaseAll", holder); PROCLOCK_PRINT("LockReleaseAll", proclock);
LOCK_PRINT("LockReleaseAll", lock, 0); LOCK_PRINT("LockReleaseAll", lock, 0);
Assert(lock->nRequested >= 0); Assert(lock->nRequested >= 0);
Assert(lock->nGranted >= 0); Assert(lock->nGranted >= 0);
Assert(lock->nGranted <= lock->nRequested); Assert(lock->nGranted <= lock->nRequested);
Assert(holder->nHolding >= 0); Assert(proclock->nHolding >= 0);
Assert(holder->nHolding <= lock->nRequested); Assert(proclock->nHolding <= lock->nRequested);
/* /*
* fix the general lock stats * fix the general lock stats
*/ */
if (lock->nRequested != holder->nHolding) if (lock->nRequested != proclock->nHolding)
{ {
for (i = 1; i <= numLockModes; i++) for (i = 1; i <= numLockModes; i++)
{ {
Assert(holder->holding[i] >= 0); Assert(proclock->holding[i] >= 0);
if (holder->holding[i] > 0) if (proclock->holding[i] > 0)
{ {
lock->requested[i] -= holder->holding[i]; lock->requested[i] -= proclock->holding[i];
lock->granted[i] -= holder->holding[i]; lock->granted[i] -= proclock->holding[i];
Assert(lock->requested[i] >= 0 && lock->granted[i] >= 0); Assert(lock->requested[i] >= 0 && lock->granted[i] >= 0);
if (lock->granted[i] == 0) if (lock->granted[i] == 0)
lock->grantMask &= BITS_OFF[i]; lock->grantMask &= BITS_OFF[i];
...@@ -1261,15 +1261,15 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, ...@@ -1261,15 +1261,15 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc,
wakeupNeeded = true; wakeupNeeded = true;
} }
} }
lock->nRequested -= holder->nHolding; lock->nRequested -= proclock->nHolding;
lock->nGranted -= holder->nHolding; lock->nGranted -= proclock->nHolding;
Assert((lock->nRequested >= 0) && (lock->nGranted >= 0)); Assert((lock->nRequested >= 0) && (lock->nGranted >= 0));
Assert(lock->nGranted <= lock->nRequested); Assert(lock->nGranted <= lock->nRequested);
} }
else else
{ {
/* /*
* This holder accounts for all the requested locks on the * This proclock accounts for all the requested locks on the
* object, so we can be lazy and just zero things out. * object, so we can be lazy and just zero things out.
*/ */
lock->nRequested = 0; lock->nRequested = 0;
...@@ -1283,25 +1283,25 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, ...@@ -1283,25 +1283,25 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc,
} }
LOCK_PRINT("LockReleaseAll: updated", lock, 0); LOCK_PRINT("LockReleaseAll: updated", lock, 0);
PROCLOCK_PRINT("LockReleaseAll: deleting", holder); PROCLOCK_PRINT("LockReleaseAll: deleting", proclock);
/* /*
* Remove the holder entry from the linked lists * Remove the proclock entry from the linked lists
*/ */
SHMQueueDelete(&holder->lockLink); SHMQueueDelete(&proclock->lockLink);
SHMQueueDelete(&holder->procLink); SHMQueueDelete(&proclock->procLink);
/* /*
* remove the holder entry from the hashtable * remove the proclock entry from the hashtable
*/ */
holder = (PROCLOCK *) hash_search(lockMethodTable->holderHash, proclock = (PROCLOCK *) hash_search(lockMethodTable->proclockHash,
(void *) holder, (void *) proclock,
HASH_REMOVE, HASH_REMOVE,
NULL); NULL);
if (!holder) if (!proclock)
{ {
LWLockRelease(masterLock); LWLockRelease(masterLock);
elog(WARNING, "LockReleaseAll: holder table corrupted"); elog(WARNING, "LockReleaseAll: proclock table corrupted");
return FALSE; return FALSE;
} }
...@@ -1327,7 +1327,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, ...@@ -1327,7 +1327,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc,
ProcLockWakeup(lockMethodTable, lock); ProcLockWakeup(lockMethodTable, lock);
next_item: next_item:
holder = nextHolder; proclock = nextHolder;
} }
LWLockRelease(masterLock); LWLockRelease(masterLock);
...@@ -1353,7 +1353,7 @@ LockShmemSize(int maxBackends) ...@@ -1353,7 +1353,7 @@ LockShmemSize(int maxBackends)
/* lockHash table */ /* lockHash table */
size += hash_estimate_size(max_table_size, sizeof(LOCK)); size += hash_estimate_size(max_table_size, sizeof(LOCK));
/* holderHash table */ /* proclockHash table */
size += hash_estimate_size(max_table_size, sizeof(PROCLOCK)); size += hash_estimate_size(max_table_size, sizeof(PROCLOCK));
/* /*
...@@ -1383,8 +1383,8 @@ LockData * ...@@ -1383,8 +1383,8 @@ LockData *
GetLockStatusData(void) GetLockStatusData(void)
{ {
LockData *data; LockData *data;
HTAB *holderTable; HTAB *proclockTable;
PROCLOCK *holder; PROCLOCK *proclock;
HASH_SEQ_STATUS seqstat; HASH_SEQ_STATUS seqstat;
int i; int i;
...@@ -1392,28 +1392,28 @@ GetLockStatusData(void) ...@@ -1392,28 +1392,28 @@ GetLockStatusData(void)
LWLockAcquire(LockMgrLock, LW_EXCLUSIVE); LWLockAcquire(LockMgrLock, LW_EXCLUSIVE);
holderTable = LockMethodTable[DEFAULT_LOCKMETHOD]->holderHash; proclockTable = LockMethodTable[DEFAULT_LOCKMETHOD]->proclockHash;
data->nelements = i = holderTable->hctl->nentries; data->nelements = i = proclockTable->hctl->nentries;
if (i == 0) if (i == 0)
i = 1; /* avoid palloc(0) if empty table */ i = 1; /* avoid palloc(0) if empty table */
data->holderaddrs = (SHMEM_OFFSET *) palloc(sizeof(SHMEM_OFFSET) * i); data->proclockaddrs = (SHMEM_OFFSET *) palloc(sizeof(SHMEM_OFFSET) * i);
data->holders = (PROCLOCK *) palloc(sizeof(PROCLOCK) * i); data->proclocks = (PROCLOCK *) palloc(sizeof(PROCLOCK) * i);
data->procs = (PGPROC *) palloc(sizeof(PGPROC) * i); data->procs = (PGPROC *) palloc(sizeof(PGPROC) * i);
data->locks = (LOCK *) palloc(sizeof(LOCK) * i); data->locks = (LOCK *) palloc(sizeof(LOCK) * i);
hash_seq_init(&seqstat, holderTable); hash_seq_init(&seqstat, proclockTable);
i = 0; i = 0;
while ((holder = hash_seq_search(&seqstat))) while ((proclock = hash_seq_search(&seqstat)))
{ {
PGPROC *proc = (PGPROC *) MAKE_PTR(holder->tag.proc); PGPROC *proc = (PGPROC *) MAKE_PTR(proclock->tag.proc);
LOCK *lock = (LOCK *) MAKE_PTR(holder->tag.lock); LOCK *lock = (LOCK *) MAKE_PTR(proclock->tag.lock);
data->holderaddrs[i] = MAKE_OFFSET(holder); data->proclockaddrs[i] = MAKE_OFFSET(proclock);
memcpy(&(data->holders[i]), holder, sizeof(PROCLOCK)); memcpy(&(data->proclocks[i]), proclock, sizeof(PROCLOCK));
memcpy(&(data->procs[i]), proc, sizeof(PGPROC)); memcpy(&(data->procs[i]), proc, sizeof(PGPROC));
memcpy(&(data->locks[i]), lock, sizeof(LOCK)); memcpy(&(data->locks[i]), lock, sizeof(LOCK));
...@@ -1446,7 +1446,7 @@ DumpLocks(void) ...@@ -1446,7 +1446,7 @@ DumpLocks(void)
{ {
PGPROC *proc; PGPROC *proc;
SHM_QUEUE *procHolders; SHM_QUEUE *procHolders;
PROCLOCK *holder; PROCLOCK *proclock;
LOCK *lock; LOCK *lock;
int lockmethod = DEFAULT_LOCKMETHOD; int lockmethod = DEFAULT_LOCKMETHOD;
LOCKMETHODTABLE *lockMethodTable; LOCKMETHODTABLE *lockMethodTable;
...@@ -1465,19 +1465,19 @@ DumpLocks(void) ...@@ -1465,19 +1465,19 @@ DumpLocks(void)
if (proc->waitLock) if (proc->waitLock)
LOCK_PRINT("DumpLocks: waiting on", proc->waitLock, 0); LOCK_PRINT("DumpLocks: waiting on", proc->waitLock, 0);
holder = (PROCLOCK *) SHMQueueNext(procHolders, procHolders, proclock = (PROCLOCK *) SHMQueueNext(procHolders, procHolders,
offsetof(PROCLOCK, procLink)); offsetof(PROCLOCK, procLink));
while (holder) while (proclock)
{ {
Assert(holder->tag.proc == MAKE_OFFSET(proc)); Assert(proclock->tag.proc == MAKE_OFFSET(proc));
lock = (LOCK *) MAKE_PTR(holder->tag.lock); lock = (LOCK *) MAKE_PTR(proclock->tag.lock);
PROCLOCK_PRINT("DumpLocks", holder); PROCLOCK_PRINT("DumpLocks", proclock);
LOCK_PRINT("DumpLocks", lock, 0); LOCK_PRINT("DumpLocks", lock, 0);
holder = (PROCLOCK *) SHMQueueNext(procHolders, &holder->procLink, proclock = (PROCLOCK *) SHMQueueNext(procHolders, &proclock->procLink,
offsetof(PROCLOCK, procLink)); offsetof(PROCLOCK, procLink));
} }
} }
...@@ -1489,11 +1489,11 @@ void ...@@ -1489,11 +1489,11 @@ void
DumpAllLocks(void) DumpAllLocks(void)
{ {
PGPROC *proc; PGPROC *proc;
PROCLOCK *holder; PROCLOCK *proclock;
LOCK *lock; LOCK *lock;
int lockmethod = DEFAULT_LOCKMETHOD; int lockmethod = DEFAULT_LOCKMETHOD;
LOCKMETHODTABLE *lockMethodTable; LOCKMETHODTABLE *lockMethodTable;
HTAB *holderTable; HTAB *proclockTable;
HASH_SEQ_STATUS status; HASH_SEQ_STATUS status;
proc = MyProc; proc = MyProc;
...@@ -1505,23 +1505,23 @@ DumpAllLocks(void) ...@@ -1505,23 +1505,23 @@ DumpAllLocks(void)
if (!lockMethodTable) if (!lockMethodTable)
return; return;
holderTable = lockMethodTable->holderHash; proclockTable = lockMethodTable->proclockHash;
if (proc->waitLock) if (proc->waitLock)
LOCK_PRINT("DumpAllLocks: waiting on", proc->waitLock, 0); LOCK_PRINT("DumpAllLocks: waiting on", proc->waitLock, 0);
hash_seq_init(&status, holderTable); hash_seq_init(&status, proclockTable);
while ((holder = (PROCLOCK *) hash_seq_search(&status)) != NULL) while ((proclock = (PROCLOCK *) hash_seq_search(&status)) != NULL)
{ {
PROCLOCK_PRINT("DumpAllLocks", holder); PROCLOCK_PRINT("DumpAllLocks", proclock);
if (holder->tag.lock) if (proclock->tag.lock)
{ {
lock = (LOCK *) MAKE_PTR(holder->tag.lock); lock = (LOCK *) MAKE_PTR(proclock->tag.lock);
LOCK_PRINT("DumpAllLocks", lock, 0); LOCK_PRINT("DumpAllLocks", lock, 0);
} }
else else
elog(LOG, "DumpAllLocks: holder->tag.lock = NULL"); elog(LOG, "DumpAllLocks: proclock->tag.lock = NULL");
} }
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.128 2003/01/16 21:01:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.129 2003/02/18 02:13:24 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -521,7 +521,7 @@ int ...@@ -521,7 +521,7 @@ int
ProcSleep(LOCKMETHODTABLE *lockMethodTable, ProcSleep(LOCKMETHODTABLE *lockMethodTable,
LOCKMODE lockmode, LOCKMODE lockmode,
LOCK *lock, LOCK *lock,
PROCLOCK *holder) PROCLOCK *proclock)
{ {
LWLockId masterLock = lockMethodTable->masterLock; LWLockId masterLock = lockMethodTable->masterLock;
PROC_QUEUE *waitQueue = &(lock->waitProcs); PROC_QUEUE *waitQueue = &(lock->waitProcs);
...@@ -577,12 +577,12 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable, ...@@ -577,12 +577,12 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable,
LockCheckConflicts(lockMethodTable, LockCheckConflicts(lockMethodTable,
lockmode, lockmode,
lock, lock,
holder, proclock,
MyProc, MyProc,
NULL) == STATUS_OK) NULL) == STATUS_OK)
{ {
/* Skip the wait and just grant myself the lock. */ /* Skip the wait and just grant myself the lock. */
GrantLock(lock, holder, lockmode); GrantLock(lock, proclock, lockmode);
return STATUS_OK; return STATUS_OK;
} }
/* Break out of loop to put myself before him */ /* Break out of loop to put myself before him */
...@@ -615,7 +615,7 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable, ...@@ -615,7 +615,7 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable,
/* Set up wait information in PGPROC object, too */ /* Set up wait information in PGPROC object, too */
MyProc->waitLock = lock; MyProc->waitLock = lock;
MyProc->waitHolder = holder; MyProc->waitHolder = proclock;
MyProc->waitLockMode = lockmode; MyProc->waitLockMode = lockmode;
MyProc->errType = STATUS_OK; /* initialize result for success */ MyProc->errType = STATUS_OK; /* initialize result for success */
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright (c) 2002, PostgreSQL Global Development Group * Copyright (c) 2002, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/lockfuncs.c,v 1.7 2002/09/04 20:31:28 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/lockfuncs.c,v 1.8 2003/02/18 02:13:24 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -88,7 +88,7 @@ pg_lock_status(PG_FUNCTION_ARGS) ...@@ -88,7 +88,7 @@ pg_lock_status(PG_FUNCTION_ARGS)
while (mystatus->currIdx < lockData->nelements) while (mystatus->currIdx < lockData->nelements)
{ {
PROCLOCK *holder; PROCLOCK *proclock;
LOCK *lock; LOCK *lock;
PGPROC *proc; PGPROC *proc;
bool granted; bool granted;
...@@ -98,7 +98,7 @@ pg_lock_status(PG_FUNCTION_ARGS) ...@@ -98,7 +98,7 @@ pg_lock_status(PG_FUNCTION_ARGS)
HeapTuple tuple; HeapTuple tuple;
Datum result; Datum result;
holder = &(lockData->holders[mystatus->currIdx]); proclock = &(lockData->proclocks[mystatus->currIdx]);
lock = &(lockData->locks[mystatus->currIdx]); lock = &(lockData->locks[mystatus->currIdx]);
proc = &(lockData->procs[mystatus->currIdx]); proc = &(lockData->procs[mystatus->currIdx]);
...@@ -110,10 +110,10 @@ pg_lock_status(PG_FUNCTION_ARGS) ...@@ -110,10 +110,10 @@ pg_lock_status(PG_FUNCTION_ARGS)
granted = false; granted = false;
for (mode = 0; mode < MAX_LOCKMODES; mode++) for (mode = 0; mode < MAX_LOCKMODES; mode++)
{ {
if (holder->holding[mode] > 0) if (proclock->holding[mode] > 0)
{ {
granted = true; granted = true;
holder->holding[mode] = 0; proclock->holding[mode] = 0;
break; break;
} }
} }
...@@ -124,7 +124,7 @@ pg_lock_status(PG_FUNCTION_ARGS) ...@@ -124,7 +124,7 @@ pg_lock_status(PG_FUNCTION_ARGS)
*/ */
if (!granted) if (!granted)
{ {
if (proc->waitLock == (LOCK *) MAKE_PTR(holder->tag.lock)) if (proc->waitLock == (LOCK *) MAKE_PTR(proclock->tag.lock))
{ {
/* Yes, so report it with proper mode */ /* Yes, so report it with proper mode */
mode = proc->waitLockMode; mode = proc->waitLockMode;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, 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.68 2003/01/16 21:01:45 tgl Exp $ * $Id: lock.h,v 1.69 2003/02/18 02:13:24 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -68,7 +68,7 @@ typedef int LOCKMETHOD; ...@@ -68,7 +68,7 @@ typedef int LOCKMETHOD;
* *
* lockHash -- hash table holding per-locked-object lock information * lockHash -- hash table holding per-locked-object lock information
* *
* holderHash -- hash table holding per-lock-holder lock information * proclockHash -- hash table holding per-lock-waiter/holder lock information
* *
* lockmethod -- the handle used by the lock table's clients to * lockmethod -- the handle used by the lock table's clients to
* refer to the type of lock table being used. * refer to the type of lock table being used.
...@@ -86,7 +86,7 @@ typedef int LOCKMETHOD; ...@@ -86,7 +86,7 @@ typedef int LOCKMETHOD;
typedef struct LOCKMETHODTABLE typedef struct LOCKMETHODTABLE
{ {
HTAB *lockHash; HTAB *lockHash;
HTAB *holderHash; HTAB *proclockHash;
LOCKMETHOD lockmethod; LOCKMETHOD lockmethod;
int numLockModes; int numLockModes;
int conflictTab[MAX_LOCKMODES]; int conflictTab[MAX_LOCKMODES];
...@@ -156,24 +156,25 @@ typedef struct LOCK ...@@ -156,24 +156,25 @@ typedef struct LOCK
/* /*
* We may have several different transactions holding or awaiting locks * We may have several different transactions holding or awaiting locks
* on the same lockable object. We need to store some per-holder information * on the same lockable object. We need to store some per-waiter/holder
* for each such holder (or would-be holder). * information for each such holder (or would-be holder).
* *
* PROCLOCKTAG is the key information needed to look up a PROCLOCK item in the * PROCLOCKTAG is the key information needed to look up a PROCLOCK item in the
* holder hashtable. A PROCLOCKTAG value uniquely identifies a lock holder. * proclock hashtable. A PROCLOCKTAG value uniquely identifies a lock
* holder/waiter.
* *
* There are two possible kinds of holder tags: a transaction (identified * There are two possible kinds of proclock tags: a transaction (identified
* both by the PGPROC of the backend running it, and the xact's own ID) and * both by the PGPROC of the backend running it, and the xact's own ID) and
* a session (identified by backend PGPROC, with xid = InvalidTransactionId). * a session (identified by backend PGPROC, with xid = InvalidTransactionId).
* *
* Currently, session holders are used for user locks and for cross-xact * Currently, session proclocks are used for user locks and for cross-xact
* locks obtained for VACUUM. We assume that a session lock never conflicts * locks obtained for VACUUM. We assume that a session lock never conflicts
* with per-transaction locks obtained by the same backend. * with per-transaction locks obtained by the same backend.
* *
* The holding[] array counts the granted locks (of each type) represented * The holding[] array counts the granted locks (of each type) represented
* by this holder. Note that there will be a holder object, possibly with * by this proclock. Note that there will be a proclock object, possibly with
* zero holding[], for any lock that the process is currently waiting on. * zero holding[], for any lock that the process is currently waiting on.
* Otherwise, holder objects whose counts have gone to zero are recycled * Otherwise, proclock objects whose counts have gone to zero are recycled
* as soon as convenient. * as soon as convenient.
* *
* Each PROCLOCK object is linked into lists for both the associated LOCK object * Each PROCLOCK object is linked into lists for both the associated LOCK object
...@@ -192,17 +193,17 @@ typedef struct PROCLOCKTAG ...@@ -192,17 +193,17 @@ typedef struct PROCLOCKTAG
typedef struct PROCLOCK typedef struct PROCLOCK
{ {
/* tag */ /* tag */
PROCLOCKTAG tag; /* unique identifier of holder object */ PROCLOCKTAG tag; /* unique identifier of proclock object */
/* data */ /* data */
int holding[MAX_LOCKMODES]; /* count of locks currently held */ int holding[MAX_LOCKMODES]; /* count of locks currently held */
int nHolding; /* total of holding[] array */ int nHolding; /* total of holding[] array */
SHM_QUEUE lockLink; /* list link for lock's list of holders */ SHM_QUEUE lockLink; /* list link for lock's list of proclocks */
SHM_QUEUE procLink; /* list link for process's list of holders */ SHM_QUEUE procLink; /* list link for process's list of proclocks */
} PROCLOCK; } PROCLOCK;
#define PROCLOCK_LOCKMETHOD(holder) \ #define PROCLOCK_LOCKMETHOD(proclock) \
(((LOCK *) MAKE_PTR((holder).tag.lock))->tag.lockmethod) (((LOCK *) MAKE_PTR((proclock).tag.lock))->tag.lockmethod)
/* /*
* This struct holds information passed from lmgr internals to the lock * This struct holds information passed from lmgr internals to the lock
...@@ -215,8 +216,8 @@ typedef struct PROCLOCK ...@@ -215,8 +216,8 @@ typedef struct PROCLOCK
typedef struct typedef struct
{ {
int nelements; /* The length of each of the arrays */ int nelements; /* The length of each of the arrays */
SHMEM_OFFSET *holderaddrs; SHMEM_OFFSET *proclockaddrs;
PROCLOCK *holders; PROCLOCK *proclocks;
PGPROC *procs; PGPROC *procs;
LOCK *locks; LOCK *locks;
} LockData; } LockData;
...@@ -237,9 +238,9 @@ extern bool LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, ...@@ -237,9 +238,9 @@ extern bool LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc,
bool allxids, TransactionId xid); bool allxids, TransactionId xid);
extern int LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable, extern int LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
LOCKMODE lockmode, LOCKMODE lockmode,
LOCK *lock, PROCLOCK *holder, PGPROC *proc, LOCK *lock, PROCLOCK *proclock, PGPROC *proc,
int *myHolding); int *myHolding);
extern void GrantLock(LOCK *lock, PROCLOCK *holder, LOCKMODE lockmode); extern void GrantLock(LOCK *lock, PROCLOCK *proclock, LOCKMODE lockmode);
extern void RemoveFromWaitQueue(PGPROC *proc); extern void RemoveFromWaitQueue(PGPROC *proc);
extern int LockShmemSize(int maxBackends); extern int LockShmemSize(int maxBackends);
extern bool DeadLockCheck(PGPROC *proc); extern bool DeadLockCheck(PGPROC *proc);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, 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: proc.h,v 1.62 2002/10/31 21:34:17 tgl Exp $ * $Id: proc.h,v 1.63 2003/02/18 02:13:24 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -102,7 +102,7 @@ extern void ProcReleaseLocks(bool isCommit); ...@@ -102,7 +102,7 @@ extern void ProcReleaseLocks(bool isCommit);
extern void ProcQueueInit(PROC_QUEUE *queue); extern void ProcQueueInit(PROC_QUEUE *queue);
extern int ProcSleep(LOCKMETHODTABLE *lockMethodTable, LOCKMODE lockmode, extern int ProcSleep(LOCKMETHODTABLE *lockMethodTable, LOCKMODE lockmode,
LOCK *lock, PROCLOCK *holder); LOCK *lock, PROCLOCK *proclock);
extern PGPROC *ProcWakeup(PGPROC *proc, int errType); extern PGPROC *ProcWakeup(PGPROC *proc, int errType);
extern void ProcLockWakeup(LOCKMETHODTABLE *lockMethodTable, LOCK *lock); extern void ProcLockWakeup(LOCKMETHODTABLE *lockMethodTable, LOCK *lock);
extern bool LockWaitCancel(void); extern bool LockWaitCancel(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment