提交 3a1ced8f 编写于 作者: D Daniel Gustafsson

Fix LOCK_DEBUG in LWLock acquiring

Commit ea9df812 relaxes the requirement
that all LWLocks are in a single array, which broke the LOCK_DEBUG
code for trying to acquiring an LWLock. This is a meatball surgery
attempt at making it at least compile and run, without trying to
reinvent the old usecase.

Minor tweaking of the code is also done to make LOCK_DEBUG cases be
identified identically.

Reported-by: Simon Gao in Github issue #7251
Reviewed-by: Ashwin Agrawal
上级 3ba6c5cd
...@@ -417,14 +417,9 @@ LWLockAssign(void) ...@@ -417,14 +417,9 @@ LWLockAssign(void)
#ifdef LOCK_DEBUG #ifdef LOCK_DEBUG
static void static void
LWLockTryLockWaiting( LWLockTryLockWaiting(PGPROC *proc, volatile LWLock *l)
PGPROC *proc,
LWLockId lockid,
LWLockMode mode)
{ {
volatile LWLock *lock = &(LWLockArray[lockid].lock); int milliseconds = 0;
int milliseconds = 0;
int exclusivePid;
while(true) while(true)
{ {
...@@ -432,46 +427,13 @@ LWLockTryLockWaiting( ...@@ -432,46 +427,13 @@ LWLockTryLockWaiting(
if (PGSemaphoreTryLock(&proc->sem)) if (PGSemaphoreTryLock(&proc->sem))
{ {
if (milliseconds >= 750) if (milliseconds >= 750)
elog(LOG, "Done waiting on lockid %d", lockid); elog(LOG, "Done waiting on lockid %d", T_ID(l));
return; return;
} }
milliseconds += 5; milliseconds += 5;
if (milliseconds == 750) if (milliseconds == 750)
{ elog(LOG, "Waited .75 seconds on lockid %d with no success", T_ID(l));
int l;
int count = 0;
char buffer[200];
SpinLockAcquire(&lock->mutex);
if (lock->exclusive > 0)
exclusivePid = lock->exclusivePid;
else
exclusivePid = 0;
SpinLockRelease(&lock->mutex);
memcpy(buffer, "none", 5);
for (l = 0; l < num_held_lwlocks; l++)
{
if (l == 0)
count += sprintf(&buffer[count],"(");
else
count += sprintf(&buffer[count],", ");
count += sprintf(&buffer[count],
"lockid %d",
held_lwlocks[l]);
}
if (num_held_lwlocks > 0)
count += sprintf(&buffer[count],")");
elog(LOG, "Waited .75 seconds on lockid %d with no success. Exclusive pid %d. Already held: %s",
lockid, exclusivePid, buffer);
}
} }
} }
...@@ -716,10 +678,10 @@ LWLockAcquireCommon(LWLock *l, LWLockMode mode, uint64 *valptr, uint64 val) ...@@ -716,10 +678,10 @@ LWLockAcquireCommon(LWLock *l, LWLockMode mode, uint64 *valptr, uint64 val)
for (;;) for (;;)
{ {
/* "false" means cannot accept cancel/die interrupt here. */ /* "false" means cannot accept cancel/die interrupt here. */
#ifndef LOCK_DEBUG #ifdef LOCK_DEBUG
PGSemaphoreLock(&proc->sem, false); LWLockTryLockWaiting(proc, lock);
#else #else
LWLockTryLockWaiting(proc, lockid, mode); PGSemaphoreLock(&proc->sem, false);
#endif #endif
if (!proc->lwWaiting) if (!proc->lwWaiting)
break; break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册