Commit e7ca8674 authored by Bruce Momjian's avatar Bruce Momjian

Try to reduce confusion about what is a lock method identifier, a lock

method control structure, or a table of control structures.

. Use type LOCKMASK where an int is not a counter.

. Get rid of INVALID_TABLEID, use INVALID_LOCKMETHOD instead.

. Use INVALID_LOCKMETHOD instead of (LOCKMETHOD) NULL, because
  LOCKMETHOD is not a pointer.

. Define and use macro LockMethodIsValid.

. Rename LOCKMETHOD to LOCKMETHODID.

. Remove global variable LongTermTableId in lmgr.c, because it is
  never used.

. Make LockTableId static in lmgr.c, because it is used nowhere else.
  Why not remove it and use DEFAULT_LOCKMETHOD?

. Rename the lock method control structure from LOCKMETHODTABLE to
  LockMethodData.  Introduce a pointer type named LockMethod.

. Remove elog(FATAL) after InitLockTable() call in
  CreateSharedMemoryAndSemaphores(), because if something goes wrong,
  there is elog(FATAL) in LockMethodTableInit(), and if this doesn't
  help, an elog(ERROR) in InitLockTable() is promoted to FATAL.

. Make InitLockTable() void, because its only caller does not use its
  return value any more.

. Rename variables in lock.c to avoid statements like
        LockMethodTable[NumLockMethods] = lockMethodTable;
        lockMethodTable = LockMethodTable[lockmethod];

. Change LOCKMETHODID type to uint16 to fit into struct LOCKTAG.

. Remove static variables BITS_OFF and BITS_ON from lock.c, because
  I agree to this doubt:
 * XXX is a fetch from a static array really faster than a shift?

. Define and use macros LOCKBIT_ON/OFF.


Manfred Koizar
parent e2ac58c7
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.58 2003/11/29 19:51:56 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.59 2003/12/01 21:59:25 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -111,8 +111,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, ...@@ -111,8 +111,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate,
* Set up lock manager * Set up lock manager
*/ */
InitLocks(); InitLocks();
if (InitLockTable(maxBackends) == INVALID_TABLEID) InitLockTable(maxBackends);
elog(FATAL, "could not create the lock table");
/* /*
* Set up process table * Set up process table
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.26 2003/11/29 19:51:56 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.27 2003/12/01 21:59:25 momjian Exp $
* *
* Interface: * Interface:
* *
...@@ -428,7 +428,7 @@ FindLockCycleRecurse(PGPROC *checkProc, ...@@ -428,7 +428,7 @@ FindLockCycleRecurse(PGPROC *checkProc,
LOCK *lock; LOCK *lock;
PROCLOCK *proclock; PROCLOCK *proclock;
SHM_QUEUE *lockHolders; SHM_QUEUE *lockHolders;
LOCKMETHODTABLE *lockMethodTable; LockMethod lockMethodTable;
PROC_QUEUE *waitQueue; PROC_QUEUE *waitQueue;
int queue_size; int queue_size;
int conflictMask; int conflictMask;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.61 2003/11/29 19:51:56 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.62 2003/12/01 21:59:25 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -65,26 +65,24 @@ static LOCKMASK LockConflicts[] = { ...@@ -65,26 +65,24 @@ static LOCKMASK LockConflicts[] = {
}; };
LOCKMETHOD LockTableId = (LOCKMETHOD) NULL; static LOCKMETHODID LockTableId = INVALID_LOCKMETHOD;
LOCKMETHOD LongTermTableId = (LOCKMETHOD) NULL;
/* /*
* Create the lock table described by LockConflicts * Create the lock table described by LockConflicts
*/ */
LOCKMETHOD void
InitLockTable(int maxBackends) InitLockTable(int maxBackends)
{ {
int lockmethod; LOCKMETHODID LongTermTableId;
/* number of lock modes is lengthof()-1 because of dummy zero */ /* number of lock modes is lengthof()-1 because of dummy zero */
lockmethod = LockMethodTableInit("LockTable", LockTableId = LockMethodTableInit("LockTable",
LockConflicts, LockConflicts,
lengthof(LockConflicts) - 1, lengthof(LockConflicts) - 1,
maxBackends); maxBackends);
LockTableId = lockmethod; if (!LockMethodIsValid(LockTableId))
if (!(LockTableId))
elog(ERROR, "could not initialize lock table"); elog(ERROR, "could not initialize lock table");
Assert(LockTableId == DEFAULT_LOCKMETHOD);
#ifdef USER_LOCKS #ifdef USER_LOCKS
...@@ -92,11 +90,10 @@ InitLockTable(int maxBackends) ...@@ -92,11 +90,10 @@ InitLockTable(int maxBackends)
* Allocate another tableId for long-term locks * Allocate another tableId for long-term locks
*/ */
LongTermTableId = LockMethodTableRename(LockTableId); LongTermTableId = LockMethodTableRename(LockTableId);
if (!(LongTermTableId)) if (!LockMethodIsValid(LongTermTableId))
elog(ERROR, "could not rename long-term lock table"); elog(ERROR, "could not rename long-term lock table");
Assert(LongTermTableId == USER_LOCKMETHOD);
#endif #endif
return LockTableId;
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.129 2003/11/29 19:51:56 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.130 2003/12/01 21:59:25 momjian Exp $
* *
* NOTES * NOTES
* Outside modules can create a lock table and acquire/release * Outside modules can create a lock table and acquire/release
...@@ -46,7 +46,7 @@ int max_locks_per_xact; /* set by guc.c */ ...@@ -46,7 +46,7 @@ int max_locks_per_xact; /* set by guc.c */
#define NLOCKENTS(maxBackends) (max_locks_per_xact * (maxBackends)) #define NLOCKENTS(maxBackends) (max_locks_per_xact * (maxBackends))
static int WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode, static int WaitOnLock(LOCKMETHODID lockmethodid, LOCKMODE lockmode,
LOCK *lock, PROCLOCK *proclock); LOCK *lock, PROCLOCK *proclock);
static void LockCountMyLocks(SHMEM_OFFSET lockOffset, PGPROC *proc, static void LockCountMyLocks(SHMEM_OFFSET lockOffset, PGPROC *proc,
int *myHolding); int *myHolding);
...@@ -111,7 +111,7 @@ LOCK_PRINT(const char *where, const LOCK *lock, LOCKMODE type) ...@@ -111,7 +111,7 @@ LOCK_PRINT(const char *where, const LOCK *lock, LOCKMODE type)
"req(%d,%d,%d,%d,%d,%d,%d)=%d " "req(%d,%d,%d,%d,%d,%d,%d)=%d "
"grant(%d,%d,%d,%d,%d,%d,%d)=%d wait(%d) type(%s)", "grant(%d,%d,%d,%d,%d,%d,%d)=%d wait(%d) type(%s)",
where, MAKE_OFFSET(lock), where, MAKE_OFFSET(lock),
lock->tag.lockmethod, lock->tag.relId, lock->tag.dbId, lock->tag.lockmethodid, lock->tag.relId, lock->tag.dbId,
lock->tag.objId.blkno, lock->grantMask, lock->tag.objId.blkno, lock->grantMask,
lock->requested[1], lock->requested[2], lock->requested[3], lock->requested[1], lock->requested[2], lock->requested[3],
lock->requested[4], lock->requested[5], lock->requested[6], lock->requested[4], lock->requested[5], lock->requested[6],
...@@ -150,19 +150,9 @@ PROCLOCK_PRINT(const char *where, const PROCLOCK *proclockP) ...@@ -150,19 +150,9 @@ PROCLOCK_PRINT(const char *where, const PROCLOCK *proclockP)
/* /*
* These are to simplify/speed up some bit arithmetic. * map from lock method id to the lock table structure
*
* XXX is a fetch from a static array really faster than a shift?
* Wouldn't bet on it...
*/ */
static LockMethod LockMethods[MAX_LOCK_METHODS];
static LOCKMASK BITS_OFF[MAX_LOCKMODES];
static LOCKMASK BITS_ON[MAX_LOCKMODES];
/*
* map from lockmethod to the lock table structure
*/
static LOCKMETHODTABLE *LockMethodTable[MAX_LOCK_METHODS];
static int NumLockMethods; static int NumLockMethods;
...@@ -173,28 +163,20 @@ static int NumLockMethods; ...@@ -173,28 +163,20 @@ static int NumLockMethods;
void void
InitLocks(void) InitLocks(void)
{ {
int i; /* NOP */
int bit;
bit = 1;
for (i = 0; i < MAX_LOCKMODES; i++, bit <<= 1)
{
BITS_ON[i] = bit;
BITS_OFF[i] = ~bit;
}
} }
/* /*
* Fetch the lock method table associated with a given lock * Fetch the lock method table associated with a given lock
*/ */
LOCKMETHODTABLE * LockMethod
GetLocksMethodTable(LOCK *lock) GetLocksMethodTable(LOCK *lock)
{ {
LOCKMETHOD lockmethod = LOCK_LOCKMETHOD(*lock); LOCKMETHODID lockmethodid = LOCK_LOCKMETHOD(*lock);
Assert(lockmethod > 0 && lockmethod < NumLockMethods); Assert(0 < lockmethodid && lockmethodid < NumLockMethods);
return LockMethodTable[lockmethod]; return LockMethods[lockmethodid];
} }
...@@ -205,7 +187,7 @@ GetLocksMethodTable(LOCK *lock) ...@@ -205,7 +187,7 @@ GetLocksMethodTable(LOCK *lock)
* Notes: just copying. Should only be called once. * Notes: just copying. Should only be called once.
*/ */
static void static void
LockMethodInit(LOCKMETHODTABLE *lockMethodTable, LockMethodInit(LockMethod lockMethodTable,
LOCKMASK *conflictsP, LOCKMASK *conflictsP,
int numModes) int numModes)
{ {
...@@ -226,13 +208,13 @@ LockMethodInit(LOCKMETHODTABLE *lockMethodTable, ...@@ -226,13 +208,13 @@ LockMethodInit(LOCKMETHODTABLE *lockMethodTable,
* by the postmaster are inherited by each backend, so they must be in * by the postmaster are inherited by each backend, so they must be in
* TopMemoryContext. * TopMemoryContext.
*/ */
LOCKMETHOD LOCKMETHODID
LockMethodTableInit(char *tabName, LockMethodTableInit(char *tabName,
LOCKMASK *conflictsP, LOCKMASK *conflictsP,
int numModes, int numModes,
int maxBackends) int maxBackends)
{ {
LOCKMETHODTABLE *lockMethodTable; LockMethod newLockMethod;
char *shmemName; char *shmemName;
HASHCTL info; HASHCTL info;
int hash_flags; int hash_flags;
...@@ -254,10 +236,10 @@ LockMethodTableInit(char *tabName, ...@@ -254,10 +236,10 @@ LockMethodTableInit(char *tabName,
/* each lock table has a header in shared memory */ /* each lock table has a header in shared memory */
sprintf(shmemName, "%s (lock method table)", tabName); sprintf(shmemName, "%s (lock method table)", tabName);
lockMethodTable = (LOCKMETHODTABLE *) newLockMethod = (LockMethod)
ShmemInitStruct(shmemName, sizeof(LOCKMETHODTABLE), &found); ShmemInitStruct(shmemName, sizeof(LockMethodData), &found);
if (!lockMethodTable) if (!newLockMethod)
elog(FATAL, "could not initialize lock table \"%s\"", tabName); elog(FATAL, "could not initialize lock table \"%s\"", tabName);
/* /*
...@@ -275,15 +257,15 @@ LockMethodTableInit(char *tabName, ...@@ -275,15 +257,15 @@ LockMethodTableInit(char *tabName,
*/ */
if (!found) if (!found)
{ {
MemSet(lockMethodTable, 0, sizeof(LOCKMETHODTABLE)); MemSet(newLockMethod, 0, sizeof(LockMethodData));
lockMethodTable->masterLock = LockMgrLock; newLockMethod->masterLock = LockMgrLock;
lockMethodTable->lockmethod = NumLockMethods; newLockMethod->lockmethodid = NumLockMethods;
} }
/* /*
* other modules refer to the lock table by a lockmethod ID * other modules refer to the lock table by a lockmethod ID
*/ */
LockMethodTable[NumLockMethods] = lockMethodTable; LockMethods[NumLockMethods] = newLockMethod;
NumLockMethods++; NumLockMethods++;
Assert(NumLockMethods <= MAX_LOCK_METHODS); Assert(NumLockMethods <= MAX_LOCK_METHODS);
...@@ -297,15 +279,15 @@ LockMethodTableInit(char *tabName, ...@@ -297,15 +279,15 @@ LockMethodTableInit(char *tabName,
hash_flags = (HASH_ELEM | HASH_FUNCTION); hash_flags = (HASH_ELEM | HASH_FUNCTION);
sprintf(shmemName, "%s (lock hash)", tabName); sprintf(shmemName, "%s (lock hash)", tabName);
lockMethodTable->lockHash = ShmemInitHash(shmemName, newLockMethod->lockHash = ShmemInitHash(shmemName,
init_table_size, init_table_size,
max_table_size, max_table_size,
&info, &info,
hash_flags); hash_flags);
if (!lockMethodTable->lockHash) if (!newLockMethod->lockHash)
elog(FATAL, "could not initialize lock table \"%s\"", tabName); elog(FATAL, "could not initialize lock table \"%s\"", tabName);
Assert(lockMethodTable->lockHash->hash == tag_hash); Assert(newLockMethod->lockHash->hash == tag_hash);
/* /*
* allocate a hash table for PROCLOCK structs. This is used to store * allocate a hash table for PROCLOCK structs. This is used to store
...@@ -317,23 +299,23 @@ LockMethodTableInit(char *tabName, ...@@ -317,23 +299,23 @@ LockMethodTableInit(char *tabName,
hash_flags = (HASH_ELEM | HASH_FUNCTION); hash_flags = (HASH_ELEM | HASH_FUNCTION);
sprintf(shmemName, "%s (proclock hash)", tabName); sprintf(shmemName, "%s (proclock hash)", tabName);
lockMethodTable->proclockHash = ShmemInitHash(shmemName, newLockMethod->proclockHash = ShmemInitHash(shmemName,
init_table_size, init_table_size,
max_table_size, max_table_size,
&info, &info,
hash_flags); hash_flags);
if (!lockMethodTable->proclockHash) if (!newLockMethod->proclockHash)
elog(FATAL, "could not initialize lock table \"%s\"", tabName); elog(FATAL, "could not initialize lock table \"%s\"", tabName);
/* init data structures */ /* init data structures */
LockMethodInit(lockMethodTable, conflictsP, numModes); LockMethodInit(newLockMethod, conflictsP, numModes);
LWLockRelease(LockMgrLock); LWLockRelease(LockMgrLock);
pfree(shmemName); pfree(shmemName);
return lockMethodTable->lockmethod; return newLockMethod->lockmethodid;
} }
/* /*
...@@ -349,22 +331,22 @@ LockMethodTableInit(char *tabName, ...@@ -349,22 +331,22 @@ LockMethodTableInit(char *tabName,
* short term and long term locks, yet store them all in one hashtable. * short term and long term locks, yet store them all in one hashtable.
*/ */
LOCKMETHOD LOCKMETHODID
LockMethodTableRename(LOCKMETHOD lockmethod) LockMethodTableRename(LOCKMETHODID lockmethodid)
{ {
LOCKMETHOD newLockMethod; LOCKMETHODID newLockMethodId;
if (NumLockMethods >= MAX_LOCK_METHODS) if (NumLockMethods >= MAX_LOCK_METHODS)
return INVALID_LOCKMETHOD; return INVALID_LOCKMETHOD;
if (LockMethodTable[lockmethod] == INVALID_LOCKMETHOD) if (LockMethods[lockmethodid] == INVALID_LOCKMETHOD)
return INVALID_LOCKMETHOD; return INVALID_LOCKMETHOD;
/* other modules refer to the lock table by a lockmethod ID */ /* other modules refer to the lock table by a lockmethod ID */
newLockMethod = NumLockMethods; newLockMethodId = NumLockMethods;
NumLockMethods++; NumLockMethods++;
LockMethodTable[newLockMethod] = LockMethodTable[lockmethod]; LockMethods[newLockMethodId] = LockMethods[lockmethodid];
return newLockMethod; return newLockMethodId;
} }
/* /*
...@@ -412,7 +394,7 @@ LockMethodTableRename(LOCKMETHOD lockmethod) ...@@ -412,7 +394,7 @@ LockMethodTableRename(LOCKMETHOD lockmethod)
* *
* normal lock user lock * normal lock user lock
* *
* lockmethod 1 2 * lockmethodid 1 2
* tag.dbId database oid database oid * tag.dbId database oid database oid
* tag.relId rel oid or 0 0 * tag.relId rel oid or 0 0
* tag.objId block id lock id2 * tag.objId block id lock id2
...@@ -429,7 +411,7 @@ LockMethodTableRename(LOCKMETHOD lockmethod) ...@@ -429,7 +411,7 @@ LockMethodTableRename(LOCKMETHOD lockmethod)
*/ */
bool bool
LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
TransactionId xid, LOCKMODE lockmode, bool dontWait) TransactionId xid, LOCKMODE lockmode, bool dontWait)
{ {
PROCLOCK *proclock; PROCLOCK *proclock;
...@@ -438,25 +420,25 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -438,25 +420,25 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
bool found; bool found;
LOCK *lock; LOCK *lock;
LWLockId masterLock; LWLockId masterLock;
LOCKMETHODTABLE *lockMethodTable; LockMethod lockMethodTable;
int status; int status;
int myHolding[MAX_LOCKMODES]; int myHolding[MAX_LOCKMODES];
int i; int i;
#ifdef LOCK_DEBUG #ifdef LOCK_DEBUG
if (lockmethod == USER_LOCKMETHOD && Trace_userlocks) if (lockmethodid == USER_LOCKMETHOD && Trace_userlocks)
elog(LOG, "LockAcquire: user lock [%u] %s", elog(LOG, "LockAcquire: user lock [%u] %s",
locktag->objId.blkno, lock_mode_names[lockmode]); locktag->objId.blkno, lock_mode_names[lockmode]);
#endif #endif
/* ???????? This must be changed when short term locks will be used */ /* ???????? This must be changed when short term locks will be used */
locktag->lockmethod = lockmethod; locktag->lockmethodid = lockmethodid;
Assert(lockmethod < NumLockMethods); Assert(lockmethodid < NumLockMethods);
lockMethodTable = LockMethodTable[lockmethod]; lockMethodTable = LockMethods[lockmethodid];
if (!lockMethodTable) if (!lockMethodTable)
{ {
elog(WARNING, "bad lock table id: %d", lockmethod); elog(WARNING, "bad lock table id: %d", lockmethodid);
return FALSE; return FALSE;
} }
...@@ -666,15 +648,12 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -666,15 +648,12 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
* Construct bitmask of locks this process holds on this object. * Construct bitmask of locks this process holds on this object.
*/ */
{ {
int heldLocks = 0; LOCKMASK heldLocks = 0;
int tmpMask;
for (i = 1, tmpMask = 2; for (i = 1; i <= lockMethodTable->numLockModes; i++)
i <= lockMethodTable->numLockModes;
i++, tmpMask <<= 1)
{ {
if (myHolding[i] > 0) if (myHolding[i] > 0)
heldLocks |= tmpMask; heldLocks |= LOCKBIT_ON(i);
} }
MyProc->heldLocks = heldLocks; MyProc->heldLocks = heldLocks;
} }
...@@ -682,7 +661,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -682,7 +661,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
/* /*
* Sleep till someone wakes me up. * Sleep till someone wakes me up.
*/ */
status = WaitOnLock(lockmethod, lockmode, lock, proclock); status = WaitOnLock(lockmethodid, 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
...@@ -729,7 +708,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -729,7 +708,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
* known. If NULL is passed then these values will be computed internally. * known. If NULL is passed then these values will be computed internally.
*/ */
int int
LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable, LockCheckConflicts(LockMethod lockMethodTable,
LOCKMODE lockmode, LOCKMODE lockmode,
LOCK *lock, LOCK *lock,
PROCLOCK *proclock, PROCLOCK *proclock,
...@@ -737,9 +716,8 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable, ...@@ -737,9 +716,8 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
int *myHolding) /* myHolding[] array or NULL */ int *myHolding) /* myHolding[] array or NULL */
{ {
int numLockModes = lockMethodTable->numLockModes; int numLockModes = lockMethodTable->numLockModes;
int bitmask; LOCKMASK bitmask;
int i, int i;
tmpMask;
int localHolding[MAX_LOCKMODES]; int localHolding[MAX_LOCKMODES];
/* /*
...@@ -772,11 +750,10 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable, ...@@ -772,11 +750,10 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
/* Compute mask of lock types held by other processes */ /* Compute mask of lock types held by other processes */
bitmask = 0; bitmask = 0;
tmpMask = 2; for (i = 1; i <= numLockModes; i++)
for (i = 1; i <= numLockModes; i++, tmpMask <<= 1)
{ {
if (lock->granted[i] != myHolding[i]) if (lock->granted[i] != myHolding[i])
bitmask |= tmpMask; bitmask |= LOCKBIT_ON(i);
} }
/* /*
...@@ -842,9 +819,9 @@ GrantLock(LOCK *lock, PROCLOCK *proclock, LOCKMODE lockmode) ...@@ -842,9 +819,9 @@ GrantLock(LOCK *lock, PROCLOCK *proclock, LOCKMODE lockmode)
{ {
lock->nGranted++; lock->nGranted++;
lock->granted[lockmode]++; lock->granted[lockmode]++;
lock->grantMask |= BITS_ON[lockmode]; lock->grantMask |= LOCKBIT_ON(lockmode);
if (lock->granted[lockmode] == lock->requested[lockmode]) if (lock->granted[lockmode] == lock->requested[lockmode])
lock->waitMask &= BITS_OFF[lockmode]; lock->waitMask &= LOCKBIT_OFF(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);
...@@ -862,14 +839,14 @@ GrantLock(LOCK *lock, PROCLOCK *proclock, LOCKMODE lockmode) ...@@ -862,14 +839,14 @@ GrantLock(LOCK *lock, PROCLOCK *proclock, LOCKMODE lockmode)
* The locktable's masterLock must be held at entry. * The locktable's masterLock must be held at entry.
*/ */
static int static int
WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode, WaitOnLock(LOCKMETHODID lockmethodid, LOCKMODE lockmode,
LOCK *lock, PROCLOCK *proclock) LOCK *lock, PROCLOCK *proclock)
{ {
LOCKMETHODTABLE *lockMethodTable = LockMethodTable[lockmethod]; LockMethod lockMethodTable = LockMethods[lockmethodid];
char *new_status, char *new_status,
*old_status; *old_status;
Assert(lockmethod < NumLockMethods); Assert(lockmethodid < NumLockMethods);
LOCK_PRINT("WaitOnLock: sleeping on lock", lock, lockmode); LOCK_PRINT("WaitOnLock: sleeping on lock", lock, lockmode);
...@@ -957,7 +934,7 @@ RemoveFromWaitQueue(PGPROC *proc) ...@@ -957,7 +934,7 @@ RemoveFromWaitQueue(PGPROC *proc)
waitLock->requested[lockmode]--; waitLock->requested[lockmode]--;
/* don't forget to clear waitMask bit if appropriate */ /* don't forget to clear waitMask bit if appropriate */
if (waitLock->granted[lockmode] == waitLock->requested[lockmode]) if (waitLock->granted[lockmode] == waitLock->requested[lockmode])
waitLock->waitMask &= BITS_OFF[lockmode]; waitLock->waitMask &= LOCKBIT_OFF(lockmode);
/* Clean up the proc's own state */ /* Clean up the proc's own state */
proc->waitLock = NULL; proc->waitLock = NULL;
...@@ -968,7 +945,7 @@ RemoveFromWaitQueue(PGPROC *proc) ...@@ -968,7 +945,7 @@ RemoveFromWaitQueue(PGPROC *proc)
} }
/* /*
* LockRelease -- look up 'locktag' in lock table 'lockmethod' and * LockRelease -- look up 'locktag' in lock table 'lockmethodid' and
* release one 'lockmode' lock on it. * release one 'lockmode' lock on it.
* *
* Side Effects: find any waiting processes that are now wakable, * Side Effects: find any waiting processes that are now wakable,
...@@ -978,27 +955,27 @@ RemoveFromWaitQueue(PGPROC *proc) ...@@ -978,27 +955,27 @@ RemoveFromWaitQueue(PGPROC *proc)
* come along and request the lock.) * come along and request the lock.)
*/ */
bool bool
LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, LockRelease(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
TransactionId xid, LOCKMODE lockmode) TransactionId xid, LOCKMODE lockmode)
{ {
LOCK *lock; LOCK *lock;
LWLockId masterLock; LWLockId masterLock;
LOCKMETHODTABLE *lockMethodTable; LockMethod lockMethodTable;
PROCLOCK *proclock; PROCLOCK *proclock;
PROCLOCKTAG proclocktag; PROCLOCKTAG proclocktag;
HTAB *proclockTable; HTAB *proclockTable;
bool wakeupNeeded = false; bool wakeupNeeded = false;
#ifdef LOCK_DEBUG #ifdef LOCK_DEBUG
if (lockmethod == USER_LOCKMETHOD && Trace_userlocks) if (lockmethodid == USER_LOCKMETHOD && Trace_userlocks)
elog(LOG, "LockRelease: user lock tag [%u] %d", locktag->objId.blkno, lockmode); elog(LOG, "LockRelease: user lock tag [%u] %d", locktag->objId.blkno, lockmode);
#endif #endif
/* ???????? This must be changed when short term locks will be used */ /* ???????? This must be changed when short term locks will be used */
locktag->lockmethod = lockmethod; locktag->lockmethodid = lockmethodid;
Assert(lockmethod < NumLockMethods); Assert(lockmethodid < NumLockMethods);
lockMethodTable = LockMethodTable[lockmethod]; lockMethodTable = LockMethods[lockmethodid];
if (!lockMethodTable) if (!lockMethodTable)
{ {
elog(WARNING, "lockMethodTable is null in LockRelease"); elog(WARNING, "lockMethodTable is null in LockRelease");
...@@ -1045,7 +1022,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -1045,7 +1022,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
{ {
LWLockRelease(masterLock); LWLockRelease(masterLock);
#ifdef USER_LOCKS #ifdef USER_LOCKS
if (lockmethod == USER_LOCKMETHOD) if (lockmethodid == USER_LOCKMETHOD)
elog(WARNING, "no lock with this tag"); elog(WARNING, "no lock with this tag");
else else
#endif #endif
...@@ -1083,7 +1060,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -1083,7 +1060,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
if (lock->granted[lockmode] == 0) if (lock->granted[lockmode] == 0)
{ {
/* change the conflict mask. No more of this lock type. */ /* change the conflict mask. No more of this lock type. */
lock->grantMask &= BITS_OFF[lockmode]; lock->grantMask &= LOCKBIT_OFF(lockmode);
} }
LOCK_PRINT("LockRelease: updated", lock, lockmode); LOCK_PRINT("LockRelease: updated", lock, lockmode);
...@@ -1173,29 +1150,29 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -1173,29 +1150,29 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
* specified XID are released. * specified XID are released.
*/ */
bool bool
LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, LockReleaseAll(LOCKMETHODID lockmethodid, PGPROC *proc,
bool allxids, TransactionId xid) bool allxids, TransactionId xid)
{ {
SHM_QUEUE *procHolders = &(proc->procHolders); SHM_QUEUE *procHolders = &(proc->procHolders);
PROCLOCK *proclock; PROCLOCK *proclock;
PROCLOCK *nextHolder; PROCLOCK *nextHolder;
LWLockId masterLock; LWLockId masterLock;
LOCKMETHODTABLE *lockMethodTable; LockMethod lockMethodTable;
int i, int i,
numLockModes; numLockModes;
LOCK *lock; LOCK *lock;
#ifdef LOCK_DEBUG #ifdef LOCK_DEBUG
if (lockmethod == USER_LOCKMETHOD ? Trace_userlocks : Trace_locks) if (lockmethodid == USER_LOCKMETHOD ? Trace_userlocks : Trace_locks)
elog(LOG, "LockReleaseAll: lockmethod=%d, pid=%d", elog(LOG, "LockReleaseAll: lockmethod=%d, pid=%d",
lockmethod, proc->pid); lockmethodid, proc->pid);
#endif #endif
Assert(lockmethod < NumLockMethods); Assert(lockmethodid < NumLockMethods);
lockMethodTable = LockMethodTable[lockmethod]; lockMethodTable = LockMethods[lockmethodid];
if (!lockMethodTable) if (!lockMethodTable)
{ {
elog(WARNING, "bad lock method: %d", lockmethod); elog(WARNING, "bad lock method: %d", lockmethodid);
return FALSE; return FALSE;
} }
...@@ -1220,7 +1197,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, ...@@ -1220,7 +1197,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc,
lock = (LOCK *) MAKE_PTR(proclock->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) != lockmethodid)
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 */
...@@ -1249,7 +1226,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, ...@@ -1249,7 +1226,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc,
lock->granted[i] -= proclock->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 &= LOCKBIT_OFF(i);
/* /*
* Read comments in LockRelease * Read comments in LockRelease
...@@ -1331,7 +1308,7 @@ next_item: ...@@ -1331,7 +1308,7 @@ next_item:
LWLockRelease(masterLock); LWLockRelease(masterLock);
#ifdef LOCK_DEBUG #ifdef LOCK_DEBUG
if (lockmethod == USER_LOCKMETHOD ? Trace_userlocks : Trace_locks) if (lockmethodid == USER_LOCKMETHOD ? Trace_userlocks : Trace_locks)
elog(LOG, "LockReleaseAll done"); elog(LOG, "LockReleaseAll done");
#endif #endif
...@@ -1346,7 +1323,7 @@ LockShmemSize(int maxBackends) ...@@ -1346,7 +1323,7 @@ LockShmemSize(int maxBackends)
size += MAXALIGN(sizeof(PROC_HDR)); /* ProcGlobal */ size += MAXALIGN(sizeof(PROC_HDR)); /* ProcGlobal */
size += maxBackends * MAXALIGN(sizeof(PGPROC)); /* each MyProc */ size += maxBackends * MAXALIGN(sizeof(PGPROC)); /* each MyProc */
size += MAX_LOCK_METHODS * MAXALIGN(sizeof(LOCKMETHODTABLE)); /* each lockMethodTable */ size += MAX_LOCK_METHODS * MAXALIGN(sizeof(LockMethodData)); /* each lock method */
/* lockHash table */ /* lockHash table */
size += hash_estimate_size(max_table_size, sizeof(LOCK)); size += hash_estimate_size(max_table_size, sizeof(LOCK));
...@@ -1390,7 +1367,7 @@ GetLockStatusData(void) ...@@ -1390,7 +1367,7 @@ GetLockStatusData(void)
LWLockAcquire(LockMgrLock, LW_EXCLUSIVE); LWLockAcquire(LockMgrLock, LW_EXCLUSIVE);
proclockTable = LockMethodTable[DEFAULT_LOCKMETHOD]->proclockHash; proclockTable = LockMethods[DEFAULT_LOCKMETHOD]->proclockHash;
data->nelements = i = proclockTable->hctl->nentries; data->nelements = i = proclockTable->hctl->nentries;
...@@ -1446,8 +1423,8 @@ DumpLocks(void) ...@@ -1446,8 +1423,8 @@ DumpLocks(void)
SHM_QUEUE *procHolders; SHM_QUEUE *procHolders;
PROCLOCK *proclock; PROCLOCK *proclock;
LOCK *lock; LOCK *lock;
int lockmethod = DEFAULT_LOCKMETHOD; int lockmethodid = DEFAULT_LOCKMETHOD;
LOCKMETHODTABLE *lockMethodTable; LockMethod lockMethodTable;
proc = MyProc; proc = MyProc;
if (proc == NULL) if (proc == NULL)
...@@ -1455,8 +1432,8 @@ DumpLocks(void) ...@@ -1455,8 +1432,8 @@ DumpLocks(void)
procHolders = &proc->procHolders; procHolders = &proc->procHolders;
Assert(lockmethod < NumLockMethods); Assert(lockmethodid < NumLockMethods);
lockMethodTable = LockMethodTable[lockmethod]; lockMethodTable = LockMethods[lockmethodid];
if (!lockMethodTable) if (!lockMethodTable)
return; return;
...@@ -1489,8 +1466,8 @@ DumpAllLocks(void) ...@@ -1489,8 +1466,8 @@ DumpAllLocks(void)
PGPROC *proc; PGPROC *proc;
PROCLOCK *proclock; PROCLOCK *proclock;
LOCK *lock; LOCK *lock;
int lockmethod = DEFAULT_LOCKMETHOD; int lockmethodid = DEFAULT_LOCKMETHOD;
LOCKMETHODTABLE *lockMethodTable; LockMethod lockMethodTable;
HTAB *proclockTable; HTAB *proclockTable;
HASH_SEQ_STATUS status; HASH_SEQ_STATUS status;
...@@ -1498,8 +1475,8 @@ DumpAllLocks(void) ...@@ -1498,8 +1475,8 @@ DumpAllLocks(void)
if (proc == NULL) if (proc == NULL)
return; return;
Assert(lockmethod < NumLockMethods); Assert(lockmethodid < NumLockMethods);
lockMethodTable = LockMethodTable[lockmethod]; lockMethodTable = LockMethods[lockmethodid];
if (!lockMethodTable) if (!lockMethodTable)
return; return;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.138 2003/11/29 19:51:57 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.139 2003/12/01 21:59:25 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -543,14 +543,14 @@ ProcQueueInit(PROC_QUEUE *queue) ...@@ -543,14 +543,14 @@ ProcQueueInit(PROC_QUEUE *queue)
* semaphore is normally zero, so when we try to acquire it, we sleep. * semaphore is normally zero, so when we try to acquire it, we sleep.
*/ */
int int
ProcSleep(LOCKMETHODTABLE *lockMethodTable, ProcSleep(LockMethod lockMethodTable,
LOCKMODE lockmode, LOCKMODE lockmode,
LOCK *lock, LOCK *lock,
PROCLOCK *proclock) PROCLOCK *proclock)
{ {
LWLockId masterLock = lockMethodTable->masterLock; LWLockId masterLock = lockMethodTable->masterLock;
PROC_QUEUE *waitQueue = &(lock->waitProcs); PROC_QUEUE *waitQueue = &(lock->waitProcs);
int myHeldLocks = MyProc->heldLocks; LOCKMASK myHeldLocks = MyProc->heldLocks;
bool early_deadlock = false; bool early_deadlock = false;
PGPROC *proc; PGPROC *proc;
int i; int i;
...@@ -575,7 +575,7 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable, ...@@ -575,7 +575,7 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable,
*/ */
if (myHeldLocks != 0) if (myHeldLocks != 0)
{ {
int aheadRequests = 0; LOCKMASK aheadRequests = 0;
proc = (PGPROC *) MAKE_PTR(waitQueue->links.next); proc = (PGPROC *) MAKE_PTR(waitQueue->links.next);
for (i = 0; i < waitQueue->size; i++) for (i = 0; i < waitQueue->size; i++)
...@@ -615,7 +615,7 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable, ...@@ -615,7 +615,7 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable,
break; break;
} }
/* Nope, so advance to next waiter */ /* Nope, so advance to next waiter */
aheadRequests |= (1 << proc->waitLockMode); aheadRequests |= LOCKBIT_ON(proc->waitLockMode);
proc = (PGPROC *) MAKE_PTR(proc->links.next); proc = (PGPROC *) MAKE_PTR(proc->links.next);
} }
...@@ -637,7 +637,7 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable, ...@@ -637,7 +637,7 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable,
SHMQueueInsertBefore(&(proc->links), &(MyProc->links)); SHMQueueInsertBefore(&(proc->links), &(MyProc->links));
waitQueue->size++; waitQueue->size++;
lock->waitMask |= (1 << lockmode); lock->waitMask |= LOCKBIT_ON(lockmode);
/* Set up wait information in PGPROC object, too */ /* Set up wait information in PGPROC object, too */
MyProc->waitLock = lock; MyProc->waitLock = lock;
...@@ -769,12 +769,12 @@ ProcWakeup(PGPROC *proc, int errType) ...@@ -769,12 +769,12 @@ ProcWakeup(PGPROC *proc, int errType)
* for lock, waken any that are no longer blocked. * for lock, waken any that are no longer blocked.
*/ */
void void
ProcLockWakeup(LOCKMETHODTABLE *lockMethodTable, LOCK *lock) ProcLockWakeup(LockMethod lockMethodTable, LOCK *lock)
{ {
PROC_QUEUE *waitQueue = &(lock->waitProcs); PROC_QUEUE *waitQueue = &(lock->waitProcs);
int queue_size = waitQueue->size; int queue_size = waitQueue->size;
PGPROC *proc; PGPROC *proc;
int aheadRequests = 0; LOCKMASK aheadRequests = 0;
Assert(queue_size >= 0); Assert(queue_size >= 0);
...@@ -815,7 +815,7 @@ ProcLockWakeup(LOCKMETHODTABLE *lockMethodTable, LOCK *lock) ...@@ -815,7 +815,7 @@ ProcLockWakeup(LOCKMETHODTABLE *lockMethodTable, LOCK *lock)
* Cannot wake this guy. Remember his request for later * Cannot wake this guy. Remember his request for later
* checks. * checks.
*/ */
aheadRequests |= (1 << lockmode); aheadRequests |= LOCKBIT_ON(lockmode);
proc = (PGPROC *) MAKE_PTR(proc->links.next); proc = (PGPROC *) MAKE_PTR(proc->links.next);
} }
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/storage/lmgr.h,v 1.41 2003/11/29 22:41:13 pgsql Exp $ * $PostgreSQL: pgsql/src/include/storage/lmgr.h,v 1.42 2003/12/01 21:59:25 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -40,10 +40,7 @@ ...@@ -40,10 +40,7 @@
* so increase that if you want to add more modes. * so increase that if you want to add more modes.
*/ */
extern LOCKMETHOD LockTableId; extern void InitLockTable(int maxBackends);
extern LOCKMETHOD InitLockTable(int maxBackends);
extern void RelationInitLockInfo(Relation relation); extern void RelationInitLockInfo(Relation relation);
/* Lock a relation */ /* Lock a relation */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.74 2003/11/29 22:41:13 pgsql Exp $ * $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.75 2003/12/01 21:59:25 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -42,22 +42,23 @@ extern bool Debug_deadlocks; ...@@ -42,22 +42,23 @@ extern bool Debug_deadlocks;
typedef int LOCKMASK; typedef int LOCKMASK;
typedef int LOCKMODE; typedef int LOCKMODE;
typedef int LOCKMETHOD;
/* MAX_LOCKMODES cannot be larger than the # of bits in LOCKMASK */ /* MAX_LOCKMODES cannot be larger than the # of bits in LOCKMASK */
#define MAX_LOCKMODES 10 #define MAX_LOCKMODES 10
#define LOCKBIT_ON(lockmode) (1 << (lockmode))
#define LOCKBIT_OFF(lockmode) (~(1 << (lockmode)))
typedef uint16 LOCKMETHODID;
/* MAX_LOCK_METHODS is the number of distinct lock control tables allowed */ /* MAX_LOCK_METHODS is the number of distinct lock control tables allowed */
#define MAX_LOCK_METHODS 3 #define MAX_LOCK_METHODS 3
#define INVALID_TABLEID 0 #define INVALID_LOCKMETHOD 0
#define INVALID_LOCKMETHOD INVALID_TABLEID
#define DEFAULT_LOCKMETHOD 1 #define DEFAULT_LOCKMETHOD 1
#define USER_LOCKMETHOD 2 #define USER_LOCKMETHOD 2
#define LockMethodIsValid(lockmethodid) ((lockmethodid) != INVALID_LOCKMETHOD)
/* /*
* There is normally only one lock method, the default one. * There is normally only one lock method, the default one.
* If user locks are enabled, an additional lock method is present. * If user locks are enabled, an additional lock method is present.
...@@ -83,15 +84,16 @@ typedef int LOCKMETHOD; ...@@ -83,15 +84,16 @@ typedef int LOCKMETHOD;
* masterLock -- synchronizes access to the table * masterLock -- synchronizes access to the table
* *
*/ */
typedef struct LOCKMETHODTABLE typedef struct LockMethodData
{ {
HTAB *lockHash; HTAB *lockHash;
HTAB *proclockHash; HTAB *proclockHash;
LOCKMETHOD lockmethod; LOCKMETHODID lockmethodid;
int numLockModes; int numLockModes;
int conflictTab[MAX_LOCKMODES]; LOCKMASK conflictTab[MAX_LOCKMODES];
LWLockId masterLock; LWLockId masterLock;
} LOCKMETHODTABLE; } LockMethodData;
typedef LockMethodData *LockMethod;
/* /*
...@@ -115,7 +117,7 @@ typedef struct LOCKTAG ...@@ -115,7 +117,7 @@ typedef struct LOCKTAG
*/ */
OffsetNumber offnum; OffsetNumber offnum;
uint16 lockmethod; /* needed by userlocks */ LOCKMETHODID lockmethodid; /* needed by userlocks */
} LOCKTAG; } LOCKTAG;
...@@ -139,8 +141,8 @@ typedef struct LOCK ...@@ -139,8 +141,8 @@ typedef struct LOCK
LOCKTAG tag; /* unique identifier of lockable object */ LOCKTAG tag; /* unique identifier of lockable object */
/* data */ /* data */
int grantMask; /* bitmask for lock types already granted */ LOCKMASK grantMask; /* bitmask for lock types already granted */
int waitMask; /* bitmask for lock types awaited */ LOCKMASK waitMask; /* bitmask for lock types awaited */
SHM_QUEUE lockHolders; /* list of PROCLOCK objects assoc. with SHM_QUEUE lockHolders; /* list of PROCLOCK objects assoc. with
* lock */ * lock */
PROC_QUEUE waitProcs; /* list of PGPROC objects waiting on lock */ PROC_QUEUE waitProcs; /* list of PGPROC objects waiting on lock */
...@@ -151,7 +153,7 @@ typedef struct LOCK ...@@ -151,7 +153,7 @@ typedef struct LOCK
int nGranted; /* total of granted[] array */ int nGranted; /* total of granted[] array */
} LOCK; } LOCK;
#define LOCK_LOCKMETHOD(lock) ((lock).tag.lockmethod) #define LOCK_LOCKMETHOD(lock) ((lock).tag.lockmethodid)
/* /*
...@@ -204,7 +206,7 @@ typedef struct PROCLOCK ...@@ -204,7 +206,7 @@ typedef struct PROCLOCK
} PROCLOCK; } PROCLOCK;
#define PROCLOCK_LOCKMETHOD(proclock) \ #define PROCLOCK_LOCKMETHOD(proclock) \
(((LOCK *) MAKE_PTR((proclock).tag.lock))->tag.lockmethod) (((LOCK *) MAKE_PTR((proclock).tag.lock))->tag.lockmethodid)
/* /*
* This struct holds information passed from lmgr internals to the lock * This struct holds information passed from lmgr internals to the lock
...@@ -227,17 +229,17 @@ typedef struct ...@@ -227,17 +229,17 @@ typedef struct
* function prototypes * function prototypes
*/ */
extern void InitLocks(void); extern void InitLocks(void);
extern LOCKMETHODTABLE *GetLocksMethodTable(LOCK *lock); extern LockMethod GetLocksMethodTable(LOCK *lock);
extern LOCKMETHOD LockMethodTableInit(char *tabName, LOCKMASK *conflictsP, extern LOCKMETHODID LockMethodTableInit(char *tabName, LOCKMASK *conflictsP,
int numModes, int maxBackends); int numModes, int maxBackends);
extern LOCKMETHOD LockMethodTableRename(LOCKMETHOD lockmethod); extern LOCKMETHODID LockMethodTableRename(LOCKMETHODID lockmethodid);
extern bool LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, extern bool LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
TransactionId xid, LOCKMODE lockmode, bool dontWait); TransactionId xid, LOCKMODE lockmode, bool dontWait);
extern bool LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, extern bool LockRelease(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
TransactionId xid, LOCKMODE lockmode); TransactionId xid, LOCKMODE lockmode);
extern bool LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, extern bool LockReleaseAll(LOCKMETHODID lockmethodid, PGPROC *proc,
bool allxids, TransactionId xid); bool allxids, TransactionId xid);
extern int LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable, extern int LockCheckConflicts(LockMethod lockMethodTable,
LOCKMODE lockmode, LOCKMODE lockmode,
LOCK *lock, PROCLOCK *proclock, PGPROC *proc, LOCK *lock, PROCLOCK *proclock, PGPROC *proc,
int *myHolding); int *myHolding);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.66 2003/11/29 22:41:13 pgsql Exp $ * $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.67 2003/12/01 21:59:25 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -106,10 +106,10 @@ extern void InitDummyProcess(int proctype); ...@@ -106,10 +106,10 @@ extern void InitDummyProcess(int proctype);
extern void ProcReleaseLocks(bool isCommit); 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(LockMethod lockMethodTable, LOCKMODE lockmode,
LOCK *lock, PROCLOCK *proclock); 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(LockMethod lockMethodTable, LOCK *lock);
extern bool LockWaitCancel(void); extern bool LockWaitCancel(void);
extern void ProcWaitForSignal(void); extern void ProcWaitForSignal(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