#define BUFFER_LOCK_SHARE 1
#define BUFFER_LOCK_EXCLUSIVE 2
-/*
- * These routines are beaten on quite heavily, hence inline.
- */
-
-/*
- * BufferIsValid
- * True iff the given buffer number is valid (either as a shared
- * or local buffer).
- *
- * Note: For a long time this was defined the same as BufferIsPinned,
- * that is it would say False if you didn't hold a pin on the buffer.
- * I believe this was bogus and served only to mask logic errors.
- * Code should always know whether it has a buffer reference,
- * independently of the pin state.
- *
- * Note: For a further long time this was not quite the inverse of the
- * BufferIsInvalid() macro, in that it also did sanity checks to verify
- * that the buffer number was in range. Most likely, this macro was
- * originally intended only to be used in assertions, but its use has
- * since expanded quite a bit, and the overhead of making those checks
- * even in non-assert-enabled builds can be significant. Thus, we've
- * now demoted the range checks to assertions within the macro itself.
- */
-static inline bool
-BufferIsValid(Buffer bufnum)
-{
- Assert(bufnum <= NBuffers);
- Assert(bufnum >= -NLocBuffer);
-
- return bufnum != InvalidBuffer;
-}
-
-/*
- * BufferGetBlock
- * Returns a reference to a disk page image associated with a buffer.
- *
- * Note:
- * Assumes buffer is valid.
- */
-static inline Block
-BufferGetBlock(Buffer buffer)
-{
- Assert(BufferIsValid(buffer));
-
- if (BufferIsLocal(buffer))
- return LocalBufferBlockPointers[-buffer - 1];
- else
- return (Block) (BufferBlocks + ((Size) (buffer - 1)) * BLCKSZ);
-}
-
-/*
- * BufferGetPageSize
- * Returns the page size within a buffer.
- *
- * Notes:
- * Assumes buffer is valid.
- *
- * The buffer can be a raw disk block and need not contain a valid
- * (formatted) disk page.
- */
-/* XXX should dig out of buffer descriptor */
-static inline Size
-BufferGetPageSize(Buffer buffer)
-{
- AssertMacro(BufferIsValid(buffer));
- return (Size) BLCKSZ;
-}
-
-/*
- * BufferGetPage
- * Returns the page associated with a buffer.
- *
- * When this is called as part of a scan, there may be a need for a nearby
- * call to TestForOldSnapshot(). See the definition of that for details.
- */
-static inline Page
-BufferGetPage(Buffer buffer)
-{
- return (Page) BufferGetBlock(buffer);
-}
/*
* prototypes for functions in bufmgr.c
extern BlockNumber BufferGetBlockNumber(Buffer buffer);
extern BlockNumber RelationGetNumberOfBlocksInFork(Relation relation,
ForkNumber forkNum);
-static inline BlockNumber
-RelationGetNumberOfBlocks(Relation reln)
-{
- return RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM);
-}
-
extern void FlushOneBuffer(Buffer buffer);
extern void FlushRelationBuffers(Relation rel);
extern void FlushRelationsAllBuffers(struct SMgrRelationData **smgrs, int nrels);
int nlocators);
extern void DropDatabaseBuffers(Oid dbid);
+#define RelationGetNumberOfBlocks(reln) \
+ RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM)
+
extern bool BufferIsPermanent(Buffer buffer);
extern XLogRecPtr BufferGetLSNAtomic(Buffer buffer);
#ifndef FRONTEND
+/*
+ * BufferIsValid
+ * True iff the given buffer number is valid (either as a shared
+ * or local buffer).
+ *
+ * Note: For a long time this was defined the same as BufferIsPinned,
+ * that is it would say False if you didn't hold a pin on the buffer.
+ * I believe this was bogus and served only to mask logic errors.
+ * Code should always know whether it has a buffer reference,
+ * independently of the pin state.
+ *
+ * Note: For a further long time this was not quite the inverse of the
+ * BufferIsInvalid() macro, in that it also did sanity checks to verify
+ * that the buffer number was in range. Most likely, this macro was
+ * originally intended only to be used in assertions, but its use has
+ * since expanded quite a bit, and the overhead of making those checks
+ * even in non-assert-enabled builds can be significant. Thus, we've
+ * now demoted the range checks to assertions within the macro itself.
+ */
+static inline bool
+BufferIsValid(Buffer bufnum)
+{
+ Assert(bufnum <= NBuffers);
+ Assert(bufnum >= -NLocBuffer);
+
+ return bufnum != InvalidBuffer;
+}
+
+/*
+ * BufferGetBlock
+ * Returns a reference to a disk page image associated with a buffer.
+ *
+ * Note:
+ * Assumes buffer is valid.
+ */
+static inline Block
+BufferGetBlock(Buffer buffer)
+{
+ Assert(BufferIsValid(buffer));
+
+ if (BufferIsLocal(buffer))
+ return LocalBufferBlockPointers[-buffer - 1];
+ else
+ return (Block) (BufferBlocks + ((Size) (buffer - 1)) * BLCKSZ);
+}
+
+/*
+ * BufferGetPageSize
+ * Returns the page size within a buffer.
+ *
+ * Notes:
+ * Assumes buffer is valid.
+ *
+ * The buffer can be a raw disk block and need not contain a valid
+ * (formatted) disk page.
+ */
+/* XXX should dig out of buffer descriptor */
+static inline Size
+BufferGetPageSize(Buffer buffer)
+{
+ AssertMacro(BufferIsValid(buffer));
+ return (Size) BLCKSZ;
+}
+
+/*
+ * BufferGetPage
+ * Returns the page associated with a buffer.
+ *
+ * When this is called as part of a scan, there may be a need for a nearby
+ * call to TestForOldSnapshot(). See the definition of that for details.
+ */
+static inline Page
+BufferGetPage(Buffer buffer)
+{
+ return (Page) BufferGetBlock(buffer);
+}
+
/*
* Check whether the given snapshot is too old to have safely read the given
* page from the given table. If so, throw a "snapshot too old" error.