Skip to content

Commit 680b735

Browse files
committed
Rearrange bufmgr header files so that buf_internals.h need not be
included by everything that includes bufmgr.h --- it's supposed to be internals, after all, not part of the API! This fixes the conflict against FreeBSD headers reported by Rosenman, by making it unnecessary for s_lock.h to be included by plperl.c.
1 parent 9f20852 commit 680b735

File tree

13 files changed

+125
-74
lines changed

13 files changed

+125
-74
lines changed

src/backend/access/hash/hashpage.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashpage.c,v 1.27 2000/03/17 02:36:02 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashpage.c,v 1.28 2000/11/30 01:39:06 tgl Exp $
1212
*
1313
* NOTES
1414
* Postgres hash pages look like ordinary relation pages. The opaque
@@ -29,6 +29,7 @@
2929
#include "access/genam.h"
3030
#include "access/hash.h"
3131
#include "miscadmin.h"
32+
#include "storage/lmgr.h"
3233

3334

3435
static void _hash_setpagelock(Relation rel, BlockNumber blkno, int access);

src/backend/access/nbtree/nbtpage.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.40 2000/10/21 15:43:18 vadim Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.41 2000/11/30 01:39:06 tgl Exp $
1313
*
1414
* NOTES
1515
* Postgres btree pages look like ordinary relation pages. The opaque
@@ -20,12 +20,14 @@
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
23-
#include <time.h>
24-
2523
#include "postgres.h"
2624

25+
#include <time.h>
26+
2727
#include "access/nbtree.h"
2828
#include "miscadmin.h"
29+
#include "storage/lmgr.h"
30+
2931

3032
/*
3133
* We use high-concurrency locking on btrees. There are two cases in

src/backend/storage/buffer/buf_init.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.38 2000/11/28 23:27:55 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.39 2000/11/30 01:39:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
15+
#include "postgres.h"
16+
1517
#include <sys/types.h>
1618
#include <sys/file.h>
1719
#include <math.h>
1820
#include <signal.h>
1921

20-
#include "postgres.h"
21-
2222
#include "catalog/catalog.h"
2323
#include "executor/execdebug.h"
2424
#include "miscadmin.h"
@@ -54,7 +54,7 @@ int Lookup_List_Descriptor;
5454
int Num_Descriptors;
5555

5656
BufferDesc *BufferDescriptors;
57-
BufferBlock BufferBlocks;
57+
Block *BufferBlockPointers;
5858

5959
long *PrivateRefCount; /* also used in freelist.c */
6060
bits8 *BufferLocks; /* flag bits showing locks I have set */
@@ -126,14 +126,15 @@ long int LocalBufferFlushCount;
126126

127127

128128
/*
129-
* Initialize module:
129+
* Initialize module: called once during shared-memory initialization
130130
*
131131
* should calculate size of pool dynamically based on the
132132
* amount of available memory.
133133
*/
134134
void
135135
InitBufferPool(void)
136136
{
137+
char *BufferBlocks;
137138
bool foundBufs,
138139
foundDescs;
139140
int i;
@@ -159,24 +160,22 @@ InitBufferPool(void)
159160
ShmemInitStruct("Buffer Descriptors",
160161
Num_Descriptors * sizeof(BufferDesc), &foundDescs);
161162

162-
BufferBlocks = (BufferBlock)
163+
BufferBlocks = (char *)
163164
ShmemInitStruct("Buffer Blocks",
164165
NBuffers * BLCKSZ, &foundBufs);
165166

166167
if (foundDescs || foundBufs)
167168
{
168-
169169
/* both should be present or neither */
170170
Assert(foundDescs && foundBufs);
171-
172171
}
173172
else
174173
{
175174
BufferDesc *buf;
176-
unsigned long block;
175+
char *block;
177176

178177
buf = BufferDescriptors;
179-
block = (unsigned long) BufferBlocks;
178+
block = BufferBlocks;
180179

181180
/*
182181
* link the buffers into a circular, doubly-linked list to
@@ -210,11 +209,21 @@ InitBufferPool(void)
210209

211210
SpinRelease(BufMgrLock);
212211

212+
BufferBlockPointers = (Block *) calloc(NBuffers, sizeof(Block));
213213
PrivateRefCount = (long *) calloc(NBuffers, sizeof(long));
214214
BufferLocks = (bits8 *) calloc(NBuffers, sizeof(bits8));
215215
BufferTagLastDirtied = (BufferTag *) calloc(NBuffers, sizeof(BufferTag));
216216
BufferBlindLastDirtied = (BufferBlindId *) calloc(NBuffers, sizeof(BufferBlindId));
217217
BufferDirtiedByMe = (bool *) calloc(NBuffers, sizeof(bool));
218+
219+
/*
220+
* Convert shmem offsets into addresses as seen by this process.
221+
* This is just to speed up the BufferGetBlock() macro.
222+
*/
223+
for (i = 0; i < NBuffers; i++)
224+
{
225+
BufferBlockPointers[i] = (Block) MAKE_PTR(BufferDescriptors[i].data);
226+
}
218227
}
219228

220229
/* -----------------------------------------------------

src/backend/storage/buffer/buf_table.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.18 2000/10/18 05:50:15 vadim Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.19 2000/11/30 01:39:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -29,6 +29,7 @@
2929

3030
#include "postgres.h"
3131

32+
#include "storage/buf_internals.h"
3233
#include "storage/bufmgr.h"
3334

3435
static HTAB *SharedBufHash;

src/backend/storage/buffer/bufmgr.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.95 2000/11/28 23:27:55 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.96 2000/11/30 01:39:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -56,6 +56,8 @@
5656

5757
#include "executor/execdebug.h"
5858
#include "miscadmin.h"
59+
#include "storage/buf_internals.h"
60+
#include "storage/bufmgr.h"
5961
#include "storage/s_lock.h"
6062
#include "storage/smgr.h"
6163
#include "utils/relcache.h"

src/backend/storage/buffer/freelist.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/freelist.c,v 1.21 2000/04/09 04:43:19 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/freelist.c,v 1.22 2000/11/30 01:39:07 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -26,6 +26,8 @@
2626
*/
2727

2828
#include "postgres.h"
29+
30+
#include "storage/buf_internals.h"
2931
#include "storage/bufmgr.h"
3032

3133

src/backend/storage/buffer/localbuf.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.35 2000/11/20 16:47:32 petere Exp $
19+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.36 2000/11/30 01:39:07 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -33,13 +33,16 @@
3333
#include <signal.h>
3434

3535
#include "executor/execdebug.h"
36+
#include "storage/buf_internals.h"
37+
#include "storage/bufmgr.h"
3638
#include "storage/smgr.h"
3739
#include "utils/relcache.h"
3840

3941
extern long int LocalBufferFlushCount;
4042

4143
int NLocBuffer = 64;
4244
BufferDesc *LocalBufferDescriptors = NULL;
45+
Block *LocalBufferBlockPointers = NULL;
4346
long *LocalRefCount = NULL;
4447

4548
static int nextFreeLocalBuf = 0;
@@ -135,14 +138,24 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
135138
bufHdr->flags &= ~BM_DIRTY;
136139

137140
/*
138-
* lazy memory allocation. (see MAKE_PTR for why we need to do
139-
* MAKE_OFFSET.)
141+
* lazy memory allocation: allocate space on first use of a buffer.
140142
*/
141143
if (bufHdr->data == (SHMEM_OFFSET) 0)
142144
{
143145
char *data = (char *) malloc(BLCKSZ);
144146

147+
if (data == NULL)
148+
elog(FATAL, "Out of memory in LocalBufferAlloc");
149+
/*
150+
* This is a bit of a hack: bufHdr->data needs to be a shmem offset
151+
* for consistency with the shared-buffer case, so make it one
152+
* even though it's not really a valid shmem offset.
153+
*/
145154
bufHdr->data = MAKE_OFFSET(data);
155+
/*
156+
* Set pointer for use by BufferGetBlock() macro.
157+
*/
158+
LocalBufferBlockPointers[-(bufHdr->buf_id + 2)] = (Block) data;
146159
}
147160

148161
*foundPtr = FALSE;
@@ -223,7 +236,7 @@ FlushLocalBuffer(Buffer buffer, bool sync, bool release)
223236
/*
224237
* InitLocalBuffer -
225238
* init the local buffer cache. Since most queries (esp. multi-user ones)
226-
* don't involve local buffers, we delay allocating memory for actual the
239+
* don't involve local buffers, we delay allocating actual memory for the
227240
* buffer until we need it.
228241
*/
229242
void
@@ -235,8 +248,9 @@ InitLocalBuffer(void)
235248
* these aren't going away. I'm not gonna use palloc.
236249
*/
237250
LocalBufferDescriptors =
238-
(BufferDesc *) malloc(sizeof(BufferDesc) * NLocBuffer);
239-
MemSet(LocalBufferDescriptors, 0, sizeof(BufferDesc) * NLocBuffer);
251+
(BufferDesc *) calloc(NLocBuffer, sizeof(BufferDesc));
252+
LocalBufferBlockPointers = (Block *) calloc(NLocBuffer, sizeof(Block));
253+
LocalRefCount = (long *) calloc(NLocBuffer, sizeof(long));
240254
nextFreeLocalBuf = 0;
241255

242256
for (i = 0; i < NLocBuffer; i++)
@@ -251,9 +265,6 @@ InitLocalBuffer(void)
251265
*/
252266
buf->buf_id = -i - 2;
253267
}
254-
255-
LocalRefCount = (long *) malloc(sizeof(long) * NLocBuffer);
256-
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
257268
}
258269

259270
/*
@@ -308,7 +319,6 @@ ResetLocalBufferPool(void)
308319

309320
buf->tag.rnode.relNode = InvalidOid;
310321
buf->flags &= ~BM_DIRTY;
311-
buf->buf_id = -i - 2;
312322
}
313323

314324
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);

src/backend/storage/buffer/xlog_bufmgr.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*-------------------------------------------------------------------------
22
*
3-
* bufmgr.c
3+
* xlog_bufmgr.c
44
* buffer manager interface routines
55
*
66
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/xlog_bufmgr.c,v 1.5 2000/11/28 23:27:55 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/xlog_bufmgr.c,v 1.6 2000/11/30 01:39:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -39,14 +39,17 @@
3939
* freelist.c -- chooses victim for buffer replacement
4040
* buf_table.c -- manages the buffer lookup table
4141
*/
42+
#include "postgres.h"
43+
4244
#include <sys/types.h>
4345
#include <sys/file.h>
4446
#include <math.h>
4547
#include <signal.h>
4648

47-
#include "postgres.h"
4849
#include "executor/execdebug.h"
4950
#include "miscadmin.h"
51+
#include "storage/buf_internals.h"
52+
#include "storage/bufmgr.h"
5053
#include "storage/s_lock.h"
5154
#include "storage/smgr.h"
5255
#include "utils/relcache.h"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy