1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +03:00

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.
This commit is contained in:
Tom Lane
2000-11-30 01:39:08 +00:00
parent 9f20852f87
commit 680b7357ce
13 changed files with 125 additions and 74 deletions

View File

@@ -8,17 +8,17 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.38 2000/11/28 23:27:55 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.39 2000/11/30 01:39:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include <sys/types.h>
#include <sys/file.h>
#include <math.h>
#include <signal.h>
#include "postgres.h"
#include "catalog/catalog.h"
#include "executor/execdebug.h"
#include "miscadmin.h"
@@ -54,7 +54,7 @@ int Lookup_List_Descriptor;
int Num_Descriptors;
BufferDesc *BufferDescriptors;
BufferBlock BufferBlocks;
Block *BufferBlockPointers;
long *PrivateRefCount; /* also used in freelist.c */
bits8 *BufferLocks; /* flag bits showing locks I have set */
@@ -126,7 +126,7 @@ long int LocalBufferFlushCount;
/*
* Initialize module:
* Initialize module: called once during shared-memory initialization
*
* should calculate size of pool dynamically based on the
* amount of available memory.
@@ -134,6 +134,7 @@ long int LocalBufferFlushCount;
void
InitBufferPool(void)
{
char *BufferBlocks;
bool foundBufs,
foundDescs;
int i;
@@ -159,24 +160,22 @@ InitBufferPool(void)
ShmemInitStruct("Buffer Descriptors",
Num_Descriptors * sizeof(BufferDesc), &foundDescs);
BufferBlocks = (BufferBlock)
BufferBlocks = (char *)
ShmemInitStruct("Buffer Blocks",
NBuffers * BLCKSZ, &foundBufs);
if (foundDescs || foundBufs)
{
/* both should be present or neither */
Assert(foundDescs && foundBufs);
}
else
{
BufferDesc *buf;
unsigned long block;
char *block;
buf = BufferDescriptors;
block = (unsigned long) BufferBlocks;
block = BufferBlocks;
/*
* link the buffers into a circular, doubly-linked list to
@@ -210,11 +209,21 @@ InitBufferPool(void)
SpinRelease(BufMgrLock);
BufferBlockPointers = (Block *) calloc(NBuffers, sizeof(Block));
PrivateRefCount = (long *) calloc(NBuffers, sizeof(long));
BufferLocks = (bits8 *) calloc(NBuffers, sizeof(bits8));
BufferTagLastDirtied = (BufferTag *) calloc(NBuffers, sizeof(BufferTag));
BufferBlindLastDirtied = (BufferBlindId *) calloc(NBuffers, sizeof(BufferBlindId));
BufferDirtiedByMe = (bool *) calloc(NBuffers, sizeof(bool));
/*
* Convert shmem offsets into addresses as seen by this process.
* This is just to speed up the BufferGetBlock() macro.
*/
for (i = 0; i < NBuffers; i++)
{
BufferBlockPointers[i] = (Block) MAKE_PTR(BufferDescriptors[i].data);
}
}
/* -----------------------------------------------------

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.18 2000/10/18 05:50:15 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.19 2000/11/30 01:39:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -29,6 +29,7 @@
#include "postgres.h"
#include "storage/buf_internals.h"
#include "storage/bufmgr.h"
static HTAB *SharedBufHash;

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.95 2000/11/28 23:27:55 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.96 2000/11/30 01:39:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -56,6 +56,8 @@
#include "executor/execdebug.h"
#include "miscadmin.h"
#include "storage/buf_internals.h"
#include "storage/bufmgr.h"
#include "storage/s_lock.h"
#include "storage/smgr.h"
#include "utils/relcache.h"

View File

@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/freelist.c,v 1.21 2000/04/09 04:43:19 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/freelist.c,v 1.22 2000/11/30 01:39:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -26,6 +26,8 @@
*/
#include "postgres.h"
#include "storage/buf_internals.h"
#include "storage/bufmgr.h"

View File

@@ -16,7 +16,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.35 2000/11/20 16:47:32 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.36 2000/11/30 01:39:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -33,6 +33,8 @@
#include <signal.h>
#include "executor/execdebug.h"
#include "storage/buf_internals.h"
#include "storage/bufmgr.h"
#include "storage/smgr.h"
#include "utils/relcache.h"
@@ -40,6 +42,7 @@ extern long int LocalBufferFlushCount;
int NLocBuffer = 64;
BufferDesc *LocalBufferDescriptors = NULL;
Block *LocalBufferBlockPointers = NULL;
long *LocalRefCount = NULL;
static int nextFreeLocalBuf = 0;
@@ -135,14 +138,24 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
bufHdr->flags &= ~BM_DIRTY;
/*
* lazy memory allocation. (see MAKE_PTR for why we need to do
* MAKE_OFFSET.)
* lazy memory allocation: allocate space on first use of a buffer.
*/
if (bufHdr->data == (SHMEM_OFFSET) 0)
{
char *data = (char *) malloc(BLCKSZ);
if (data == NULL)
elog(FATAL, "Out of memory in LocalBufferAlloc");
/*
* This is a bit of a hack: bufHdr->data needs to be a shmem offset
* for consistency with the shared-buffer case, so make it one
* even though it's not really a valid shmem offset.
*/
bufHdr->data = MAKE_OFFSET(data);
/*
* Set pointer for use by BufferGetBlock() macro.
*/
LocalBufferBlockPointers[-(bufHdr->buf_id + 2)] = (Block) data;
}
*foundPtr = FALSE;
@@ -223,7 +236,7 @@ FlushLocalBuffer(Buffer buffer, bool sync, bool release)
/*
* InitLocalBuffer -
* init the local buffer cache. Since most queries (esp. multi-user ones)
* don't involve local buffers, we delay allocating memory for actual the
* don't involve local buffers, we delay allocating actual memory for the
* buffer until we need it.
*/
void
@@ -235,8 +248,9 @@ InitLocalBuffer(void)
* these aren't going away. I'm not gonna use palloc.
*/
LocalBufferDescriptors =
(BufferDesc *) malloc(sizeof(BufferDesc) * NLocBuffer);
MemSet(LocalBufferDescriptors, 0, sizeof(BufferDesc) * NLocBuffer);
(BufferDesc *) calloc(NLocBuffer, sizeof(BufferDesc));
LocalBufferBlockPointers = (Block *) calloc(NLocBuffer, sizeof(Block));
LocalRefCount = (long *) calloc(NLocBuffer, sizeof(long));
nextFreeLocalBuf = 0;
for (i = 0; i < NLocBuffer; i++)
@@ -251,9 +265,6 @@ InitLocalBuffer(void)
*/
buf->buf_id = -i - 2;
}
LocalRefCount = (long *) malloc(sizeof(long) * NLocBuffer);
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
}
/*
@@ -308,7 +319,6 @@ ResetLocalBufferPool(void)
buf->tag.rnode.relNode = InvalidOid;
buf->flags &= ~BM_DIRTY;
buf->buf_id = -i - 2;
}
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);

View File

@@ -1,6 +1,6 @@
/*-------------------------------------------------------------------------
*
* bufmgr.c
* xlog_bufmgr.c
* buffer manager interface routines
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/xlog_bufmgr.c,v 1.5 2000/11/28 23:27:55 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/xlog_bufmgr.c,v 1.6 2000/11/30 01:39:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -39,14 +39,17 @@
* freelist.c -- chooses victim for buffer replacement
* buf_table.c -- manages the buffer lookup table
*/
#include "postgres.h"
#include <sys/types.h>
#include <sys/file.h>
#include <math.h>
#include <signal.h>
#include "postgres.h"
#include "executor/execdebug.h"
#include "miscadmin.h"
#include "storage/buf_internals.h"
#include "storage/bufmgr.h"
#include "storage/s_lock.h"
#include "storage/smgr.h"
#include "utils/relcache.h"

View File

@@ -1,6 +1,6 @@
/*-------------------------------------------------------------------------
*
* localbuf.c
* xlog_localbuf.c
* local buffer manager. Fast buffer manager for temporary tables
* or special cases when the operation is not visible to other backends.
*
@@ -16,18 +16,20 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/xlog_localbuf.c,v 1.1 2000/10/28 16:20:56 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/xlog_localbuf.c,v 1.2 2000/11/30 01:39:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include <sys/types.h>
#include <sys/file.h>
#include <math.h>
#include <signal.h>
#include "postgres.h"
#include "executor/execdebug.h"
#include "storage/buf_internals.h"
#include "storage/bufmgr.h"
#include "storage/smgr.h"
#include "utils/relcache.h"
@@ -35,6 +37,7 @@ extern long int LocalBufferFlushCount;
int NLocBuffer = 64;
BufferDesc *LocalBufferDescriptors = NULL;
Block *LocalBufferBlockPointers = NULL;
long *LocalRefCount = NULL;
static int nextFreeLocalBuf = 0;
@@ -131,14 +134,24 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
bufHdr->cntxDirty = false;
/*
* lazy memory allocation. (see MAKE_PTR for why we need to do
* MAKE_OFFSET.)
* lazy memory allocation: allocate space on first use of a buffer.
*/
if (bufHdr->data == (SHMEM_OFFSET) 0)
{
char *data = (char *) malloc(BLCKSZ);
if (data == NULL)
elog(FATAL, "Out of memory in LocalBufferAlloc");
/*
* This is a bit of a hack: bufHdr->data needs to be a shmem offset
* for consistency with the shared-buffer case, so make it one
* even though it's not really a valid shmem offset.
*/
bufHdr->data = MAKE_OFFSET(data);
/*
* Set pointer for use by BufferGetBlock() macro.
*/
LocalBufferBlockPointers[-(bufHdr->buf_id + 2)] = (Block) data;
}
*foundPtr = FALSE;
@@ -175,7 +188,7 @@ WriteLocalBuffer(Buffer buffer, bool release)
/*
* InitLocalBuffer -
* init the local buffer cache. Since most queries (esp. multi-user ones)
* don't involve local buffers, we delay allocating memory for actual the
* don't involve local buffers, we delay allocating actual memory for the
* buffer until we need it.
*/
void
@@ -187,8 +200,9 @@ InitLocalBuffer(void)
* these aren't going away. I'm not gonna use palloc.
*/
LocalBufferDescriptors =
(BufferDesc *) malloc(sizeof(BufferDesc) * NLocBuffer);
MemSet(LocalBufferDescriptors, 0, sizeof(BufferDesc) * NLocBuffer);
(BufferDesc *) calloc(NLocBuffer, sizeof(BufferDesc));
LocalBufferBlockPointers = (Block *) calloc(NLocBuffer, sizeof(Block));
LocalRefCount = (long *) calloc(NLocBuffer, sizeof(long));
nextFreeLocalBuf = 0;
for (i = 0; i < NLocBuffer; i++)
@@ -203,9 +217,6 @@ InitLocalBuffer(void)
*/
buf->buf_id = -i - 2;
}
LocalRefCount = (long *) malloc(sizeof(long) * NLocBuffer);
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
}
/*
@@ -238,7 +249,7 @@ LocalBufferSync(void)
Assert(bufrel != NULL);
smgrwrite(DEFAULT_SMGR, bufrel, buf->tag.blockNum,
(char *) MAKE_PTR(buf->data));
(char *) MAKE_PTR(buf->data));
smgrmarkdirty(DEFAULT_SMGR, bufrel, buf->tag.blockNum);
LocalBufferFlushCount++;
@@ -266,7 +277,6 @@ ResetLocalBufferPool(void)
buf->tag.rnode.relNode = InvalidOid;
buf->flags &= ~BM_DIRTY;
buf->cntxDirty = false;
buf->buf_id = -i - 2;
}
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);