File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -5873,6 +5873,47 @@ IsBufferCleanupOK(Buffer buffer)
58735873 return false;
58745874}
58755875
5876+ /*
5877+ * BufferLockHeldByMe - does the backend have the buffer locked?
5878+ *
5879+ * This likely should only be used for asserts etc.
5880+ *
5881+ * Note that this can only be called for non-temp buffers - there is no
5882+ * correct value to return for temporary buffers. One might think that just
5883+ * returning true for temp buffers would work, but the caller might assert
5884+ * that a lock is *not* held.
5885+ */
5886+ bool
5887+ BufferLockHeldByMe (Buffer buffer , int mode )
5888+ {
5889+ BufferDesc * buf ;
5890+ LWLockMode lwmode ;
5891+
5892+ /*
5893+ * Can't hold a lock without a pin, there never should be uncertainty
5894+ * about having a pin.
5895+ */
5896+ Assert (BufferIsPinned (buffer ));
5897+
5898+ /* there'd be no correct value to return */
5899+ Assert (!BufferIsLocal (buffer ));
5900+
5901+ buf = GetBufferDescriptor (buffer - 1 );
5902+
5903+ if (mode == BUFFER_LOCK_EXCLUSIVE )
5904+ lwmode = LW_EXCLUSIVE ;
5905+ else if (mode == BUFFER_LOCK_SHARE )
5906+ lwmode = LW_SHARED ;
5907+ else
5908+ {
5909+ Assert (false);
5910+ pg_unreachable ();
5911+ lwmode = LW_EXCLUSIVE ; /* assuage compiler */
5912+ }
5913+
5914+ return LWLockHeldByMeInMode (BufferDescriptorGetContentLock (buf ), lwmode );
5915+ }
5916+
58765917
58775918/*
58785919 * Functions for buffer I/O handling
Original file line number Diff line number Diff line change @@ -294,6 +294,7 @@ extern void LockBufferForCleanup(Buffer buffer);
294294extern bool ConditionalLockBufferForCleanup (Buffer buffer );
295295extern bool IsBufferCleanupOK (Buffer buffer );
296296extern bool HoldingBufferPinThatDelaysRecovery (void );
297+ extern bool BufferLockHeldByMe (Buffer buffer , int mode );
297298
298299extern bool BgBufferSync (struct WritebackContext * wb_context );
299300
You can’t perform that action at this time.
0 commit comments