* WaitIO -- Block until the IO_IN_PROGRESS flag on 'buf' is cleared. */
| 4630 | * WaitIO -- Block until the IO_IN_PROGRESS flag on 'buf' is cleared. |
| 4631 | */ |
| 4632 | static void |
| 4633 | WaitIO(BufferDesc *buf) |
| 4634 | { |
| 4635 | ConditionVariable *cv = BufferDescriptorGetIOCV(buf); |
| 4636 | |
| 4637 | ConditionVariablePrepareToSleep(cv); |
| 4638 | for (;;) |
| 4639 | { |
| 4640 | uint32 buf_state; |
| 4641 | |
| 4642 | /* |
| 4643 | * It may not be necessary to acquire the spinlock to check the flag |
| 4644 | * here, but since this test is essential for correctness, we'd better |
| 4645 | * play it safe. |
| 4646 | */ |
| 4647 | buf_state = LockBufHdr(buf); |
| 4648 | UnlockBufHdr(buf, buf_state); |
| 4649 | |
| 4650 | if (!(buf_state & BM_IO_IN_PROGRESS)) |
| 4651 | break; |
| 4652 | ConditionVariableSleep(cv, WAIT_EVENT_BUFFER_IO); |
| 4653 | } |
| 4654 | ConditionVariableCancelSleep(); |
| 4655 | } |
| 4656 | |
| 4657 | /* |
| 4658 | * StartBufferIO: begin I/O on this buffer |
no test coverage detected