*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.97 2001/09/29 21:35:14 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.98 2001/09/30 00:45:47 momjian Exp $
*
* NOTES
* Outside modules can create a lock table and acquire/release
static int WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
- LOCK *lock, PROCLOCK *holder);
+ LOCK *lock, HOLDER *holder);
static void LockCountMyLocks(SHMEM_OFFSET lockOffset, PROC *proc,
int *myHolding);
inline static void
-PROCLOCK_PRINT(const char *where, const PROCLOCK *holderP)
+HOLDER_PRINT(const char *where, const HOLDER *holderP)
{
if (
- (((PROCLOCK_LOCKMETHOD(*holderP) == DEFAULT_LOCKMETHOD && Trace_locks)
- || (PROCLOCK_LOCKMETHOD(*holderP) == USER_LOCKMETHOD && Trace_userlocks))
+ (((HOLDER_LOCKMETHOD(*holderP) == DEFAULT_LOCKMETHOD && Trace_locks)
+ || (HOLDER_LOCKMETHOD(*holderP) == USER_LOCKMETHOD && Trace_userlocks))
&& (((LOCK *) MAKE_PTR(holderP->tag.lock))->tag.relId >= (Oid) Trace_lock_oidmin))
|| (Trace_lock_table && (((LOCK *) MAKE_PTR(holderP->tag.lock))->tag.relId == Trace_lock_table))
)
elog(DEBUG,
"%s: holder(%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,
- PROCLOCK_LOCKMETHOD(*(holderP)),
+ HOLDER_LOCKMETHOD(*(holderP)),
holderP->tag.proc, holderP->tag.xid,
holderP->holding[1], holderP->holding[2], holderP->holding[3],
holderP->holding[4], holderP->holding[5], holderP->holding[6],
#else /* not LOCK_DEBUG */
#define LOCK_PRINT(where, lock, type)
-#define PROCLOCK_PRINT(where, holderP)
+#define HOLDER_PRINT(where, holderP)
#endif /* not LOCK_DEBUG */
Assert(lockMethodTable->lockHash->hash == tag_hash);
/*
- * allocate a hash table for PROCLOCK structs. This is used to store
+ * allocate a hash table for HOLDER structs. This is used to store
* per-lock-holder information.
*/
- info.keysize = SHMEM_PROCLOCKTAB_KEYSIZE;
- info.datasize = SHMEM_PROCLOCKTAB_DATASIZE;
+ info.keysize = SHMEM_HOLDERTAB_KEYSIZE;
+ info.datasize = SHMEM_HOLDERTAB_DATASIZE;
info.hash = tag_hash;
hash_flags = (HASH_ELEM | HASH_FUNCTION);
LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
TransactionId xid, LOCKMODE lockmode, bool dontWait)
{
- PROCLOCK *holder;
- PROCLOCKTAG holdertag;
+ HOLDER *holder;
+ HOLDERTAG holdertag;
HTAB *holderTable;
bool found;
LOCK *lock;
/*
* Create the hash key for the holder table.
*/
- MemSet(&holdertag, 0, sizeof(PROCLOCKTAG)); /* must clear padding,
+ MemSet(&holdertag, 0, sizeof(HOLDERTAG)); /* must clear padding,
* needed */
holdertag.lock = MAKE_OFFSET(lock);
holdertag.proc = MAKE_OFFSET(MyProc);
* Find or create a holder entry with this tag
*/
holderTable = lockMethodTable->holderHash;
- holder = (PROCLOCK *) hash_search(holderTable, (Pointer) &holdertag,
+ holder = (HOLDER *) hash_search(holderTable, (Pointer) &holdertag,
HASH_ENTER, &found);
if (!holder)
{
/* Add holder to appropriate lists */
SHMQueueInsertBefore(&lock->lockHolders, &holder->lockLink);
SHMQueueInsertBefore(&MyProc->procHolders, &holder->procLink);
- PROCLOCK_PRINT("LockAcquire: new", holder);
+ HOLDER_PRINT("LockAcquire: new", holder);
}
else
{
- PROCLOCK_PRINT("LockAcquire: found", holder);
+ HOLDER_PRINT("LockAcquire: found", holder);
Assert((holder->nHolding >= 0) && (holder->holding[lockmode] >= 0));
Assert(holder->nHolding <= lock->nGranted);
if (holder->holding[lockmode] > 0)
{
GrantLock(lock, holder, lockmode);
- PROCLOCK_PRINT("LockAcquire: owning", holder);
+ HOLDER_PRINT("LockAcquire: owning", holder);
LWLockRelease(masterLock);
return TRUE;
}
if (myHolding[lockmode] > 0)
{
GrantLock(lock, holder, lockmode);
- PROCLOCK_PRINT("LockAcquire: my other XID owning", holder);
+ HOLDER_PRINT("LockAcquire: my other XID owning", holder);
LWLockRelease(masterLock);
return TRUE;
}
{
SHMQueueDelete(&holder->lockLink);
SHMQueueDelete(&holder->procLink);
- holder = (PROCLOCK *) hash_search(holderTable,
+ holder = (HOLDER *) hash_search(holderTable,
(Pointer) holder,
HASH_REMOVE, &found);
if (!holder || !found)
elog(NOTICE, "LockAcquire: remove holder, table corrupted");
}
else
- PROCLOCK_PRINT("LockAcquire: NHOLDING", holder);
+ HOLDER_PRINT("LockAcquire: NHOLDING", holder);
lock->nRequested--;
lock->requested[lockmode]--;
LOCK_PRINT("LockAcquire: conditional lock failed", lock, lockmode);
*/
if (!((holder->nHolding > 0) && (holder->holding[lockmode] > 0)))
{
- PROCLOCK_PRINT("LockAcquire: INCONSISTENT", holder);
+ HOLDER_PRINT("LockAcquire: INCONSISTENT", holder);
LOCK_PRINT("LockAcquire: INCONSISTENT", lock, lockmode);
/* Should we retry ? */
LWLockRelease(masterLock);
return FALSE;
}
- PROCLOCK_PRINT("LockAcquire: granted", holder);
+ HOLDER_PRINT("LockAcquire: granted", holder);
LOCK_PRINT("LockAcquire: granted", lock, lockmode);
}
LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
LOCKMODE lockmode,
LOCK *lock,
- PROCLOCK *holder,
+ HOLDER *holder,
PROC *proc,
int *myHolding) /* myHolding[] array or NULL */
{
*/
if (!(lockctl->conflictTab[lockmode] & lock->grantMask))
{
- PROCLOCK_PRINT("LockCheckConflicts: no conflict", holder);
+ HOLDER_PRINT("LockCheckConflicts: no conflict", holder);
return STATUS_OK;
}
if (!(lockctl->conflictTab[lockmode] & bitmask))
{
/* no conflict. OK to get the lock */
- PROCLOCK_PRINT("LockCheckConflicts: resolved", holder);
+ HOLDER_PRINT("LockCheckConflicts: resolved", holder);
return STATUS_OK;
}
- PROCLOCK_PRINT("LockCheckConflicts: conflicting", holder);
+ HOLDER_PRINT("LockCheckConflicts: conflicting", holder);
return STATUS_FOUND;
}
LockCountMyLocks(SHMEM_OFFSET lockOffset, PROC *proc, int *myHolding)
{
SHM_QUEUE *procHolders = &(proc->procHolders);
- PROCLOCK *holder;
+ HOLDER *holder;
int i;
MemSet(myHolding, 0, MAX_LOCKMODES * sizeof(int));
- holder = (PROCLOCK *) SHMQueueNext(procHolders, procHolders,
- offsetof(PROCLOCK, procLink));
+ holder = (HOLDER *) SHMQueueNext(procHolders, procHolders,
+ offsetof(HOLDER, procLink));
while (holder)
{
myHolding[i] += holder->holding[i];
}
- holder = (PROCLOCK *) SHMQueueNext(procHolders, &holder->procLink,
- offsetof(PROCLOCK, procLink));
+ holder = (HOLDER *) SHMQueueNext(procHolders, &holder->procLink,
+ offsetof(HOLDER, procLink));
}
}
* and have its waitLock/waitHolder fields cleared. That's not done here.
*/
void
-GrantLock(LOCK *lock, PROCLOCK *holder, LOCKMODE lockmode)
+GrantLock(LOCK *lock, HOLDER *holder, LOCKMODE lockmode)
{
lock->nGranted++;
lock->granted[lockmode]++;
*/
static int
WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
- LOCK *lock, PROCLOCK *holder)
+ LOCK *lock, HOLDER *holder)
{
LOCKMETHODTABLE *lockMethodTable = LockMethodTable[lockmethod];
char *new_status,
LWLockId masterLock;
bool found;
LOCKMETHODTABLE *lockMethodTable;
- PROCLOCK *holder;
- PROCLOCKTAG holdertag;
+ HOLDER *holder;
+ HOLDERTAG holdertag;
HTAB *holderTable;
bool wakeupNeeded = false;
/*
* Find the holder entry for this holder.
*/
- MemSet(&holdertag, 0, sizeof(PROCLOCKTAG)); /* must clear padding,
+ MemSet(&holdertag, 0, sizeof(HOLDERTAG)); /* must clear padding,
* needed */
holdertag.lock = MAKE_OFFSET(lock);
holdertag.proc = MAKE_OFFSET(MyProc);
TransactionIdStore(xid, &holdertag.xid);
holderTable = lockMethodTable->holderHash;
- holder = (PROCLOCK *) hash_search(holderTable, (Pointer) &holdertag,
+ holder = (HOLDER *) hash_search(holderTable, (Pointer) &holdertag,
HASH_FIND_SAVE, &found);
if (!holder || !found)
{
elog(NOTICE, "LockRelease: holder table corrupted");
return FALSE;
}
- PROCLOCK_PRINT("LockRelease: found", holder);
+ HOLDER_PRINT("LockRelease: found", holder);
/*
* Check that we are actually holding a lock of the type we want to
*/
if (!(holder->holding[lockmode] > 0))
{
- PROCLOCK_PRINT("LockRelease: WRONGTYPE", holder);
+ HOLDER_PRINT("LockRelease: WRONGTYPE", holder);
Assert(holder->holding[lockmode] >= 0);
LWLockRelease(masterLock);
elog(NOTICE, "LockRelease: you don't own a lock of type %s",
*/
holder->holding[lockmode]--;
holder->nHolding--;
- PROCLOCK_PRINT("LockRelease: updated", holder);
+ HOLDER_PRINT("LockRelease: updated", holder);
Assert((holder->nHolding >= 0) && (holder->holding[lockmode] >= 0));
/*
*/
if (holder->nHolding == 0)
{
- PROCLOCK_PRINT("LockRelease: deleting", holder);
+ HOLDER_PRINT("LockRelease: deleting", holder);
SHMQueueDelete(&holder->lockLink);
SHMQueueDelete(&holder->procLink);
- holder = (PROCLOCK *) hash_search(holderTable, (Pointer) &holder,
+ holder = (HOLDER *) hash_search(holderTable, (Pointer) &holder,
HASH_REMOVE_SAVED, &found);
if (!holder || !found)
{
bool allxids, TransactionId xid)
{
SHM_QUEUE *procHolders = &(proc->procHolders);
- PROCLOCK *holder;
- PROCLOCK *nextHolder;
+ HOLDER *holder;
+ HOLDER *nextHolder;
LWLockId masterLock;
LOCKMETHODTABLE *lockMethodTable;
int i,
LWLockAcquire(masterLock, LW_EXCLUSIVE);
- holder = (PROCLOCK *) SHMQueueNext(procHolders, procHolders,
- offsetof(PROCLOCK, procLink));
+ holder = (HOLDER *) SHMQueueNext(procHolders, procHolders,
+ offsetof(HOLDER, procLink));
while (holder)
{
bool wakeupNeeded = false;
/* Get link first, since we may unlink/delete this holder */
- nextHolder = (PROCLOCK *) SHMQueueNext(procHolders, &holder->procLink,
- offsetof(PROCLOCK, procLink));
+ nextHolder = (HOLDER *) SHMQueueNext(procHolders, &holder->procLink,
+ offsetof(HOLDER, procLink));
Assert(holder->tag.proc == MAKE_OFFSET(proc));
if (!allxids && !TransactionIdEquals(xid, holder->tag.xid))
goto next_item;
- PROCLOCK_PRINT("LockReleaseAll", holder);
+ HOLDER_PRINT("LockReleaseAll", holder);
LOCK_PRINT("LockReleaseAll", lock, 0);
Assert(lock->nRequested >= 0);
Assert(lock->nGranted >= 0);
}
LOCK_PRINT("LockReleaseAll: updated", lock, 0);
- PROCLOCK_PRINT("LockReleaseAll: deleting", holder);
+ HOLDER_PRINT("LockReleaseAll: deleting", holder);
/*
* Remove the holder entry from the linked lists
/*
* remove the holder entry from the hashtable
*/
- holder = (PROCLOCK *) hash_search(lockMethodTable->holderHash,
+ holder = (HOLDER *) hash_search(lockMethodTable->holderHash,
(Pointer) holder,
HASH_REMOVE,
&found);
/* holderHash table */
size += hash_estimate_size(max_table_size,
- SHMEM_PROCLOCKTAB_KEYSIZE,
- SHMEM_PROCLOCKTAB_DATASIZE);
+ SHMEM_HOLDERTAB_KEYSIZE,
+ SHMEM_HOLDERTAB_DATASIZE);
/*
* Since the lockHash entry count above is only an estimate, add 10%
{
PROC *proc;
SHM_QUEUE *procHolders;
- PROCLOCK *holder;
+ HOLDER *holder;
LOCK *lock;
int lockmethod = DEFAULT_LOCKMETHOD;
LOCKMETHODTABLE *lockMethodTable;
if (proc->waitLock)
LOCK_PRINT("DumpLocks: waiting on", proc->waitLock, 0);
- holder = (PROCLOCK *) SHMQueueNext(procHolders, procHolders,
- offsetof(PROCLOCK, procLink));
+ holder = (HOLDER *) SHMQueueNext(procHolders, procHolders,
+ offsetof(HOLDER, procLink));
while (holder)
{
lock = (LOCK *) MAKE_PTR(holder->tag.lock);
- PROCLOCK_PRINT("DumpLocks", holder);
+ HOLDER_PRINT("DumpLocks", holder);
LOCK_PRINT("DumpLocks", lock, 0);
- holder = (PROCLOCK *) SHMQueueNext(procHolders, &holder->procLink,
- offsetof(PROCLOCK, procLink));
+ holder = (HOLDER *) SHMQueueNext(procHolders, &holder->procLink,
+ offsetof(HOLDER, procLink));
}
}
DumpAllLocks(void)
{
PROC *proc;
- PROCLOCK *holder = NULL;
+ HOLDER *holder = NULL;
LOCK *lock;
int lockmethod = DEFAULT_LOCKMETHOD;
LOCKMETHODTABLE *lockMethodTable;
LOCK_PRINT("DumpAllLocks: waiting on", proc->waitLock, 0);
hash_seq_init(&status, holderTable);
- while ((holder = (PROCLOCK *) hash_seq_search(&status)) &&
- (holder != (PROCLOCK *) TRUE))
+ while ((holder = (HOLDER *) hash_seq_search(&status)) &&
+ (holder != (HOLDER *) TRUE))
{
- PROCLOCK_PRINT("DumpAllLocks", holder);
+ HOLDER_PRINT("DumpAllLocks", holder);
if (holder->tag.lock)
{
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: lock.h,v 1.54 2001/09/29 21:35:14 momjian Exp $
+ * $Id: lock.h,v 1.55 2001/09/30 00:45:48 momjian Exp $
*
*-------------------------------------------------------------------------
*/
* tag -- uniquely identifies the object being locked
* grantMask -- bitmask for all lock types currently granted on this object.
* waitMask -- bitmask for all lock types currently awaited on this object.
- * lockHolders -- list of PROCLOCK objects for this lock.
+ * lockHolders -- list of HOLDER objects for this lock.
* waitProcs -- queue of processes waiting for this lock.
* requested -- count of each lock type currently requested on the lock
* (includes requests already granted!!).
/* data */
int grantMask; /* bitmask for lock types already granted */
int waitMask; /* bitmask for lock types awaited */
- SHM_QUEUE lockHolders; /* list of PROCLOCK objects assoc. with lock */
+ SHM_QUEUE lockHolders; /* list of HOLDER objects assoc. with lock */
PROC_QUEUE waitProcs; /* list of PROC objects waiting on lock */
int requested[MAX_LOCKMODES]; /* counts of requested
* locks */
* on the same lockable object. We need to store some per-holder information
* for each such holder (or would-be holder).
*
- * PROCLOCKTAG is the key information needed to look up a PROCLOCK item in the
- * holder hashtable. A PROCLOCKTAG value uniquely identifies a lock holder.
+ * HOLDERTAG is the key information needed to look up a HOLDER item in the
+ * holder hashtable. A HOLDERTAG value uniquely identifies a lock holder.
*
* There are two possible kinds of holder tags: a transaction (identified
* both by the PROC of the backend running it, and the xact's own ID) and
* Otherwise, holder objects whose counts have gone to zero are recycled
* as soon as convenient.
*
- * Each PROCLOCK object is linked into lists for both the associated LOCK object
- * and the owning PROC object. Note that the PROCLOCK is entered into these
+ * Each HOLDER object is linked into lists for both the associated LOCK object
+ * and the owning PROC object. Note that the HOLDER is entered into these
* lists as soon as it is created, even if no lock has yet been granted.
* A PROC that is waiting for a lock to be granted will also be linked into
* the lock's waitProcs queue.
*/
-typedef struct PROCLOCKTAG
+typedef struct HOLDERTAG
{
SHMEM_OFFSET lock; /* link to per-lockable-object information */
SHMEM_OFFSET proc; /* link to PROC of owning backend */
TransactionId xid; /* xact ID, or InvalidTransactionId */
-} PROCLOCKTAG;
+} HOLDERTAG;
-typedef struct PROCLOCK
+typedef struct HOLDER
{
/* tag */
- PROCLOCKTAG tag; /* unique identifier of holder object */
+ HOLDERTAG tag; /* unique identifier of holder object */
/* data */
int holding[MAX_LOCKMODES]; /* count of locks currently held */
int nHolding; /* total of holding[] array */
SHM_QUEUE lockLink; /* list link for lock's list of holders */
SHM_QUEUE procLink; /* list link for process's list of holders */
-} PROCLOCK;
+} HOLDER;
-#define SHMEM_PROCLOCKTAB_KEYSIZE sizeof(PROCLOCKTAG)
-#define SHMEM_PROCLOCKTAB_DATASIZE (sizeof(PROCLOCK) - SHMEM_PROCLOCKTAB_KEYSIZE)
+#define SHMEM_HOLDERTAB_KEYSIZE sizeof(HOLDERTAG)
+#define SHMEM_HOLDERTAB_DATASIZE (sizeof(HOLDER) - SHMEM_HOLDERTAB_KEYSIZE)
-#define PROCLOCK_LOCKMETHOD(holder) \
+#define HOLDER_LOCKMETHOD(holder) \
(((LOCK *) MAKE_PTR((holder).tag.lock))->tag.lockmethod)
bool allxids, TransactionId xid);
extern int LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
LOCKMODE lockmode,
- LOCK *lock, PROCLOCK *holder, PROC *proc,
+ LOCK *lock, HOLDER *holder, PROC *proc,
int *myHolding);
-extern void GrantLock(LOCK *lock, PROCLOCK *holder, LOCKMODE lockmode);
+extern void GrantLock(LOCK *lock, HOLDER *holder, LOCKMODE lockmode);
extern void RemoveFromWaitQueue(PROC *proc);
extern int LockShmemSize(int maxBackends);
extern bool DeadLockCheck(PROC *proc);