mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Do this TODO item:
* HOLDER/HOLDERTAB rename to PROCLOCK/PROCLOCKTAG (Tom) Didn't use PROCLOCKLINK because it made PROCLOCKLINKTAG too long.
This commit is contained in:
		@@ -12,7 +12,7 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * IDENTIFICATION
 | 
					 * IDENTIFICATION
 | 
				
			||||||
 *	  $Header: /cvsroot/pgsql/src/backend/storage/lmgr/deadlock.c,v 1.4 2001/09/29 04:02:24 tgl Exp $
 | 
					 *	  $Header: /cvsroot/pgsql/src/backend/storage/lmgr/deadlock.c,v 1.5 2001/09/29 21:35:14 momjian Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 *	Interface:
 | 
					 *	Interface:
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
@@ -382,7 +382,7 @@ FindLockCycleRecurse(PROC *checkProc,
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	PROC	   *proc;
 | 
						PROC	   *proc;
 | 
				
			||||||
	LOCK	   *lock;
 | 
						LOCK	   *lock;
 | 
				
			||||||
	HOLDER	   *holder;
 | 
						PROCLOCK	   *holder;
 | 
				
			||||||
	SHM_QUEUE  *lockHolders;
 | 
						SHM_QUEUE  *lockHolders;
 | 
				
			||||||
	LOCKMETHODTABLE *lockMethodTable;
 | 
						LOCKMETHODTABLE *lockMethodTable;
 | 
				
			||||||
	LOCKMETHODCTL *lockctl;
 | 
						LOCKMETHODCTL *lockctl;
 | 
				
			||||||
@@ -434,8 +434,8 @@ FindLockCycleRecurse(PROC *checkProc,
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	lockHolders = &(lock->lockHolders);
 | 
						lockHolders = &(lock->lockHolders);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	holder = (HOLDER *) SHMQueueNext(lockHolders, lockHolders,
 | 
						holder = (PROCLOCK *) SHMQueueNext(lockHolders, lockHolders,
 | 
				
			||||||
									 offsetof(HOLDER, lockLink));
 | 
														 offsetof(PROCLOCK, lockLink));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while (holder)
 | 
						while (holder)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -458,8 +458,8 @@ FindLockCycleRecurse(PROC *checkProc,
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		holder = (HOLDER *) SHMQueueNext(lockHolders, &holder->lockLink,
 | 
							holder = (PROCLOCK *) SHMQueueNext(lockHolders, &holder->lockLink,
 | 
				
			||||||
										 offsetof(HOLDER, lockLink));
 | 
															 offsetof(PROCLOCK, lockLink));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,7 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * IDENTIFICATION
 | 
					 * IDENTIFICATION
 | 
				
			||||||
 *	  $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.96 2001/09/29 04:02:24 tgl Exp $
 | 
					 *	  $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.97 2001/09/29 21:35:14 momjian Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * NOTES
 | 
					 * NOTES
 | 
				
			||||||
 *	  Outside modules can create a lock table and acquire/release
 | 
					 *	  Outside modules can create a lock table and acquire/release
 | 
				
			||||||
@@ -48,7 +48,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, HOLDER *holder);
 | 
							   LOCK *lock, PROCLOCK *holder);
 | 
				
			||||||
static void LockCountMyLocks(SHMEM_OFFSET lockOffset, PROC *proc,
 | 
					static void LockCountMyLocks(SHMEM_OFFSET lockOffset, PROC *proc,
 | 
				
			||||||
				 int *myHolding);
 | 
									 int *myHolding);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -125,18 +125,18 @@ LOCK_PRINT(const char *where, const LOCK *lock, LOCKMODE type)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
inline static void
 | 
					inline static void
 | 
				
			||||||
HOLDER_PRINT(const char *where, const HOLDER *holderP)
 | 
					PROCLOCK_PRINT(const char *where, const PROCLOCK *holderP)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (
 | 
						if (
 | 
				
			||||||
	 (((HOLDER_LOCKMETHOD(*holderP) == DEFAULT_LOCKMETHOD && Trace_locks)
 | 
						 (((PROCLOCK_LOCKMETHOD(*holderP) == DEFAULT_LOCKMETHOD && Trace_locks)
 | 
				
			||||||
	   || (HOLDER_LOCKMETHOD(*holderP) == USER_LOCKMETHOD && Trace_userlocks))
 | 
						   || (PROCLOCK_LOCKMETHOD(*holderP) == USER_LOCKMETHOD && Trace_userlocks))
 | 
				
			||||||
	  && (((LOCK *) MAKE_PTR(holderP->tag.lock))->tag.relId >= (Oid) Trace_lock_oidmin))
 | 
						  && (((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))
 | 
							|| (Trace_lock_table && (((LOCK *) MAKE_PTR(holderP->tag.lock))->tag.relId == Trace_lock_table))
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
		elog(DEBUG,
 | 
							elog(DEBUG,
 | 
				
			||||||
			 "%s: holder(%lx) lock(%lx) tbl(%d) proc(%lx) xid(%u) hold(%d,%d,%d,%d,%d,%d,%d)=%d",
 | 
								 "%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,
 | 
								 where, MAKE_OFFSET(holderP), holderP->tag.lock,
 | 
				
			||||||
			 HOLDER_LOCKMETHOD(*(holderP)),
 | 
								 PROCLOCK_LOCKMETHOD(*(holderP)),
 | 
				
			||||||
			 holderP->tag.proc, holderP->tag.xid,
 | 
								 holderP->tag.proc, holderP->tag.xid,
 | 
				
			||||||
		   holderP->holding[1], holderP->holding[2], holderP->holding[3],
 | 
							   holderP->holding[1], holderP->holding[2], holderP->holding[3],
 | 
				
			||||||
		   holderP->holding[4], holderP->holding[5], holderP->holding[6],
 | 
							   holderP->holding[4], holderP->holding[5], holderP->holding[6],
 | 
				
			||||||
@@ -146,7 +146,7 @@ HOLDER_PRINT(const char *where, const HOLDER *holderP)
 | 
				
			|||||||
#else							/* not LOCK_DEBUG */
 | 
					#else							/* not LOCK_DEBUG */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define LOCK_PRINT(where, lock, type)
 | 
					#define LOCK_PRINT(where, lock, type)
 | 
				
			||||||
#define HOLDER_PRINT(where, holderP)
 | 
					#define PROCLOCK_PRINT(where, holderP)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif	 /* not LOCK_DEBUG */
 | 
					#endif	 /* not LOCK_DEBUG */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -325,11 +325,11 @@ LockMethodTableInit(char *tabName,
 | 
				
			|||||||
	Assert(lockMethodTable->lockHash->hash == tag_hash);
 | 
						Assert(lockMethodTable->lockHash->hash == tag_hash);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * allocate a hash table for HOLDER structs.  This is used to store
 | 
						 * allocate a hash table for PROCLOCK structs.  This is used to store
 | 
				
			||||||
	 * per-lock-holder information.
 | 
						 * per-lock-holder information.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	info.keysize = SHMEM_HOLDERTAB_KEYSIZE;
 | 
						info.keysize = SHMEM_PROCLOCKTAB_KEYSIZE;
 | 
				
			||||||
	info.datasize = SHMEM_HOLDERTAB_DATASIZE;
 | 
						info.datasize = SHMEM_PROCLOCKTAB_DATASIZE;
 | 
				
			||||||
	info.hash = tag_hash;
 | 
						info.hash = tag_hash;
 | 
				
			||||||
	hash_flags = (HASH_ELEM | HASH_FUNCTION);
 | 
						hash_flags = (HASH_ELEM | HASH_FUNCTION);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -449,8 +449,8 @@ bool
 | 
				
			|||||||
LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
 | 
					LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
 | 
				
			||||||
			TransactionId xid, LOCKMODE lockmode, bool dontWait)
 | 
								TransactionId xid, LOCKMODE lockmode, bool dontWait)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	HOLDER	   *holder;
 | 
						PROCLOCK	   *holder;
 | 
				
			||||||
	HOLDERTAG	holdertag;
 | 
						PROCLOCKTAG	holdertag;
 | 
				
			||||||
	HTAB	   *holderTable;
 | 
						HTAB	   *holderTable;
 | 
				
			||||||
	bool		found;
 | 
						bool		found;
 | 
				
			||||||
	LOCK	   *lock;
 | 
						LOCK	   *lock;
 | 
				
			||||||
@@ -520,7 +520,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
 | 
				
			|||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Create the hash key for the holder table.
 | 
						 * Create the hash key for the holder table.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	MemSet(&holdertag, 0, sizeof(HOLDERTAG));	/* must clear padding,
 | 
						MemSet(&holdertag, 0, sizeof(PROCLOCKTAG));	/* must clear padding,
 | 
				
			||||||
												 * needed */
 | 
																	 * needed */
 | 
				
			||||||
	holdertag.lock = MAKE_OFFSET(lock);
 | 
						holdertag.lock = MAKE_OFFSET(lock);
 | 
				
			||||||
	holdertag.proc = MAKE_OFFSET(MyProc);
 | 
						holdertag.proc = MAKE_OFFSET(MyProc);
 | 
				
			||||||
@@ -530,7 +530,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
 | 
				
			|||||||
	 * Find or create a holder entry with this tag
 | 
						 * Find or create a holder entry with this tag
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	holderTable = lockMethodTable->holderHash;
 | 
						holderTable = lockMethodTable->holderHash;
 | 
				
			||||||
	holder = (HOLDER *) hash_search(holderTable, (Pointer) &holdertag,
 | 
						holder = (PROCLOCK *) hash_search(holderTable, (Pointer) &holdertag,
 | 
				
			||||||
									HASH_ENTER, &found);
 | 
														HASH_ENTER, &found);
 | 
				
			||||||
	if (!holder)
 | 
						if (!holder)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -549,11 +549,11 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
 | 
				
			|||||||
		/* Add holder to appropriate lists */
 | 
							/* Add holder to appropriate lists */
 | 
				
			||||||
		SHMQueueInsertBefore(&lock->lockHolders, &holder->lockLink);
 | 
							SHMQueueInsertBefore(&lock->lockHolders, &holder->lockLink);
 | 
				
			||||||
		SHMQueueInsertBefore(&MyProc->procHolders, &holder->procLink);
 | 
							SHMQueueInsertBefore(&MyProc->procHolders, &holder->procLink);
 | 
				
			||||||
		HOLDER_PRINT("LockAcquire: new", holder);
 | 
							PROCLOCK_PRINT("LockAcquire: new", holder);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		HOLDER_PRINT("LockAcquire: found", holder);
 | 
							PROCLOCK_PRINT("LockAcquire: found", holder);
 | 
				
			||||||
		Assert((holder->nHolding >= 0) && (holder->holding[lockmode] >= 0));
 | 
							Assert((holder->nHolding >= 0) && (holder->holding[lockmode] >= 0));
 | 
				
			||||||
		Assert(holder->nHolding <= lock->nGranted);
 | 
							Assert(holder->nHolding <= lock->nGranted);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -606,7 +606,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
 | 
				
			|||||||
	if (holder->holding[lockmode] > 0)
 | 
						if (holder->holding[lockmode] > 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		GrantLock(lock, holder, lockmode);
 | 
							GrantLock(lock, holder, lockmode);
 | 
				
			||||||
		HOLDER_PRINT("LockAcquire: owning", holder);
 | 
							PROCLOCK_PRINT("LockAcquire: owning", holder);
 | 
				
			||||||
		LWLockRelease(masterLock);
 | 
							LWLockRelease(masterLock);
 | 
				
			||||||
		return TRUE;
 | 
							return TRUE;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -619,7 +619,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
 | 
				
			|||||||
	if (myHolding[lockmode] > 0)
 | 
						if (myHolding[lockmode] > 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		GrantLock(lock, holder, lockmode);
 | 
							GrantLock(lock, holder, lockmode);
 | 
				
			||||||
		HOLDER_PRINT("LockAcquire: my other XID owning", holder);
 | 
							PROCLOCK_PRINT("LockAcquire: my other XID owning", holder);
 | 
				
			||||||
		LWLockRelease(masterLock);
 | 
							LWLockRelease(masterLock);
 | 
				
			||||||
		return TRUE;
 | 
							return TRUE;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -654,14 +654,14 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
 | 
				
			|||||||
			{
 | 
								{
 | 
				
			||||||
				SHMQueueDelete(&holder->lockLink);
 | 
									SHMQueueDelete(&holder->lockLink);
 | 
				
			||||||
				SHMQueueDelete(&holder->procLink);
 | 
									SHMQueueDelete(&holder->procLink);
 | 
				
			||||||
				holder = (HOLDER *) hash_search(holderTable,
 | 
									holder = (PROCLOCK *) hash_search(holderTable,
 | 
				
			||||||
												(Pointer) holder,
 | 
																	(Pointer) holder,
 | 
				
			||||||
												HASH_REMOVE, &found);
 | 
																	HASH_REMOVE, &found);
 | 
				
			||||||
				if (!holder || !found)
 | 
									if (!holder || !found)
 | 
				
			||||||
					elog(NOTICE, "LockAcquire: remove holder, table corrupted");
 | 
										elog(NOTICE, "LockAcquire: remove holder, table corrupted");
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else
 | 
								else
 | 
				
			||||||
				HOLDER_PRINT("LockAcquire: NHOLDING", holder);
 | 
									PROCLOCK_PRINT("LockAcquire: NHOLDING", holder);
 | 
				
			||||||
			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);
 | 
				
			||||||
@@ -706,13 +706,13 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
 | 
				
			|||||||
		 */
 | 
							 */
 | 
				
			||||||
		if (!((holder->nHolding > 0) && (holder->holding[lockmode] > 0)))
 | 
							if (!((holder->nHolding > 0) && (holder->holding[lockmode] > 0)))
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			HOLDER_PRINT("LockAcquire: INCONSISTENT", holder);
 | 
								PROCLOCK_PRINT("LockAcquire: INCONSISTENT", holder);
 | 
				
			||||||
			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;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		HOLDER_PRINT("LockAcquire: granted", holder);
 | 
							PROCLOCK_PRINT("LockAcquire: granted", holder);
 | 
				
			||||||
		LOCK_PRINT("LockAcquire: granted", lock, lockmode);
 | 
							LOCK_PRINT("LockAcquire: granted", lock, lockmode);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -741,7 +741,7 @@ int
 | 
				
			|||||||
LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
 | 
					LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
 | 
				
			||||||
				   LOCKMODE lockmode,
 | 
									   LOCKMODE lockmode,
 | 
				
			||||||
				   LOCK *lock,
 | 
									   LOCK *lock,
 | 
				
			||||||
				   HOLDER *holder,
 | 
									   PROCLOCK *holder,
 | 
				
			||||||
				   PROC *proc,
 | 
									   PROC *proc,
 | 
				
			||||||
				   int *myHolding)		/* myHolding[] array or NULL */
 | 
									   int *myHolding)		/* myHolding[] array or NULL */
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -763,7 +763,7 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (!(lockctl->conflictTab[lockmode] & lock->grantMask))
 | 
						if (!(lockctl->conflictTab[lockmode] & lock->grantMask))
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		HOLDER_PRINT("LockCheckConflicts: no conflict", holder);
 | 
							PROCLOCK_PRINT("LockCheckConflicts: no conflict", holder);
 | 
				
			||||||
		return STATUS_OK;
 | 
							return STATUS_OK;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -797,11 +797,11 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
 | 
				
			|||||||
	if (!(lockctl->conflictTab[lockmode] & bitmask))
 | 
						if (!(lockctl->conflictTab[lockmode] & bitmask))
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		/* no conflict. OK to get the lock */
 | 
							/* no conflict. OK to get the lock */
 | 
				
			||||||
		HOLDER_PRINT("LockCheckConflicts: resolved", holder);
 | 
							PROCLOCK_PRINT("LockCheckConflicts: resolved", holder);
 | 
				
			||||||
		return STATUS_OK;
 | 
							return STATUS_OK;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	HOLDER_PRINT("LockCheckConflicts: conflicting", holder);
 | 
						PROCLOCK_PRINT("LockCheckConflicts: conflicting", holder);
 | 
				
			||||||
	return STATUS_FOUND;
 | 
						return STATUS_FOUND;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -819,13 +819,13 @@ static void
 | 
				
			|||||||
LockCountMyLocks(SHMEM_OFFSET lockOffset, PROC *proc, int *myHolding)
 | 
					LockCountMyLocks(SHMEM_OFFSET lockOffset, PROC *proc, int *myHolding)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	SHM_QUEUE  *procHolders = &(proc->procHolders);
 | 
						SHM_QUEUE  *procHolders = &(proc->procHolders);
 | 
				
			||||||
	HOLDER	   *holder;
 | 
						PROCLOCK	   *holder;
 | 
				
			||||||
	int			i;
 | 
						int			i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	MemSet(myHolding, 0, MAX_LOCKMODES * sizeof(int));
 | 
						MemSet(myHolding, 0, MAX_LOCKMODES * sizeof(int));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	holder = (HOLDER *) SHMQueueNext(procHolders, procHolders,
 | 
						holder = (PROCLOCK *) SHMQueueNext(procHolders, procHolders,
 | 
				
			||||||
									 offsetof(HOLDER, procLink));
 | 
														 offsetof(PROCLOCK, procLink));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while (holder)
 | 
						while (holder)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -835,8 +835,8 @@ LockCountMyLocks(SHMEM_OFFSET lockOffset, PROC *proc, int *myHolding)
 | 
				
			|||||||
				myHolding[i] += holder->holding[i];
 | 
									myHolding[i] += holder->holding[i];
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		holder = (HOLDER *) SHMQueueNext(procHolders, &holder->procLink,
 | 
							holder = (PROCLOCK *) SHMQueueNext(procHolders, &holder->procLink,
 | 
				
			||||||
										 offsetof(HOLDER, procLink));
 | 
															 offsetof(PROCLOCK, procLink));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -848,7 +848,7 @@ LockCountMyLocks(SHMEM_OFFSET lockOffset, PROC *proc, int *myHolding)
 | 
				
			|||||||
 * 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, HOLDER *holder, LOCKMODE lockmode)
 | 
					GrantLock(LOCK *lock, PROCLOCK *holder, LOCKMODE lockmode)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	lock->nGranted++;
 | 
						lock->nGranted++;
 | 
				
			||||||
	lock->granted[lockmode]++;
 | 
						lock->granted[lockmode]++;
 | 
				
			||||||
@@ -873,7 +873,7 @@ GrantLock(LOCK *lock, HOLDER *holder, LOCKMODE lockmode)
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
static int
 | 
					static int
 | 
				
			||||||
WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
 | 
					WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
 | 
				
			||||||
		   LOCK *lock, HOLDER *holder)
 | 
							   LOCK *lock, PROCLOCK *holder)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	LOCKMETHODTABLE *lockMethodTable = LockMethodTable[lockmethod];
 | 
						LOCKMETHODTABLE *lockMethodTable = LockMethodTable[lockmethod];
 | 
				
			||||||
	char	   *new_status,
 | 
						char	   *new_status,
 | 
				
			||||||
@@ -991,8 +991,8 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
 | 
				
			|||||||
	LWLockId	masterLock;
 | 
						LWLockId	masterLock;
 | 
				
			||||||
	bool		found;
 | 
						bool		found;
 | 
				
			||||||
	LOCKMETHODTABLE *lockMethodTable;
 | 
						LOCKMETHODTABLE *lockMethodTable;
 | 
				
			||||||
	HOLDER	   *holder;
 | 
						PROCLOCK	   *holder;
 | 
				
			||||||
	HOLDERTAG	holdertag;
 | 
						PROCLOCKTAG	holdertag;
 | 
				
			||||||
	HTAB	   *holderTable;
 | 
						HTAB	   *holderTable;
 | 
				
			||||||
	bool		wakeupNeeded = false;
 | 
						bool		wakeupNeeded = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1044,14 +1044,14 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
 | 
				
			|||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Find the holder entry for this holder.
 | 
						 * Find the holder entry for this holder.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	MemSet(&holdertag, 0, sizeof(HOLDERTAG));	/* must clear padding,
 | 
						MemSet(&holdertag, 0, sizeof(PROCLOCKTAG));	/* must clear padding,
 | 
				
			||||||
												 * needed */
 | 
																	 * needed */
 | 
				
			||||||
	holdertag.lock = MAKE_OFFSET(lock);
 | 
						holdertag.lock = MAKE_OFFSET(lock);
 | 
				
			||||||
	holdertag.proc = MAKE_OFFSET(MyProc);
 | 
						holdertag.proc = MAKE_OFFSET(MyProc);
 | 
				
			||||||
	TransactionIdStore(xid, &holdertag.xid);
 | 
						TransactionIdStore(xid, &holdertag.xid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	holderTable = lockMethodTable->holderHash;
 | 
						holderTable = lockMethodTable->holderHash;
 | 
				
			||||||
	holder = (HOLDER *) hash_search(holderTable, (Pointer) &holdertag,
 | 
						holder = (PROCLOCK *) hash_search(holderTable, (Pointer) &holdertag,
 | 
				
			||||||
									HASH_FIND_SAVE, &found);
 | 
														HASH_FIND_SAVE, &found);
 | 
				
			||||||
	if (!holder || !found)
 | 
						if (!holder || !found)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -1064,7 +1064,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
 | 
				
			|||||||
			elog(NOTICE, "LockRelease: holder table corrupted");
 | 
								elog(NOTICE, "LockRelease: holder table corrupted");
 | 
				
			||||||
		return FALSE;
 | 
							return FALSE;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	HOLDER_PRINT("LockRelease: found", holder);
 | 
						PROCLOCK_PRINT("LockRelease: found", holder);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * 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
 | 
				
			||||||
@@ -1072,7 +1072,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (!(holder->holding[lockmode] > 0))
 | 
						if (!(holder->holding[lockmode] > 0))
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		HOLDER_PRINT("LockRelease: WRONGTYPE", holder);
 | 
							PROCLOCK_PRINT("LockRelease: WRONGTYPE", holder);
 | 
				
			||||||
		Assert(holder->holding[lockmode] >= 0);
 | 
							Assert(holder->holding[lockmode] >= 0);
 | 
				
			||||||
		LWLockRelease(masterLock);
 | 
							LWLockRelease(masterLock);
 | 
				
			||||||
		elog(NOTICE, "LockRelease: you don't own a lock of type %s",
 | 
							elog(NOTICE, "LockRelease: you don't own a lock of type %s",
 | 
				
			||||||
@@ -1141,7 +1141,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	holder->holding[lockmode]--;
 | 
						holder->holding[lockmode]--;
 | 
				
			||||||
	holder->nHolding--;
 | 
						holder->nHolding--;
 | 
				
			||||||
	HOLDER_PRINT("LockRelease: updated", holder);
 | 
						PROCLOCK_PRINT("LockRelease: updated", holder);
 | 
				
			||||||
	Assert((holder->nHolding >= 0) && (holder->holding[lockmode] >= 0));
 | 
						Assert((holder->nHolding >= 0) && (holder->holding[lockmode] >= 0));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
@@ -1150,10 +1150,10 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (holder->nHolding == 0)
 | 
						if (holder->nHolding == 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		HOLDER_PRINT("LockRelease: deleting", holder);
 | 
							PROCLOCK_PRINT("LockRelease: deleting", holder);
 | 
				
			||||||
		SHMQueueDelete(&holder->lockLink);
 | 
							SHMQueueDelete(&holder->lockLink);
 | 
				
			||||||
		SHMQueueDelete(&holder->procLink);
 | 
							SHMQueueDelete(&holder->procLink);
 | 
				
			||||||
		holder = (HOLDER *) hash_search(holderTable, (Pointer) &holder,
 | 
							holder = (PROCLOCK *) hash_search(holderTable, (Pointer) &holder,
 | 
				
			||||||
										HASH_REMOVE_SAVED, &found);
 | 
															HASH_REMOVE_SAVED, &found);
 | 
				
			||||||
		if (!holder || !found)
 | 
							if (!holder || !found)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@@ -1189,8 +1189,8 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
 | 
				
			|||||||
			   bool allxids, TransactionId xid)
 | 
								   bool allxids, TransactionId xid)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	SHM_QUEUE  *procHolders = &(proc->procHolders);
 | 
						SHM_QUEUE  *procHolders = &(proc->procHolders);
 | 
				
			||||||
	HOLDER	   *holder;
 | 
						PROCLOCK	   *holder;
 | 
				
			||||||
	HOLDER	   *nextHolder;
 | 
						PROCLOCK	   *nextHolder;
 | 
				
			||||||
	LWLockId	masterLock;
 | 
						LWLockId	masterLock;
 | 
				
			||||||
	LOCKMETHODTABLE *lockMethodTable;
 | 
						LOCKMETHODTABLE *lockMethodTable;
 | 
				
			||||||
	int			i,
 | 
						int			i,
 | 
				
			||||||
@@ -1217,16 +1217,16 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	LWLockAcquire(masterLock, LW_EXCLUSIVE);
 | 
						LWLockAcquire(masterLock, LW_EXCLUSIVE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	holder = (HOLDER *) SHMQueueNext(procHolders, procHolders,
 | 
						holder = (PROCLOCK *) SHMQueueNext(procHolders, procHolders,
 | 
				
			||||||
									 offsetof(HOLDER, procLink));
 | 
														 offsetof(PROCLOCK, procLink));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while (holder)
 | 
						while (holder)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		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 holder */
 | 
				
			||||||
		nextHolder = (HOLDER *) SHMQueueNext(procHolders, &holder->procLink,
 | 
							nextHolder = (PROCLOCK *) SHMQueueNext(procHolders, &holder->procLink,
 | 
				
			||||||
											 offsetof(HOLDER, procLink));
 | 
																 offsetof(PROCLOCK, procLink));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Assert(holder->tag.proc == MAKE_OFFSET(proc));
 | 
							Assert(holder->tag.proc == MAKE_OFFSET(proc));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1240,7 +1240,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
 | 
				
			|||||||
		if (!allxids && !TransactionIdEquals(xid, holder->tag.xid))
 | 
							if (!allxids && !TransactionIdEquals(xid, holder->tag.xid))
 | 
				
			||||||
			goto next_item;
 | 
								goto next_item;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		HOLDER_PRINT("LockReleaseAll", holder);
 | 
							PROCLOCK_PRINT("LockReleaseAll", holder);
 | 
				
			||||||
		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);
 | 
				
			||||||
@@ -1294,7 +1294,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		LOCK_PRINT("LockReleaseAll: updated", lock, 0);
 | 
							LOCK_PRINT("LockReleaseAll: updated", lock, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		HOLDER_PRINT("LockReleaseAll: deleting", holder);
 | 
							PROCLOCK_PRINT("LockReleaseAll: deleting", holder);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * Remove the holder entry from the linked lists
 | 
							 * Remove the holder entry from the linked lists
 | 
				
			||||||
@@ -1305,7 +1305,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
 | 
				
			|||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * remove the holder entry from the hashtable
 | 
							 * remove the holder entry from the hashtable
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		holder = (HOLDER *) hash_search(lockMethodTable->holderHash,
 | 
							holder = (PROCLOCK *) hash_search(lockMethodTable->holderHash,
 | 
				
			||||||
										(Pointer) holder,
 | 
															(Pointer) holder,
 | 
				
			||||||
										HASH_REMOVE,
 | 
															HASH_REMOVE,
 | 
				
			||||||
										&found);
 | 
															&found);
 | 
				
			||||||
@@ -1370,8 +1370,8 @@ LockShmemSize(int maxBackends)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* holderHash table */
 | 
						/* holderHash table */
 | 
				
			||||||
	size += hash_estimate_size(max_table_size,
 | 
						size += hash_estimate_size(max_table_size,
 | 
				
			||||||
							   SHMEM_HOLDERTAB_KEYSIZE,
 | 
												   SHMEM_PROCLOCKTAB_KEYSIZE,
 | 
				
			||||||
							   SHMEM_HOLDERTAB_DATASIZE);
 | 
												   SHMEM_PROCLOCKTAB_DATASIZE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Since the lockHash entry count above is only an estimate, add 10%
 | 
						 * Since the lockHash entry count above is only an estimate, add 10%
 | 
				
			||||||
@@ -1394,7 +1394,7 @@ DumpLocks(void)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	PROC	   *proc;
 | 
						PROC	   *proc;
 | 
				
			||||||
	SHM_QUEUE  *procHolders;
 | 
						SHM_QUEUE  *procHolders;
 | 
				
			||||||
	HOLDER	   *holder;
 | 
						PROCLOCK	   *holder;
 | 
				
			||||||
	LOCK	   *lock;
 | 
						LOCK	   *lock;
 | 
				
			||||||
	int			lockmethod = DEFAULT_LOCKMETHOD;
 | 
						int			lockmethod = DEFAULT_LOCKMETHOD;
 | 
				
			||||||
	LOCKMETHODTABLE *lockMethodTable;
 | 
						LOCKMETHODTABLE *lockMethodTable;
 | 
				
			||||||
@@ -1413,8 +1413,8 @@ 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 = (HOLDER *) SHMQueueNext(procHolders, procHolders,
 | 
						holder = (PROCLOCK *) SHMQueueNext(procHolders, procHolders,
 | 
				
			||||||
									 offsetof(HOLDER, procLink));
 | 
														 offsetof(PROCLOCK, procLink));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while (holder)
 | 
						while (holder)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -1422,11 +1422,11 @@ DumpLocks(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		lock = (LOCK *) MAKE_PTR(holder->tag.lock);
 | 
							lock = (LOCK *) MAKE_PTR(holder->tag.lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		HOLDER_PRINT("DumpLocks", holder);
 | 
							PROCLOCK_PRINT("DumpLocks", holder);
 | 
				
			||||||
		LOCK_PRINT("DumpLocks", lock, 0);
 | 
							LOCK_PRINT("DumpLocks", lock, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		holder = (HOLDER *) SHMQueueNext(procHolders, &holder->procLink,
 | 
							holder = (PROCLOCK *) SHMQueueNext(procHolders, &holder->procLink,
 | 
				
			||||||
										 offsetof(HOLDER, procLink));
 | 
															 offsetof(PROCLOCK, procLink));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1437,7 +1437,7 @@ void
 | 
				
			|||||||
DumpAllLocks(void)
 | 
					DumpAllLocks(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	PROC	   *proc;
 | 
						PROC	   *proc;
 | 
				
			||||||
	HOLDER	   *holder = NULL;
 | 
						PROCLOCK	   *holder = NULL;
 | 
				
			||||||
	LOCK	   *lock;
 | 
						LOCK	   *lock;
 | 
				
			||||||
	int			lockmethod = DEFAULT_LOCKMETHOD;
 | 
						int			lockmethod = DEFAULT_LOCKMETHOD;
 | 
				
			||||||
	LOCKMETHODTABLE *lockMethodTable;
 | 
						LOCKMETHODTABLE *lockMethodTable;
 | 
				
			||||||
@@ -1459,10 +1459,10 @@ DumpAllLocks(void)
 | 
				
			|||||||
		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, holderTable);
 | 
				
			||||||
	while ((holder = (HOLDER *) hash_seq_search(&status)) &&
 | 
						while ((holder = (PROCLOCK *) hash_seq_search(&status)) &&
 | 
				
			||||||
		   (holder != (HOLDER *) TRUE))
 | 
							   (holder != (PROCLOCK *) TRUE))
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		HOLDER_PRINT("DumpAllLocks", holder);
 | 
							PROCLOCK_PRINT("DumpAllLocks", holder);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (holder->tag.lock)
 | 
							if (holder->tag.lock)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,7 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * IDENTIFICATION
 | 
					 * IDENTIFICATION
 | 
				
			||||||
 *	  $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.109 2001/09/29 04:02:24 tgl Exp $
 | 
					 *	  $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.110 2001/09/29 21:35:14 momjian Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 *-------------------------------------------------------------------------
 | 
					 *-------------------------------------------------------------------------
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@@ -563,7 +563,7 @@ int
 | 
				
			|||||||
ProcSleep(LOCKMETHODTABLE *lockMethodTable,
 | 
					ProcSleep(LOCKMETHODTABLE *lockMethodTable,
 | 
				
			||||||
		  LOCKMODE lockmode,
 | 
							  LOCKMODE lockmode,
 | 
				
			||||||
		  LOCK *lock,
 | 
							  LOCK *lock,
 | 
				
			||||||
		  HOLDER *holder)
 | 
							  PROCLOCK *holder)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	LOCKMETHODCTL *lockctl = lockMethodTable->ctl;
 | 
						LOCKMETHODCTL *lockctl = lockMethodTable->ctl;
 | 
				
			||||||
	LWLockId	masterLock = lockctl->masterLock;
 | 
						LWLockId	masterLock = lockctl->masterLock;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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.53 2001/09/29 04:02:26 tgl Exp $
 | 
					 * $Id: lock.h,v 1.54 2001/09/29 21:35:14 momjian Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 *-------------------------------------------------------------------------
 | 
					 *-------------------------------------------------------------------------
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@@ -144,7 +144,7 @@ typedef struct LOCKTAG
 | 
				
			|||||||
 * tag -- uniquely identifies the object being locked
 | 
					 * tag -- uniquely identifies the object being locked
 | 
				
			||||||
 * grantMask -- bitmask for all lock types currently granted on this object.
 | 
					 * grantMask -- bitmask for all lock types currently granted on this object.
 | 
				
			||||||
 * waitMask -- bitmask for all lock types currently awaited on this object.
 | 
					 * waitMask -- bitmask for all lock types currently awaited on this object.
 | 
				
			||||||
 * lockHolders -- list of HOLDER objects for this lock.
 | 
					 * lockHolders -- list of PROCLOCK objects for this lock.
 | 
				
			||||||
 * waitProcs -- queue of processes waiting for this lock.
 | 
					 * waitProcs -- queue of processes waiting for this lock.
 | 
				
			||||||
 * requested -- count of each lock type currently requested on the lock
 | 
					 * requested -- count of each lock type currently requested on the lock
 | 
				
			||||||
 *		(includes requests already granted!!).
 | 
					 *		(includes requests already granted!!).
 | 
				
			||||||
@@ -160,7 +160,7 @@ typedef struct LOCK
 | 
				
			|||||||
	/* data */
 | 
						/* data */
 | 
				
			||||||
	int			grantMask;		/* bitmask for lock types already granted */
 | 
						int			grantMask;		/* bitmask for lock types already granted */
 | 
				
			||||||
	int			waitMask;		/* bitmask for lock types awaited */
 | 
						int			waitMask;		/* bitmask for lock types awaited */
 | 
				
			||||||
	SHM_QUEUE	lockHolders;	/* list of HOLDER objects assoc. with lock */
 | 
						SHM_QUEUE	lockHolders;	/* list of PROCLOCK objects assoc. with lock */
 | 
				
			||||||
	PROC_QUEUE	waitProcs;		/* list of PROC objects waiting on lock */
 | 
						PROC_QUEUE	waitProcs;		/* list of PROC objects waiting on lock */
 | 
				
			||||||
	int			requested[MAX_LOCKMODES];		/* counts of requested
 | 
						int			requested[MAX_LOCKMODES];		/* counts of requested
 | 
				
			||||||
												 * locks */
 | 
																	 * locks */
 | 
				
			||||||
@@ -180,8 +180,8 @@ typedef struct LOCK
 | 
				
			|||||||
 * on the same lockable object.  We need to store some per-holder information
 | 
					 * on the same lockable object.  We need to store some per-holder information
 | 
				
			||||||
 * for each such holder (or would-be holder).
 | 
					 * for each such holder (or would-be holder).
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * HOLDERTAG is the key information needed to look up a HOLDER item in the
 | 
					 * PROCLOCKTAG is the key information needed to look up a PROCLOCK item in the
 | 
				
			||||||
 * holder hashtable.  A HOLDERTAG value uniquely identifies a lock holder.
 | 
					 * holder hashtable.  A PROCLOCKTAG value uniquely identifies a lock holder.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * There are two possible kinds of holder tags: a transaction (identified
 | 
					 * 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
 | 
					 * both by the PROC of the backend running it, and the xact's own ID) and
 | 
				
			||||||
@@ -197,35 +197,35 @@ typedef struct LOCK
 | 
				
			|||||||
 * Otherwise, holder objects whose counts have gone to zero are recycled
 | 
					 * Otherwise, holder objects whose counts have gone to zero are recycled
 | 
				
			||||||
 * as soon as convenient.
 | 
					 * as soon as convenient.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Each HOLDER object is linked into lists for both the associated LOCK object
 | 
					 * Each PROCLOCK object is linked into lists for both the associated LOCK object
 | 
				
			||||||
 * and the owning PROC object.	Note that the HOLDER is entered into these
 | 
					 * and the owning PROC object.	Note that the PROCLOCK is entered into these
 | 
				
			||||||
 * lists as soon as it is created, even if no lock has yet been granted.
 | 
					 * 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
 | 
					 * A PROC that is waiting for a lock to be granted will also be linked into
 | 
				
			||||||
 * the lock's waitProcs queue.
 | 
					 * the lock's waitProcs queue.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
typedef struct HOLDERTAG
 | 
					typedef struct PROCLOCKTAG
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	SHMEM_OFFSET lock;			/* link to per-lockable-object information */
 | 
						SHMEM_OFFSET lock;			/* link to per-lockable-object information */
 | 
				
			||||||
	SHMEM_OFFSET proc;			/* link to PROC of owning backend */
 | 
						SHMEM_OFFSET proc;			/* link to PROC of owning backend */
 | 
				
			||||||
	TransactionId xid;			/* xact ID, or InvalidTransactionId */
 | 
						TransactionId xid;			/* xact ID, or InvalidTransactionId */
 | 
				
			||||||
} HOLDERTAG;
 | 
					} PROCLOCKTAG;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct HOLDER
 | 
					typedef struct PROCLOCK
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/* tag */
 | 
						/* tag */
 | 
				
			||||||
	HOLDERTAG	tag;			/* unique identifier of holder object */
 | 
						PROCLOCKTAG	tag;			/* unique identifier of holder 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 holders */
 | 
				
			||||||
	SHM_QUEUE	procLink;		/* list link for process's list of holders */
 | 
						SHM_QUEUE	procLink;		/* list link for process's list of holders */
 | 
				
			||||||
} HOLDER;
 | 
					} PROCLOCK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define SHMEM_HOLDERTAB_KEYSIZE  sizeof(HOLDERTAG)
 | 
					#define SHMEM_PROCLOCKTAB_KEYSIZE  sizeof(PROCLOCKTAG)
 | 
				
			||||||
#define SHMEM_HOLDERTAB_DATASIZE (sizeof(HOLDER) - SHMEM_HOLDERTAB_KEYSIZE)
 | 
					#define SHMEM_PROCLOCKTAB_DATASIZE (sizeof(PROCLOCK) - SHMEM_PROCLOCKTAB_KEYSIZE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define HOLDER_LOCKMETHOD(holder) \
 | 
					#define PROCLOCK_LOCKMETHOD(holder) \
 | 
				
			||||||
		(((LOCK *) MAKE_PTR((holder).tag.lock))->tag.lockmethod)
 | 
							(((LOCK *) MAKE_PTR((holder).tag.lock))->tag.lockmethod)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -245,9 +245,9 @@ extern bool LockReleaseAll(LOCKMETHOD lockmethod, PROC *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, HOLDER *holder, PROC *proc,
 | 
									   LOCK *lock, PROCLOCK *holder, PROC *proc,
 | 
				
			||||||
				   int *myHolding);
 | 
									   int *myHolding);
 | 
				
			||||||
extern void GrantLock(LOCK *lock, HOLDER *holder, LOCKMODE lockmode);
 | 
					extern void GrantLock(LOCK *lock, PROCLOCK *holder, LOCKMODE lockmode);
 | 
				
			||||||
extern void RemoveFromWaitQueue(PROC *proc);
 | 
					extern void RemoveFromWaitQueue(PROC *proc);
 | 
				
			||||||
extern int	LockShmemSize(int maxBackends);
 | 
					extern int	LockShmemSize(int maxBackends);
 | 
				
			||||||
extern bool DeadLockCheck(PROC *proc);
 | 
					extern bool DeadLockCheck(PROC *proc);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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: proc.h,v 1.48 2001/09/29 04:02:26 tgl Exp $
 | 
					 * $Id: proc.h,v 1.49 2001/09/29 21:35:14 momjian Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 *-------------------------------------------------------------------------
 | 
					 *-------------------------------------------------------------------------
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@@ -67,12 +67,12 @@ struct PROC
 | 
				
			|||||||
	/* Info about lock the process is currently waiting for, if any. */
 | 
						/* Info about lock the process is currently waiting for, if any. */
 | 
				
			||||||
	/* waitLock and waitHolder are NULL if not currently waiting. */
 | 
						/* waitLock and waitHolder are NULL if not currently waiting. */
 | 
				
			||||||
	LOCK	   *waitLock;		/* Lock object we're sleeping on ... */
 | 
						LOCK	   *waitLock;		/* Lock object we're sleeping on ... */
 | 
				
			||||||
	HOLDER	   *waitHolder;		/* Per-holder info for awaited lock */
 | 
						PROCLOCK	   *waitHolder;		/* Per-holder info for awaited lock */
 | 
				
			||||||
	LOCKMODE	waitLockMode;	/* type of lock we're waiting for */
 | 
						LOCKMODE	waitLockMode;	/* type of lock we're waiting for */
 | 
				
			||||||
	LOCKMASK	heldLocks;		/* bitmask for lock types already held on
 | 
						LOCKMASK	heldLocks;		/* bitmask for lock types already held on
 | 
				
			||||||
								 * this lock object by this backend */
 | 
													 * this lock object by this backend */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	SHM_QUEUE	procHolders;	/* list of HOLDER objects for locks held
 | 
						SHM_QUEUE	procHolders;	/* list of PROCLOCK objects for locks held
 | 
				
			||||||
								 * or awaited by this backend */
 | 
													 * or awaited by this backend */
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -138,7 +138,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, HOLDER *holder);
 | 
							  LOCK *lock, PROCLOCK *holder);
 | 
				
			||||||
extern PROC *ProcWakeup(PROC *proc, int errType);
 | 
					extern PROC *ProcWakeup(PROC *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);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user