* TerminateBufferIO: release a buffer we were doing I/O on * (Assumptions) * My process is executing IO for the buffer * BM_IO_IN_PROGRESS bit is set for the buffer * The buffer is Pinned * * If clear_dirty is true and BM_JUST_DIRTIED is not set, we clear the * buffer's BM_DIRTY flag. This is appropriate when terminating a * successful write. The check on BM_JUST_DIRTIED is necessary to
| 4728 | * be 0, or BM_VALID if we just finished reading in the page. |
| 4729 | */ |
| 4730 | static void |
| 4731 | TerminateBufferIO(BufferDesc *buf, bool clear_dirty, uint32 set_flag_bits) |
| 4732 | { |
| 4733 | uint32 buf_state; |
| 4734 | |
| 4735 | Assert(buf == InProgressBuf); |
| 4736 | |
| 4737 | buf_state = LockBufHdr(buf); |
| 4738 | |
| 4739 | Assert(buf_state & BM_IO_IN_PROGRESS); |
| 4740 | |
| 4741 | buf_state &= ~(BM_IO_IN_PROGRESS | BM_IO_ERROR); |
| 4742 | if (clear_dirty && !(buf_state & BM_JUST_DIRTIED)) |
| 4743 | buf_state &= ~(BM_DIRTY | BM_CHECKPOINT_NEEDED); |
| 4744 | |
| 4745 | buf_state |= set_flag_bits; |
| 4746 | UnlockBufHdr(buf, buf_state); |
| 4747 | |
| 4748 | InProgressBuf = NULL; |
| 4749 | |
| 4750 | #ifdef MPROTECT_BUFFERS |
| 4751 | /* XXX: should this be PROT_NONE if called from AbortBufferIO? */ |
| 4752 | if (!LWLockHeldByMe(BufferDescriptorGetContentLock(buf))) |
| 4753 | BufferMProtect(buf, PROT_READ); |
| 4754 | #endif |
| 4755 | ConditionVariableBroadcast(BufferDescriptorGetIOCV(buf)); |
| 4756 | } |
| 4757 | |
| 4758 | /* |
| 4759 | * AbortBufferIO: Clean up any active buffer I/O after an error. |
no test coverage detected