* Acquire or release the content_lock for the buffer. */
| 4287 | * Acquire or release the content_lock for the buffer. |
| 4288 | */ |
| 4289 | void |
| 4290 | LockBuffer(Buffer buffer, int mode) |
| 4291 | { |
| 4292 | BufferDesc *buf; |
| 4293 | |
| 4294 | Assert(BufferIsPinned(buffer)); |
| 4295 | if (BufferIsLocal(buffer)) |
| 4296 | return; /* local buffers need no lock */ |
| 4297 | |
| 4298 | buf = GetBufferDescriptor(buffer - 1); |
| 4299 | |
| 4300 | if (mode == BUFFER_LOCK_UNLOCK) |
| 4301 | ReleaseContentLock(buf); |
| 4302 | else if (mode == BUFFER_LOCK_SHARE) |
| 4303 | AcquireContentLock(buf, LW_SHARED); |
| 4304 | else if (mode == BUFFER_LOCK_EXCLUSIVE) |
| 4305 | AcquireContentLock(buf, LW_EXCLUSIVE); |
| 4306 | else |
| 4307 | elog(ERROR, "unrecognized buffer lock mode: %d", mode); |
| 4308 | } |
| 4309 | |
| 4310 | /* |
| 4311 | * Acquire the content_lock for the buffer, but only if we don't have to wait. |
no test coverage detected