* Insert MyProc into the specified SyncRepQueue, maintaining sorted invariant. * * Usually we will go at tail of queue, though it's possible that we arrive * here out of order, so start at tail and work back to insertion point. */
| 506 | * here out of order, so start at tail and work back to insertion point. |
| 507 | */ |
| 508 | static void |
| 509 | SyncRepQueueInsert(int mode) |
| 510 | { |
| 511 | PGPROC *proc; |
| 512 | |
| 513 | Assert(mode >= 0 && mode < NUM_SYNC_REP_WAIT_MODE); |
| 514 | proc = (PGPROC *) SHMQueuePrev(&(WalSndCtl->SyncRepQueue[mode]), |
| 515 | &(WalSndCtl->SyncRepQueue[mode]), |
| 516 | offsetof(PGPROC, syncRepLinks)); |
| 517 | |
| 518 | while (proc) |
| 519 | { |
| 520 | /* |
| 521 | * Stop at the queue element that we should after to ensure the queue |
| 522 | * is ordered by LSN. |
| 523 | */ |
| 524 | if (proc->waitLSN < MyProc->waitLSN) |
| 525 | break; |
| 526 | |
| 527 | proc = (PGPROC *) SHMQueuePrev(&(WalSndCtl->SyncRepQueue[mode]), |
| 528 | &(proc->syncRepLinks), |
| 529 | offsetof(PGPROC, syncRepLinks)); |
| 530 | } |
| 531 | |
| 532 | if (proc) |
| 533 | SHMQueueInsertAfter(&(proc->syncRepLinks), &(MyProc->syncRepLinks)); |
| 534 | else |
| 535 | SHMQueueInsertAfter(&(WalSndCtl->SyncRepQueue[mode]), &(MyProc->syncRepLinks)); |
| 536 | } |
| 537 | |
| 538 | /* |
| 539 | * Acquire SyncRepLock and cancel any wait currently in progress. |
no test coverage detected