Convert macros to static inline functions (bufmgr.h)

Reviewed-by: Amul Sul <sulamul@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/5b558da8-99fb-0a99-83dd-f72f05388517%40enterprisedb.com
This commit is contained in:
Peter Eisentraut 2022-07-13 14:33:03 +02:00
parent aeb767ca0b
commit 9c727360bc

View File

@ -98,7 +98,7 @@ extern PGDLLIMPORT int32 *LocalRefCount;
#define BUFFER_LOCK_EXCLUSIVE 2 #define BUFFER_LOCK_EXCLUSIVE 2
/* /*
* These routines are beaten on quite heavily, hence the macroization. * These routines are beaten on quite heavily, hence inline.
*/ */
/* /*
@ -120,11 +120,14 @@ extern PGDLLIMPORT int32 *LocalRefCount;
* even in non-assert-enabled builds can be significant. Thus, we've * even in non-assert-enabled builds can be significant. Thus, we've
* now demoted the range checks to assertions within the macro itself. * now demoted the range checks to assertions within the macro itself.
*/ */
#define BufferIsValid(bufnum) \ static inline bool
( \ BufferIsValid(Buffer bufnum)
AssertMacro((bufnum) <= NBuffers && (bufnum) >= -NLocBuffer), \ {
(bufnum) != InvalidBuffer \ Assert(bufnum <= NBuffers);
) Assert(bufnum >= -NLocBuffer);
return bufnum != InvalidBuffer;
}
/* /*
* BufferGetBlock * BufferGetBlock
@ -133,14 +136,16 @@ extern PGDLLIMPORT int32 *LocalRefCount;
* Note: * Note:
* Assumes buffer is valid. * Assumes buffer is valid.
*/ */
#define BufferGetBlock(buffer) \ static inline Block
( \ BufferGetBlock(Buffer buffer)
AssertMacro(BufferIsValid(buffer)), \ {
BufferIsLocal(buffer) ? \ Assert(BufferIsValid(buffer));
LocalBufferBlockPointers[-(buffer) - 1] \
: \ if (BufferIsLocal(buffer))
(Block) (BufferBlocks + ((Size) ((buffer) - 1)) * BLCKSZ) \ return LocalBufferBlockPointers[-buffer - 1];
) else
return (Block) (BufferBlocks + ((Size) (buffer - 1)) * BLCKSZ);
}
/* /*
* BufferGetPageSize * BufferGetPageSize
@ -153,11 +158,12 @@ extern PGDLLIMPORT int32 *LocalRefCount;
* (formatted) disk page. * (formatted) disk page.
*/ */
/* XXX should dig out of buffer descriptor */ /* XXX should dig out of buffer descriptor */
#define BufferGetPageSize(buffer) \ static inline Size
( \ BufferGetPageSize(Buffer buffer)
AssertMacro(BufferIsValid(buffer)), \ {
(Size)BLCKSZ \ AssertMacro(BufferIsValid(buffer));
) return (Size) BLCKSZ;
}
/* /*
* BufferGetPage * BufferGetPage
@ -166,7 +172,11 @@ extern PGDLLIMPORT int32 *LocalRefCount;
* When this is called as part of a scan, there may be a need for a nearby * 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. * call to TestForOldSnapshot(). See the definition of that for details.
*/ */
#define BufferGetPage(buffer) ((Page)BufferGetBlock(buffer)) static inline Page
BufferGetPage(Buffer buffer)
{
return (Page) BufferGetBlock(buffer);
}
/* /*
* prototypes for functions in bufmgr.c * prototypes for functions in bufmgr.c
@ -201,6 +211,12 @@ extern void CheckPointBuffers(int flags);
extern BlockNumber BufferGetBlockNumber(Buffer buffer); extern BlockNumber BufferGetBlockNumber(Buffer buffer);
extern BlockNumber RelationGetNumberOfBlocksInFork(Relation relation, extern BlockNumber RelationGetNumberOfBlocksInFork(Relation relation,
ForkNumber forkNum); ForkNumber forkNum);
static inline BlockNumber
RelationGetNumberOfBlocks(Relation reln)
{
return RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM);
}
extern void FlushOneBuffer(Buffer buffer); extern void FlushOneBuffer(Buffer buffer);
extern void FlushRelationBuffers(Relation rel); extern void FlushRelationBuffers(Relation rel);
extern void FlushRelationsAllBuffers(struct SMgrRelationData **smgrs, int nrels); extern void FlushRelationsAllBuffers(struct SMgrRelationData **smgrs, int nrels);
@ -215,9 +231,6 @@ extern void DropRelationsAllBuffers(struct SMgrRelationData **smgr_reln,
int nlocators); int nlocators);
extern void DropDatabaseBuffers(Oid dbid); extern void DropDatabaseBuffers(Oid dbid);
#define RelationGetNumberOfBlocks(reln) \
RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM)
extern bool BufferIsPermanent(Buffer buffer); extern bool BufferIsPermanent(Buffer buffer);
extern XLogRecPtr BufferGetLSNAtomic(Buffer buffer); extern XLogRecPtr BufferGetLSNAtomic(Buffer buffer);