MCPcopy Create free account
hub / github.com/apache/cloudberry / ResRemoveFromWaitQueue

Function ResRemoveFromWaitQueue

src/backend/utils/resscheduler/resqueue.c:1494–1554  ·  view source on GitHub ↗

* ResRemoveFromWaitQueue -- Remove a process from the wait queue, cleaning up * any locks. */

Source from the content-addressed store, hash-verified

1492 * any locks.
1493 */
1494void
1495ResRemoveFromWaitQueue(PGPROC *proc, uint32 hashcode)
1496{
1497 LOCK *waitLock = proc->waitLock;
1498 PROCLOCK *proclock = proc->waitProcLock;
1499 LOCKMODE lockmode = proc->waitLockMode;
1500#ifdef USE_ASSERT_CHECKING
1501 LOCKMETHODID lockmethodid = LOCK_LOCKMETHOD(*waitLock);
1502#endif /* USE_ASSERT_CHECKING */
1503 ResPortalTag portalTag;
1504
1505 /* Make sure lockmethod is for a resource lock. */
1506 Assert(lockmethodid == RESOURCE_LOCKMETHOD);
1507
1508 /* Make sure proc is waiting */
1509 Assert(proc->links.next != NULL);
1510 Assert(waitLock);
1511 Assert(waitLock->waitProcs.size > 0);
1512
1513 /* Remove proc from lock's wait queue */
1514 SHMQueueDelete(&(proc->links));
1515 waitLock->waitProcs.size--;
1516
1517 /* Undo increments of request counts by waiting process */
1518 Assert(waitLock->nRequested > 0);
1519 Assert(waitLock->nRequested > proc->waitLock->nGranted);
1520
1521 waitLock->nRequested--;
1522 Assert(waitLock->requested[lockmode] > 0);
1523 waitLock->requested[lockmode]--;
1524
1525 /* don't forget to clear waitMask bit if appropriate */
1526 if (waitLock->granted[lockmode] == waitLock->requested[lockmode])
1527 waitLock->waitMask &= LOCKBIT_OFF(lockmode);
1528
1529 /* Clean up the proc's own state */
1530 proc->waitLock = NULL;
1531 proc->waitProcLock = NULL;
1532 proc->waitStatus = STATUS_ERROR;
1533
1534 /*
1535 * Remove the waited on portal increment.
1536 */
1537 MemSet(&portalTag, 0, sizeof(ResPortalTag));
1538 portalTag.pid = MyProc->pid;
1539 portalTag.portalId = MyProc->waitPortalId;
1540
1541 LWLockAcquire(ResQueueLock, LW_EXCLUSIVE);
1542 ResIncrementRemove(&portalTag);
1543
1544 /*
1545 * Delete the proclock immediately if it represents no already-held locks.
1546 * (This must happen now because if the owner of the lock decides to
1547 * release it, and the requested/granted counts then go to zero,
1548 * LockRelease expects there to be no remaining proclocks.) Then see if
1549 * any other waiters for the lock can be woken up now.
1550 */
1551 ResCleanUpLock(waitLock, proclock, hashcode, true);

Callers 2

CheckDeadLockFunction · 0.85
ResLockWaitCancelFunction · 0.85

Calls 5

SHMQueueDeleteFunction · 0.85
LWLockAcquireFunction · 0.85
ResIncrementRemoveFunction · 0.85
ResCleanUpLockFunction · 0.85
LWLockReleaseFunction · 0.85

Tested by

no test coverage detected