@@ -97,86 +97,6 @@ extern PGDLLIMPORT int32 *LocalRefCount;
97
97
#define BUFFER_LOCK_SHARE 1
98
98
#define BUFFER_LOCK_EXCLUSIVE 2
99
99
100
- /*
101
- * These routines are beaten on quite heavily, hence inline.
102
- */
103
-
104
- /*
105
- * BufferIsValid
106
- * True iff the given buffer number is valid (either as a shared
107
- * or local buffer).
108
- *
109
- * Note: For a long time this was defined the same as BufferIsPinned,
110
- * that is it would say False if you didn't hold a pin on the buffer.
111
- * I believe this was bogus and served only to mask logic errors.
112
- * Code should always know whether it has a buffer reference,
113
- * independently of the pin state.
114
- *
115
- * Note: For a further long time this was not quite the inverse of the
116
- * BufferIsInvalid() macro, in that it also did sanity checks to verify
117
- * that the buffer number was in range. Most likely, this macro was
118
- * originally intended only to be used in assertions, but its use has
119
- * since expanded quite a bit, and the overhead of making those checks
120
- * even in non-assert-enabled builds can be significant. Thus, we've
121
- * now demoted the range checks to assertions within the macro itself.
122
- */
123
- static inline bool
124
- BufferIsValid (Buffer bufnum )
125
- {
126
- Assert (bufnum <= NBuffers );
127
- Assert (bufnum >= - NLocBuffer );
128
-
129
- return bufnum != InvalidBuffer ;
130
- }
131
-
132
- /*
133
- * BufferGetBlock
134
- * Returns a reference to a disk page image associated with a buffer.
135
- *
136
- * Note:
137
- * Assumes buffer is valid.
138
- */
139
- static inline Block
140
- BufferGetBlock (Buffer buffer )
141
- {
142
- Assert (BufferIsValid (buffer ));
143
-
144
- if (BufferIsLocal (buffer ))
145
- return LocalBufferBlockPointers [- buffer - 1 ];
146
- else
147
- return (Block ) (BufferBlocks + ((Size ) (buffer - 1 )) * BLCKSZ );
148
- }
149
-
150
- /*
151
- * BufferGetPageSize
152
- * Returns the page size within a buffer.
153
- *
154
- * Notes:
155
- * Assumes buffer is valid.
156
- *
157
- * The buffer can be a raw disk block and need not contain a valid
158
- * (formatted) disk page.
159
- */
160
- /* XXX should dig out of buffer descriptor */
161
- static inline Size
162
- BufferGetPageSize (Buffer buffer )
163
- {
164
- AssertMacro (BufferIsValid (buffer ));
165
- return (Size ) BLCKSZ ;
166
- }
167
-
168
- /*
169
- * BufferGetPage
170
- * Returns the page associated with a buffer.
171
- *
172
- * When this is called as part of a scan, there may be a need for a nearby
173
- * call to TestForOldSnapshot(). See the definition of that for details.
174
- */
175
- static inline Page
176
- BufferGetPage (Buffer buffer )
177
- {
178
- return (Page ) BufferGetBlock (buffer );
179
- }
180
100
181
101
/*
182
102
* prototypes for functions in bufmgr.c
@@ -211,12 +131,6 @@ extern void CheckPointBuffers(int flags);
211
131
extern BlockNumber BufferGetBlockNumber (Buffer buffer );
212
132
extern BlockNumber RelationGetNumberOfBlocksInFork (Relation relation ,
213
133
ForkNumber forkNum );
214
- static inline BlockNumber
215
- RelationGetNumberOfBlocks (Relation reln )
216
- {
217
- return RelationGetNumberOfBlocksInFork (reln , MAIN_FORKNUM );
218
- }
219
-
220
134
extern void FlushOneBuffer (Buffer buffer );
221
135
extern void FlushRelationBuffers (Relation rel );
222
136
extern void FlushRelationsAllBuffers (struct SMgrRelationData * * smgrs , int nrels );
@@ -231,6 +145,9 @@ extern void DropRelationsAllBuffers(struct SMgrRelationData **smgr_reln,
231
145
int nlocators );
232
146
extern void DropDatabaseBuffers (Oid dbid );
233
147
148
+ #define RelationGetNumberOfBlocks (reln ) \
149
+ RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM)
150
+
234
151
extern bool BufferIsPermanent (Buffer buffer );
235
152
extern XLogRecPtr BufferGetLSNAtomic (Buffer buffer );
236
153
@@ -276,6 +193,83 @@ extern void FreeAccessStrategy(BufferAccessStrategy strategy);
276
193
277
194
#ifndef FRONTEND
278
195
196
+ /*
197
+ * BufferIsValid
198
+ * True iff the given buffer number is valid (either as a shared
199
+ * or local buffer).
200
+ *
201
+ * Note: For a long time this was defined the same as BufferIsPinned,
202
+ * that is it would say False if you didn't hold a pin on the buffer.
203
+ * I believe this was bogus and served only to mask logic errors.
204
+ * Code should always know whether it has a buffer reference,
205
+ * independently of the pin state.
206
+ *
207
+ * Note: For a further long time this was not quite the inverse of the
208
+ * BufferIsInvalid() macro, in that it also did sanity checks to verify
209
+ * that the buffer number was in range. Most likely, this macro was
210
+ * originally intended only to be used in assertions, but its use has
211
+ * since expanded quite a bit, and the overhead of making those checks
212
+ * even in non-assert-enabled builds can be significant. Thus, we've
213
+ * now demoted the range checks to assertions within the macro itself.
214
+ */
215
+ static inline bool
216
+ BufferIsValid (Buffer bufnum )
217
+ {
218
+ Assert (bufnum <= NBuffers );
219
+ Assert (bufnum >= - NLocBuffer );
220
+
221
+ return bufnum != InvalidBuffer ;
222
+ }
223
+
224
+ /*
225
+ * BufferGetBlock
226
+ * Returns a reference to a disk page image associated with a buffer.
227
+ *
228
+ * Note:
229
+ * Assumes buffer is valid.
230
+ */
231
+ static inline Block
232
+ BufferGetBlock (Buffer buffer )
233
+ {
234
+ Assert (BufferIsValid (buffer ));
235
+
236
+ if (BufferIsLocal (buffer ))
237
+ return LocalBufferBlockPointers [- buffer - 1 ];
238
+ else
239
+ return (Block ) (BufferBlocks + ((Size ) (buffer - 1 )) * BLCKSZ );
240
+ }
241
+
242
+ /*
243
+ * BufferGetPageSize
244
+ * Returns the page size within a buffer.
245
+ *
246
+ * Notes:
247
+ * Assumes buffer is valid.
248
+ *
249
+ * The buffer can be a raw disk block and need not contain a valid
250
+ * (formatted) disk page.
251
+ */
252
+ /* XXX should dig out of buffer descriptor */
253
+ static inline Size
254
+ BufferGetPageSize (Buffer buffer )
255
+ {
256
+ AssertMacro (BufferIsValid (buffer ));
257
+ return (Size ) BLCKSZ ;
258
+ }
259
+
260
+ /*
261
+ * BufferGetPage
262
+ * Returns the page associated with a buffer.
263
+ *
264
+ * When this is called as part of a scan, there may be a need for a nearby
265
+ * call to TestForOldSnapshot(). See the definition of that for details.
266
+ */
267
+ static inline Page
268
+ BufferGetPage (Buffer buffer )
269
+ {
270
+ return (Page ) BufferGetBlock (buffer );
271
+ }
272
+
279
273
/*
280
274
* Check whether the given snapshot is too old to have safely read the given
281
275
* page from the given table. If so, throw a "snapshot too old" error.
0 commit comments