aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/lmgr
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/storage/lmgr')
-rw-r--r--src/backend/storage/lmgr/deadlock.c35
-rw-r--r--src/backend/storage/lmgr/lock.c65
-rw-r--r--src/backend/storage/lmgr/proc.c25
3 files changed, 65 insertions, 60 deletions
diff --git a/src/backend/storage/lmgr/deadlock.c b/src/backend/storage/lmgr/deadlock.c
index 757f1df2f4f..1106a76c3df 100644
--- a/src/backend/storage/lmgr/deadlock.c
+++ b/src/backend/storage/lmgr/deadlock.c
@@ -12,7 +12,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/deadlock.c,v 1.21 2003/07/24 22:04:13 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/deadlock.c,v 1.22 2003/08/04 00:43:24 momjian Exp $
*
* Interface:
*
@@ -49,7 +49,7 @@ typedef struct
} WAIT_ORDER;
/*
- * Information saved about each edge in a detected deadlock cycle. This
+ * Information saved about each edge in a detected deadlock cycle. This
* is used to print a diagnostic message upon failure.
*
* Note: because we want to examine this info after releasing the LockMgrLock,
@@ -61,7 +61,7 @@ typedef struct
LOCKTAG locktag; /* ID of awaited lock object */
LOCKMODE lockmode; /* type of lock we're waiting for */
int pid; /* PID of blocked backend */
-} DEADLOCK_INFO;
+} DEADLOCK_INFO;
static bool DeadLockCheckRecurse(PGPROC *proc);
@@ -147,7 +147,7 @@ InitDeadLockChecking(void)
* We need to consider rearranging at most MaxBackends/2 wait queues
* (since it takes at least two waiters in a queue to create a soft
* edge), and the expanded form of the wait queues can't involve more
- * than MaxBackends total waiters. (But avoid palloc(0) if
+ * than MaxBackends total waiters. (But avoid palloc(0) if
* MaxBackends = 1.)
*/
waitOrders = (WAIT_ORDER *)
@@ -221,7 +221,7 @@ DeadLockCheck(PGPROC *proc)
* Call FindLockCycle one more time, to record the correct
* deadlockDetails[] for the basic state with no rearrangements.
*/
- int nSoftEdges;
+ int nSoftEdges;
nWaitOrders = 0;
if (!FindLockCycle(proc, possibleConstraints, &nSoftEdges))
@@ -486,7 +486,7 @@ FindLockCycleRecurse(PGPROC *checkProc,
lockHolders = &(lock->lockHolders);
proclock = (PROCLOCK *) SHMQueueNext(lockHolders, lockHolders,
- offsetof(PROCLOCK, lockLink));
+ offsetof(PROCLOCK, lockLink));
while (proclock)
{
@@ -501,11 +501,11 @@ FindLockCycleRecurse(PGPROC *checkProc,
((1 << lm) & conflictMask) != 0)
{
/* This proc hard-blocks checkProc */
- if (FindLockCycleRecurse(proc, depth+1,
+ if (FindLockCycleRecurse(proc, depth + 1,
softEdges, nSoftEdges))
{
/* fill deadlockDetails[] */
- DEADLOCK_INFO *info = &deadlockDetails[depth];
+ DEADLOCK_INFO *info = &deadlockDetails[depth];
info->locktag = lock->tag;
info->lockmode = checkProc->waitLockMode;
@@ -558,11 +558,11 @@ FindLockCycleRecurse(PGPROC *checkProc,
if (((1 << proc->waitLockMode) & conflictMask) != 0)
{
/* This proc soft-blocks checkProc */
- if (FindLockCycleRecurse(proc, depth+1,
+ if (FindLockCycleRecurse(proc, depth + 1,
softEdges, nSoftEdges))
{
/* fill deadlockDetails[] */
- DEADLOCK_INFO *info = &deadlockDetails[depth];
+ DEADLOCK_INFO *info = &deadlockDetails[depth];
info->locktag = lock->tag;
info->lockmode = checkProc->waitLockMode;
@@ -599,11 +599,11 @@ FindLockCycleRecurse(PGPROC *checkProc,
if (((1 << proc->waitLockMode) & conflictMask) != 0)
{
/* This proc soft-blocks checkProc */
- if (FindLockCycleRecurse(proc, depth+1,
+ if (FindLockCycleRecurse(proc, depth + 1,
softEdges, nSoftEdges))
{
/* fill deadlockDetails[] */
- DEADLOCK_INFO *info = &deadlockDetails[depth];
+ DEADLOCK_INFO *info = &deadlockDetails[depth];
info->locktag = lock->tag;
info->lockmode = checkProc->waitLockMode;
@@ -834,7 +834,6 @@ PrintLockQueue(LOCK *lock, const char *info)
printf("\n");
fflush(stdout);
}
-
#endif
/*
@@ -843,17 +842,17 @@ PrintLockQueue(LOCK *lock, const char *info)
void
DeadLockReport(void)
{
- StringInfoData buf;
- int i;
+ StringInfoData buf;
+ int i;
initStringInfo(&buf);
for (i = 0; i < nDeadlockDetails; i++)
{
- DEADLOCK_INFO *info = &deadlockDetails[i];
+ DEADLOCK_INFO *info = &deadlockDetails[i];
int nextpid;
/* The last proc waits for the first one... */
- if (i < nDeadlockDetails-1)
+ if (i < nDeadlockDetails - 1)
nextpid = info[1].pid;
else
nextpid = deadlockDetails[0].pid;
@@ -900,7 +899,7 @@ RememberSimpleDeadLock(PGPROC *proc1,
LOCK *lock,
PGPROC *proc2)
{
- DEADLOCK_INFO *info = &deadlockDetails[0];
+ DEADLOCK_INFO *info = &deadlockDetails[0];
info->locktag = lock->tag;
info->lockmode = lockmode;
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index 2e71f40c09b..9d4c52f75fa 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.124 2003/07/28 00:09:15 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.125 2003/08/04 00:43:24 momjian Exp $
*
* NOTES
* Outside modules can create a lock table and acquire/release
@@ -127,9 +127,9 @@ inline static void
PROCLOCK_PRINT(const char *where, const PROCLOCK *proclockP)
{
if (
- (((PROCLOCK_LOCKMETHOD(*proclockP) == DEFAULT_LOCKMETHOD && Trace_locks)
- || (PROCLOCK_LOCKMETHOD(*proclockP) == USER_LOCKMETHOD && Trace_userlocks))
- && (((LOCK *) MAKE_PTR(proclockP->tag.lock))->tag.relId >= (Oid) Trace_lock_oidmin))
+ (((PROCLOCK_LOCKMETHOD(*proclockP) == DEFAULT_LOCKMETHOD && Trace_locks)
+ || (PROCLOCK_LOCKMETHOD(*proclockP) == USER_LOCKMETHOD && Trace_userlocks))
+ && (((LOCK *) MAKE_PTR(proclockP->tag.lock))->tag.relId >= (Oid) Trace_lock_oidmin))
|| (Trace_lock_table && (((LOCK *) MAKE_PTR(proclockP->tag.lock))->tag.relId == Trace_lock_table))
)
elog(LOG,
@@ -137,8 +137,8 @@ PROCLOCK_PRINT(const char *where, const PROCLOCK *proclockP)
where, MAKE_OFFSET(proclockP), proclockP->tag.lock,
PROCLOCK_LOCKMETHOD(*(proclockP)),
proclockP->tag.proc, proclockP->tag.xid,
- proclockP->holding[1], proclockP->holding[2], proclockP->holding[3],
- proclockP->holding[4], proclockP->holding[5], proclockP->holding[6],
+ proclockP->holding[1], proclockP->holding[2], proclockP->holding[3],
+ proclockP->holding[4], proclockP->holding[5], proclockP->holding[6],
proclockP->holding[7], proclockP->nHolding);
}
@@ -321,10 +321,10 @@ LockMethodTableInit(char *tabName,
sprintf(shmemName, "%s (proclock hash)", tabName);
lockMethodTable->proclockHash = ShmemInitHash(shmemName,
- init_table_size,
- max_table_size,
- &info,
- hash_flags);
+ init_table_size,
+ max_table_size,
+ &info,
+ hash_flags);
if (!lockMethodTable->proclockHash)
elog(FATAL, "could not initialize lock table \"%s\"", tabName);
@@ -509,8 +509,8 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
/*
* Create the hash key for the proclock table.
*/
- MemSet(&proclocktag, 0, sizeof(PROCLOCKTAG)); /* must clear padding,
- * needed */
+ MemSet(&proclocktag, 0, sizeof(PROCLOCKTAG)); /* must clear padding,
+ * needed */
proclocktag.lock = MAKE_OFFSET(lock);
proclocktag.proc = MAKE_OFFSET(MyProc);
TransactionIdStore(xid, &proclocktag.xid);
@@ -520,8 +520,8 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
*/
proclockTable = lockMethodTable->proclockHash;
proclock = (PROCLOCK *) hash_search(proclockTable,
- (void *) &proclocktag,
- HASH_ENTER, &found);
+ (void *) &proclocktag,
+ HASH_ENTER, &found);
if (!proclock)
{
LWLockRelease(masterLock);
@@ -604,8 +604,8 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
}
/*
- * If this process (under any XID) is a proclock of the lock, also grant
- * myself another one without blocking.
+ * If this process (under any XID) is a proclock of the lock, also
+ * grant myself another one without blocking.
*/
LockCountMyLocks(proclock->tag.lock, MyProc, myHolding);
if (myHolding[lockmode] > 0)
@@ -649,8 +649,8 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
SHMQueueDelete(&proclock->lockLink);
SHMQueueDelete(&proclock->procLink);
proclock = (PROCLOCK *) hash_search(proclockTable,
- (void *) proclock,
- HASH_REMOVE, NULL);
+ (void *) proclock,
+ HASH_REMOVE, NULL);
if (!proclock)
elog(WARNING, "proclock table corrupted");
}
@@ -818,7 +818,7 @@ LockCountMyLocks(SHMEM_OFFSET lockOffset, PGPROC *proc, int *myHolding)
MemSet(myHolding, 0, MAX_LOCKMODES * sizeof(int));
proclock = (PROCLOCK *) SHMQueueNext(procHolders, procHolders,
- offsetof(PROCLOCK, procLink));
+ offsetof(PROCLOCK, procLink));
while (proclock)
{
@@ -908,9 +908,10 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
*/
LOCK_PRINT("WaitOnLock: aborting on lock", lock, lockmode);
LWLockRelease(lockMethodTable->masterLock);
+
/*
- * Now that we aren't holding the LockMgrLock, we can give an error
- * report including details about the detected deadlock.
+ * Now that we aren't holding the LockMgrLock, we can give an
+ * error report including details about the detected deadlock.
*/
DeadLockReport();
/* not reached */
@@ -1033,16 +1034,16 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
/*
* Find the proclock entry for this proclock.
*/
- MemSet(&proclocktag, 0, sizeof(PROCLOCKTAG)); /* must clear padding,
- * needed */
+ MemSet(&proclocktag, 0, sizeof(PROCLOCKTAG)); /* must clear padding,
+ * needed */
proclocktag.lock = MAKE_OFFSET(lock);
proclocktag.proc = MAKE_OFFSET(MyProc);
TransactionIdStore(xid, &proclocktag.xid);
proclockTable = lockMethodTable->proclockHash;
proclock = (PROCLOCK *) hash_search(proclockTable,
- (void *) &proclocktag,
- HASH_FIND_SAVE, NULL);
+ (void *) &proclocktag,
+ HASH_FIND_SAVE, NULL);
if (!proclock)
{
LWLockRelease(masterLock);
@@ -1143,8 +1144,8 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
SHMQueueDelete(&proclock->lockLink);
SHMQueueDelete(&proclock->procLink);
proclock = (PROCLOCK *) hash_search(proclockTable,
- (void *) &proclock,
- HASH_REMOVE_SAVED, NULL);
+ (void *) &proclock,
+ HASH_REMOVE_SAVED, NULL);
if (!proclock)
{
LWLockRelease(masterLock);
@@ -1207,7 +1208,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc,
LWLockAcquire(masterLock, LW_EXCLUSIVE);
proclock = (PROCLOCK *) SHMQueueNext(procHolders, procHolders,
- offsetof(PROCLOCK, procLink));
+ offsetof(PROCLOCK, procLink));
while (proclock)
{
@@ -1295,9 +1296,9 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc,
* remove the proclock entry from the hashtable
*/
proclock = (PROCLOCK *) hash_search(lockMethodTable->proclockHash,
- (void *) proclock,
- HASH_REMOVE,
- NULL);
+ (void *) proclock,
+ HASH_REMOVE,
+ NULL);
if (!proclock)
{
LWLockRelease(masterLock);
@@ -1466,7 +1467,7 @@ DumpLocks(void)
LOCK_PRINT("DumpLocks: waiting on", proc->waitLock, 0);
proclock = (PROCLOCK *) SHMQueueNext(procHolders, procHolders,
- offsetof(PROCLOCK, procLink));
+ offsetof(PROCLOCK, procLink));
while (proclock)
{
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c
index eebd696c2c2..3bdda5924d7 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.131 2003/07/24 22:04:14 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.132 2003/08/04 00:43:24 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -78,6 +78,7 @@ static bool waitingForSignal = false;
/* Mark these volatile because they can be changed by signal handler */
static volatile bool statement_timeout_active = false;
static volatile bool deadlock_timeout_active = false;
+
/* statement_fin_time is valid only if statement_timeout_active is true */
static struct timeval statement_fin_time;
@@ -571,7 +572,8 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable,
* up correctly is to call RemoveFromWaitQueue(), but
* we can't do that until we are *on* the wait queue.
* So, set a flag to check below, and break out of
- * loop. Also, record deadlock info for later message.
+ * loop. Also, record deadlock info for later
+ * message.
*/
RememberSimpleDeadLock(MyProc, lockmode, lock, proc);
early_deadlock = true;
@@ -950,11 +952,13 @@ bool
enable_sig_alarm(int delayms, bool is_statement_timeout)
{
#ifdef WIN32
-# warning add Win32 timer
+#warning add Win32 timer
#else
struct timeval fin_time;
+
#ifndef __BEOS__
struct itimerval timeval;
+
#else
bigtime_t time_interval;
#endif
@@ -984,16 +988,16 @@ enable_sig_alarm(int delayms, bool is_statement_timeout)
/*
* Begin deadlock timeout with statement-level timeout active
*
- * Here, we want to interrupt at the closer of the two timeout
- * times. If fin_time >= statement_fin_time then we need not
- * touch the existing timer setting; else set up to interrupt
- * at the deadlock timeout time.
+ * Here, we want to interrupt at the closer of the two timeout times.
+ * If fin_time >= statement_fin_time then we need not touch the
+ * existing timer setting; else set up to interrupt at the
+ * deadlock timeout time.
*
* NOTE: in this case it is possible that this routine will be
* interrupted by the previously-set timer alarm. This is okay
- * because the signal handler will do only what it should do according
- * to the state variables. The deadlock checker may get run earlier
- * than normal, but that does no harm.
+ * because the signal handler will do only what it should do
+ * according to the state variables. The deadlock checker may get
+ * run earlier than normal, but that does no harm.
*/
deadlock_timeout_active = true;
if (fin_time.tv_sec > statement_fin_time.tv_sec ||
@@ -1037,6 +1041,7 @@ disable_sig_alarm(bool is_statement_timeout)
#ifdef WIN32
#warning add Win32 timer
#else
+
/*
* Always disable the interrupt if it is active; this avoids being
* interrupted by the signal handler and thereby possibly getting