*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.30 1998/06/27 15:47:46 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.31 1998/06/28 21:17:34 momjian Exp $
*
* NOTES
* Outside modules can create a lock table and acquire/release
static int
WaitOnLock(LOCKTAB *ltable, LockTableId tableId, LOCK *lock,
- LOCKT lockt);
+ LOCKTYPE locktype);
/*#define LOCK_MGR_DEBUG*/
* xid.xid current xid 0
* persistence transaction user or backend
*
- * The lockt parameter can have the same values for normal locks
+ * The locktype parameter can have the same values for normal locks
* although probably only WRITE_LOCK can have some practical use.
*
* DZ - 4 Oct 1996
*/
bool
-LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKT lockt)
+LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype)
{
XIDLookupEnt *result,
item;
lockName->tupleId.ip_posid,
((lockName->tupleId.ip_blkid.bi_hi << 16) +
lockName->tupleId.ip_blkid.bi_lo),
- lockt);
+ locktype);
#endif
}
#endif
if (LockingIsDisabled)
return (TRUE);
- LOCK_PRINT("Acquire", lockName, lockt);
+ LOCK_PRINT("Acquire", lockName, locktype);
masterLock = ltable->ctl->masterLock;
SpinAcquire(masterLock);
* ----------------
*/
lock->nHolding++;
- lock->holders[lockt]++;
+ lock->holders[locktype]++;
/* --------------------
* If I'm the only one holding a lock, then there
*/
if (result->nHolding == lock->nActive)
{
- result->holders[lockt]++;
+ result->holders[locktype]++;
result->nHolding++;
- GrantLock(lock, lockt);
+ GrantLock(lock, locktype);
SpinRelease(masterLock);
return (TRUE);
}
Assert(result->nHolding <= lock->nActive);
- status = LockResolveConflicts(ltable, lock, lockt, myXid);
+ status = LockResolveConflicts(ltable, lock, locktype, myXid);
if (status == STATUS_OK)
- GrantLock(lock, lockt);
+ GrantLock(lock, locktype);
else if (status == STATUS_FOUND)
{
#ifdef USER_LOCKS
hash_search(xidTable, (Pointer) &item, HASH_REMOVE, &found);
}
lock->nHolding--;
- lock->holders[lockt]--;
+ lock->holders[locktype]--;
SpinRelease(masterLock);
#ifdef USER_LOCKS_DEBUG
elog(NOTICE, "LockAcquire: user lock failed");
return (FALSE);
}
#endif
- status = WaitOnLock(ltable, tableId, lock, lockt);
+ status = WaitOnLock(ltable, tableId, lock, locktype);
XID_PRINT("Someone granted me the lock", result);
}
int
LockResolveConflicts(LOCKTAB *ltable,
LOCK *lock,
- LOCKT lockt,
+ LOCKTYPE locktype,
TransactionId xid)
{
XIDLookupEnt *result,
* do not continue and share the lock, even if we can. bjm
* ------------------------
*/
- int myprio = ltable->ctl->prio[lockt];
+ int myprio = ltable->ctl->prio[locktype];
PROC_QUEUE *waitQueue = &(lock->waitProcs);
PROC *topproc = (PROC *) MAKE_PTR(waitQueue->links.prev);
* with mine, then I get the lock.
*
* Checking for conflict: lock->mask represents the types of
- * currently held locks. conflictTable[lockt] has a bit
+ * currently held locks. conflictTable[locktype] has a bit
* set for each type of lock that conflicts with mine. Bitwise
* compare tells if there is a conflict.
* ----------------------------
*/
- if (!(ltable->ctl->conflictTab[lockt] & lock->mask))
+ if (!(ltable->ctl->conflictTab[locktype] & lock->mask))
{
- result->holders[lockt]++;
+ result->holders[locktype]++;
result->nHolding++;
XID_PRINT("Conflict Resolved: updated xid entry stats", result);
* conflict and I have to sleep.
* ------------------------
*/
- if (!(ltable->ctl->conflictTab[lockt] & bitmask))
+ if (!(ltable->ctl->conflictTab[locktype] & bitmask))
{
/* no conflict. Get the lock and go on */
- result->holders[lockt]++;
+ result->holders[locktype]++;
result->nHolding++;
XID_PRINT("Conflict Resolved: updated xid entry stats", result);
}
static int
-WaitOnLock(LOCKTAB *ltable, LockTableId tableId, LOCK *lock, LOCKT lockt)
+WaitOnLock(LOCKTAB *ltable, LockTableId tableId, LOCK *lock, LOCKTYPE locktype)
{
PROC_QUEUE *waitQueue = &(lock->waitProcs);
- int prio = ltable->ctl->prio[lockt];
+ int prio = ltable->ctl->prio[locktype];
/*
* the waitqueue is ordered by priority. I insert myself according to
* synchronization for this queue. That will not be true if/when
* people can be deleted from the queue by a SIGINT or something.
*/
- LOCK_DUMP_AUX("WaitOnLock: sleeping on lock", lock, lockt);
+ LOCK_DUMP_AUX("WaitOnLock: sleeping on lock", lock, locktype);
if (ProcSleep(waitQueue,
ltable->ctl->masterLock,
- lockt,
+ locktype,
prio,
lock) != NO_ERROR)
{
* -------------------
*/
lock->nHolding--;
- lock->holders[lockt]--;
- LOCK_DUMP_AUX("WaitOnLock: aborting on lock", lock, lockt);
+ lock->holders[locktype]--;
+ LOCK_DUMP_AUX("WaitOnLock: aborting on lock", lock, locktype);
SpinRelease(ltable->ctl->masterLock);
elog(ERROR, "WaitOnLock: error on wakeup - Aborting this transaction");
}
- LOCK_DUMP_AUX("WaitOnLock: wakeup on lock", lock, lockt);
+ LOCK_DUMP_AUX("WaitOnLock: wakeup on lock", lock, locktype);
return (STATUS_OK);
}
* come along and request the lock).
*/
bool
-LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKT lockt)
+LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype)
{
LOCK *lock = NULL;
SPINLOCK masterLock;
lockName->tupleId.ip_posid,
((lockName->tupleId.ip_blkid.bi_hi << 16) +
lockName->tupleId.ip_blkid.bi_lo),
- lockt);
+ locktype);
#endif
}
#endif
if (LockingIsDisabled)
return (TRUE);
- LOCK_PRINT("Release", lockName, lockt);
+ LOCK_PRINT("Release", lockName, locktype);
masterLock = ltable->ctl->masterLock;
xidTable = ltable->xidHash;
* fix the general lock stats
*/
lock->nHolding--;
- lock->holders[lockt]--;
+ lock->holders[locktype]--;
lock->nActive--;
- lock->activeHolders[lockt]--;
+ lock->activeHolders[locktype]--;
Assert(lock->nActive >= 0);
* now check to see if I have any private locks. If I do, decrement
* the counts associated with them.
*/
- result->holders[lockt]--;
+ result->holders[locktype]--;
result->nHolding--;
XID_PRINT("LockRelease updated xid stats", result);
* fix the general lock stats
*/
lock->nHolding--;
- lock->holders[lockt]--;
+ lock->holders[locktype]--;
lock->nActive--;
- lock->activeHolders[lockt]--;
+ lock->activeHolders[locktype]--;
Assert(lock->nActive >= 0);
* with the remaining locks.
* --------------------------
*/
- if (!(lock->activeHolders[lockt]))
+ if (!(lock->activeHolders[locktype]))
{
/* change the conflict mask. No more of this lock type. */
- lock->mask &= BITS_OFF[lockt];
+ lock->mask &= BITS_OFF[locktype];
}
if (wakeupNeeded)
* the new lock holder.
*/
void
-GrantLock(LOCK *lock, LOCKT lockt)
+GrantLock(LOCK *lock, LOCKTYPE locktype)
{
lock->nActive++;
- lock->activeHolders[lockt]++;
- lock->mask |= BITS_ON[lockt];
+ lock->activeHolders[locktype]++;
+ lock->mask |= BITS_ON[locktype];
}
#ifdef USER_LOCKS
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/multi.c,v 1.17 1998/06/27 04:53:38 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/multi.c,v 1.18 1998/06/28 21:17:35 momjian Exp $
*
* NOTES:
* (1) The lock.c module assumes that the caller here is doing
#include "miscadmin.h" /* MyDatabaseId */
static bool
-MultiAcquire(LockTableId tableId, LOCKTAG *tag, LOCKT lockt,
+MultiAcquire(LockTableId tableId, LOCKTAG *tag, LOCKTYPE locktype,
PG_LOCK_LEVEL level);
static bool
-MultiRelease(LockTableId tableId, LOCKTAG *tag, LOCKT lockt,
+MultiRelease(LockTableId tableId, LOCKTAG *tag, LOCKTYPE locktype,
PG_LOCK_LEVEL level);
/*
* Returns: TRUE if the lock can be set, FALSE otherwise.
*/
bool
-MultiLockReln(LockInfo linfo, LOCKT lockt)
+MultiLockReln(LockInfo linfo, LOCKTYPE locktype)
{
LOCKTAG tag;
MemSet(&tag, 0, sizeof(tag));
tag.relId = linfo->lRelId.relId;
tag.dbId = linfo->lRelId.dbId;
- return (MultiAcquire(MultiTableId, &tag, lockt, RELN_LEVEL));
+ return (MultiAcquire(MultiTableId, &tag, locktype, RELN_LEVEL));
}
/*
* at the page and relation level.
*/
bool
-MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKT lockt)
+MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
{
LOCKTAG tag;
/* not locking any valid Tuple, just the page */
tag.tupleId = *tidPtr;
- return (MultiAcquire(MultiTableId, &tag, lockt, TUPLE_LEVEL));
+ return (MultiAcquire(MultiTableId, &tag, locktype, TUPLE_LEVEL));
}
/*
* same as above at page level
*/
bool
-MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKT lockt)
+MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
{
LOCKTAG tag;
tag.relId = linfo->lRelId.relId;
tag.dbId = linfo->lRelId.dbId;
BlockIdCopy(&(tag.tupleId.ip_blkid), &(tidPtr->ip_blkid));
- return (MultiAcquire(MultiTableId, &tag, lockt, PAGE_LEVEL));
+ return (MultiAcquire(MultiTableId, &tag, locktype, PAGE_LEVEL));
}
/*
static bool
MultiAcquire(LockTableId tableId,
LOCKTAG *tag,
- LOCKT lockt,
+ LOCKTYPE locktype,
PG_LOCK_LEVEL level)
{
- LOCKT locks[N_LEVELS];
+ LOCKTYPE locks[N_LEVELS];
int i,
status;
LOCKTAG xxTag,
switch (level)
{
case RELN_LEVEL:
- locks[0] = lockt;
+ locks[0] = locktype;
locks[1] = NO_LOCK;
locks[2] = NO_LOCK;
break;
case PAGE_LEVEL:
- locks[0] = lockt + INTENT;
- locks[1] = lockt;
+ locks[0] = locktype + INTENT;
+ locks[1] = locktype;
locks[2] = NO_LOCK;
break;
case TUPLE_LEVEL:
- locks[0] = lockt + INTENT;
- locks[1] = lockt + INTENT;
- locks[2] = lockt;
+ locks[0] = locktype + INTENT;
+ locks[1] = locktype + INTENT;
+ locks[2] = locktype;
break;
default:
elog(ERROR, "MultiAcquire: bad lock level");
* the last level lock we successfully acquired
*/
retStatus = FALSE;
- MultiRelease(tableId, tag, lockt, i);
+ MultiRelease(tableId, tag, locktype, i);
/* now leave the loop. Don't try for any more locks */
break;
}
*/
#ifdef NOT_USED
bool
-MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKT lockt)
+MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
{
LOCKTAG tag;
tag.dbId = linfo->lRelId.dbId;
BlockIdCopy(&(tag.tupleId.ip_blkid), &(tidPtr->ip_blkid));
- return (MultiRelease(MultiTableId, &tag, lockt, PAGE_LEVEL));
+ return (MultiRelease(MultiTableId, &tag, locktype, PAGE_LEVEL));
}
#endif
* ------------------
*/
bool
-MultiReleaseReln(LockInfo linfo, LOCKT lockt)
+MultiReleaseReln(LockInfo linfo, LOCKTYPE locktype)
{
LOCKTAG tag;
tag.relId = linfo->lRelId.relId;
tag.dbId = linfo->lRelId.dbId;
- return (MultiRelease(MultiTableId, &tag, lockt, RELN_LEVEL));
+ return (MultiRelease(MultiTableId, &tag, locktype, RELN_LEVEL));
}
/*
static bool
MultiRelease(LockTableId tableId,
LOCKTAG *tag,
- LOCKT lockt,
+ LOCKTYPE locktype,
PG_LOCK_LEVEL level)
{
- LOCKT locks[N_LEVELS];
+ LOCKTYPE locks[N_LEVELS];
int i,
status;
LOCKTAG xxTag,
switch (level)
{
case RELN_LEVEL:
- locks[0] = lockt;
+ locks[0] = locktype;
locks[1] = NO_LOCK;
locks[2] = NO_LOCK;
break;
case PAGE_LEVEL:
- locks[0] = lockt + INTENT;
- locks[1] = lockt;
+ locks[0] = locktype + INTENT;
+ locks[1] = locktype;
locks[2] = NO_LOCK;
break;
case TUPLE_LEVEL:
- locks[0] = lockt + INTENT;
- locks[1] = lockt + INTENT;
- locks[2] = lockt;
+ locks[0] = locktype + INTENT;
+ locks[1] = locktype + INTENT;
+ locks[2] = locktype;
break;
default:
- elog(ERROR, "MultiRelease: bad lockt");
+ elog(ERROR, "MultiRelease: bad locktype");
}
/*
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/single.c,v 1.5 1997/09/18 20:21:40 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/single.c,v 1.6 1998/06/28 21:17:35 momjian Exp $
*
*-------------------------------------------------------------------------
*/
* Returns: TRUE if the lock can be set, FALSE otherwise.
*/
bool
-SingleLockReln(LockInfo linfo, LOCKT lockt, int action)
+SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action)
{
LOCKTAG tag;
tag.tupleId.ip_posid = InvalidOffsetNumber;
if (action == UNLOCK)
- return (LockRelease(MultiTableId, &tag, lockt));
+ return (LockRelease(MultiTableId, &tag, locktype));
else
- return (LockAcquire(MultiTableId, &tag, lockt));
+ return (LockAcquire(MultiTableId, &tag, locktype));
}
/*
bool
SingleLockPage(LockInfo linfo,
ItemPointer tidPtr,
- LOCKT lockt,
+ LOCKTYPE locktype,
int action)
{
LOCKTAG tag;
if (action == UNLOCK)
- return (LockRelease(MultiTableId, &tag, lockt));
+ return (LockRelease(MultiTableId, &tag, locktype));
else
- return (LockAcquire(MultiTableId, &tag, lockt));
+ return (LockAcquire(MultiTableId, &tag, locktype));
}
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: lmgr.h,v 1.10 1998/02/26 04:43:27 momjian Exp $
+ * $Id: lmgr.h,v 1.11 1998/06/28 21:17:35 momjian Exp $
*
*-------------------------------------------------------------------------
*/
extern void RelationUnsetWIntentLock(Relation relation);
/* single.c */
-extern bool SingleLockReln(LockInfo linfo, LOCKT lockt, int action);
+extern bool SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action);
extern bool
SingleLockPage(LockInfo linfo, ItemPointer tidPtr,
- LOCKT lockt, int action);
+ LOCKTYPE locktype, int action);
/* proc.c */
extern void InitProcGlobal(IPCKey key);
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: lock.h,v 1.13 1998/06/26 01:58:46 momjian Exp $
+ * $Id: lock.h,v 1.14 1998/06/28 21:17:35 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#define NLOCKENTS NLOCKS_PER_XACT*NBACKENDS
typedef int LOCK_TYPE;
-typedef int LOCKT;
+typedef int LOCKTYPE;
typedef int LockTableId;
/* MAX_LOCKTYPES cannot be larger than the bits in MASK */
#define LockGetLock_nHolders(l) l->nHolders
-#define LockDecrWaitHolders(lock, lockt) \
+#define LockDecrWaitHolders(lock, locktype) \
( \
lock->nHolding--, \
- lock->holders[lockt]-- \
+ lock->holders[locktype]-- \
)
#define LockLockTable() SpinAcquire(LockMgrLock);
extern LockTableId
LockTableInit(char *tabName, MASK *conflictsP, int *prioP,
int ntypes);
-extern bool LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKT lockt);
+extern bool LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype);
extern int
-LockResolveConflicts(LOCKTAB *ltable, LOCK *lock, LOCKT lockt,
+LockResolveConflicts(LOCKTAB *ltable, LOCK *lock, LOCKTYPE locktype,
TransactionId xid);
-extern bool LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKT lockt);
-extern void GrantLock(LOCK *lock, LOCKT lockt);
+extern bool LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype);
+extern void GrantLock(LOCK *lock, LOCKTYPE locktype);
extern bool LockReleaseAll(LockTableId tableId, SHM_QUEUE *lockQueue);
extern int LockShmemSize(void);
extern bool LockingDisabled(void);
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: multilev.h,v 1.8 1998/06/26 19:57:50 momjian Exp $
+ * $Id: multilev.h,v 1.9 1998/06/28 21:17:36 momjian Exp $
*
*-------------------------------------------------------------------------
*/
* function prototypes
*/
extern LockTableId InitMultiLevelLocks(void);
-extern bool MultiLockReln(LockInfo linfo, LOCKT lockt);
-extern bool MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKT lockt);
-extern bool MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKT lockt);
-extern bool MultiReleaseReln(LockInfo linfo, LOCKT lockt);
+extern bool MultiLockReln(LockInfo linfo, LOCKTYPE locktype);
+extern bool MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype);
+extern bool MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype);
+extern bool MultiReleaseReln(LockInfo linfo, LOCKTYPE locktype);
#endif /* MULTILEV_H */