From 680b7357ce850c28d06997be793aee18f72434ba Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu, 30 Nov 2000 01:39:08 +0000
Subject: [PATCH] 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.

---
 src/backend/access/hash/hashpage.c         |  3 +-
 src/backend/access/nbtree/nbtpage.c        |  8 ++--
 src/backend/storage/buffer/buf_init.c      | 29 ++++++++++-----
 src/backend/storage/buffer/buf_table.c     |  3 +-
 src/backend/storage/buffer/bufmgr.c        |  4 +-
 src/backend/storage/buffer/freelist.c      |  4 +-
 src/backend/storage/buffer/localbuf.c      | 30 ++++++++++-----
 src/backend/storage/buffer/xlog_bufmgr.c   |  9 +++--
 src/backend/storage/buffer/xlog_localbuf.c | 38 ++++++++++++-------
 src/backend/storage/ipc/ipci.c             |  3 +-
 src/backend/storage/lmgr/lmgr.c            |  3 +-
 src/include/storage/buf_internals.h        | 22 ++++-------
 src/include/storage/bufmgr.h               | 43 +++++++++++++++-------
 13 files changed, 125 insertions(+), 74 deletions(-)

diff --git a/src/backend/access/hash/hashpage.c b/src/backend/access/hash/hashpage.c
index cec40d5187a..370439f1115 100644
--- a/src/backend/access/hash/hashpage.c
+++ b/src/backend/access/hash/hashpage.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/access/hash/hashpage.c,v 1.27 2000/03/17 02:36:02 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/access/hash/hashpage.c,v 1.28 2000/11/30 01:39:06 tgl Exp $
  *
  * NOTES
  *	  Postgres hash pages look like ordinary relation pages.  The opaque
@@ -29,6 +29,7 @@
 #include "access/genam.h"
 #include "access/hash.h"
 #include "miscadmin.h"
+#include "storage/lmgr.h"
 
 
 static void _hash_setpagelock(Relation rel, BlockNumber blkno, int access);
diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index 3cf0e688856..dd7882a9dae 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.40 2000/10/21 15:43:18 vadim Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.41 2000/11/30 01:39:06 tgl Exp $
  *
  *	NOTES
  *	   Postgres btree pages look like ordinary relation pages.	The opaque
@@ -20,12 +20,14 @@
  *
  *-------------------------------------------------------------------------
  */
-#include <time.h>
-
 #include "postgres.h"
 
+#include <time.h>
+
 #include "access/nbtree.h"
 #include "miscadmin.h"
+#include "storage/lmgr.h"
+
 
 /*
  *	We use high-concurrency locking on btrees.	There are two cases in
diff --git a/src/backend/storage/buffer/buf_init.c b/src/backend/storage/buffer/buf_init.c
index 0fda21972f6..19b71933d76 100644
--- a/src/backend/storage/buffer/buf_init.c
+++ b/src/backend/storage/buffer/buf_init.c
@@ -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);
+	}
 }
 
 /* -----------------------------------------------------
diff --git a/src/backend/storage/buffer/buf_table.c b/src/backend/storage/buffer/buf_table.c
index d48d321e8f8..cd4d61224b0 100644
--- a/src/backend/storage/buffer/buf_table.c
+++ b/src/backend/storage/buffer/buf_table.c
@@ -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;
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 8ed03138fac..a25d4d9a55b 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -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"
diff --git a/src/backend/storage/buffer/freelist.c b/src/backend/storage/buffer/freelist.c
index a77a16c2a0a..c310a37951d 100644
--- a/src/backend/storage/buffer/freelist.c
+++ b/src/backend/storage/buffer/freelist.c
@@ -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"
 
 
diff --git a/src/backend/storage/buffer/localbuf.c b/src/backend/storage/buffer/localbuf.c
index 7a841a354ad..828523c0b30 100644
--- a/src/backend/storage/buffer/localbuf.c
+++ b/src/backend/storage/buffer/localbuf.c
@@ -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);
diff --git a/src/backend/storage/buffer/xlog_bufmgr.c b/src/backend/storage/buffer/xlog_bufmgr.c
index 9672510547a..fb02413f970 100644
--- a/src/backend/storage/buffer/xlog_bufmgr.c
+++ b/src/backend/storage/buffer/xlog_bufmgr.c
@@ -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"
diff --git a/src/backend/storage/buffer/xlog_localbuf.c b/src/backend/storage/buffer/xlog_localbuf.c
index cb14a32ed23..dda7456e72c 100644
--- a/src/backend/storage/buffer/xlog_localbuf.c
+++ b/src/backend/storage/buffer/xlog_localbuf.c
@@ -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);
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c
index 7a5813df57d..a813a530bfe 100644
--- a/src/backend/storage/ipc/ipci.c
+++ b/src/backend/storage/ipc/ipci.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.35 2000/11/28 23:27:56 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.36 2000/11/30 01:39:07 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -19,6 +19,7 @@
 #include "miscadmin.h"
 #include "access/xlog.h"
 #include "storage/bufmgr.h"
+#include "storage/lmgr.h"
 #include "storage/proc.h"
 #include "storage/sinval.h"
 #include "storage/spin.h"
diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c
index f1b9f874666..d6ebbc35b53 100644
--- a/src/backend/storage/lmgr/lmgr.c
+++ b/src/backend/storage/lmgr/lmgr.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.41 2000/06/08 22:37:24 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.42 2000/11/30 01:39:08 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -18,6 +18,7 @@
 #include "access/transam.h"
 #include "catalog/catalog.h"
 #include "miscadmin.h"
+#include "storage/lmgr.h"
 #include "utils/inval.h"
 
 
diff --git a/src/include/storage/buf_internals.h b/src/include/storage/buf_internals.h
index ae417118878..41fce0780f0 100644
--- a/src/include/storage/buf_internals.h
+++ b/src/include/storage/buf_internals.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: buf_internals.h,v 1.44 2000/11/28 23:27:57 tgl Exp $
+ * $Id: buf_internals.h,v 1.45 2000/11/30 01:39:08 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -18,14 +18,17 @@
 #include "storage/lmgr.h"
 #include "storage/s_lock.h"
 
+
 /* Buf Mgr constants */
 /* in bufmgr.c */
-extern int	NBuffers;
 extern int	Data_Descriptors;
 extern int	Free_List_Descriptor;
 extern int	Lookup_List_Descriptor;
 extern int	Num_Descriptors;
 
+extern int	ShowPinTrace;
+
+
 /*
  * Flags for buffer descriptors
  */
@@ -40,9 +43,6 @@ extern int	Num_Descriptors;
 
 typedef bits16 BufFlags;
 
-/* long * so alignment will be correct */
-typedef long **BufferBlock;
-
 typedef struct buftag
 {
 	RelFileNode	rnode;
@@ -63,7 +63,7 @@ typedef struct buftag
 )
 
 /*
- * We don't need in this data any more but it allows more user
+ * We don't need this data any more but it allows more user
  * friendly error messages. Feel free to get rid of it
  * (and change a lot of places -:))
  */
@@ -73,9 +73,6 @@ typedef struct bufblindid
 	char		relname[NAMEDATALEN];	/* name of reln */
 }			BufferBlindId;
 
-#define BAD_BUFFER_ID(bid) ((bid) < 1 || (bid) > NBuffers)
-#define INVALID_DESCRIPTOR (-3)
-
 /*
  *	BufferDesc -- shared buffer cache metadata for a single
  *				  shared buffer descriptor.
@@ -123,6 +120,8 @@ typedef struct sbufdesc
 	void		(*CleanupFunc)(Buffer);
 } BufferDesc;
 
+#define BufferDescriptorGetBuffer(bdesc) ((bdesc)->buf_id + 1)
+
 /*
  * Each backend has its own BufferLocks[] array holding flag bits
  * showing what locks it has set on each buffer.
@@ -182,8 +181,6 @@ extern bool BufTableInsert(BufferDesc *buf);
 
 /* bufmgr.c */
 extern BufferDesc *BufferDescriptors;
-extern BufferBlock BufferBlocks;
-extern long *PrivateRefCount;
 extern bits8 *BufferLocks;
 extern BufferTag *BufferTagLastDirtied;
 extern BufferBlindId *BufferBlindLastDirtied;
@@ -192,15 +189,12 @@ extern bool *BufferDirtiedByMe;
 extern SPINLOCK BufMgrLock;
 
 /* localbuf.c */
-extern long *LocalRefCount;
 extern BufferDesc *LocalBufferDescriptors;
-extern int	NLocBuffer;
 
 extern BufferDesc *LocalBufferAlloc(Relation reln, BlockNumber blockNum,
 				 bool *foundPtr);
 extern int	WriteLocalBuffer(Buffer buffer, bool release);
 extern int	FlushLocalBuffer(Buffer buffer, bool sync, bool release);
-extern void InitLocalBuffer(void);
 extern void LocalBufferSync(void);
 extern void ResetLocalBufferPool(void);
 
diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h
index 275146eea80..2452ac64967 100644
--- a/src/include/storage/bufmgr.h
+++ b/src/include/storage/bufmgr.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: bufmgr.h,v 1.44 2000/11/28 23:27:57 tgl Exp $
+ * $Id: bufmgr.h,v 1.45 2000/11/30 01:39:08 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -15,14 +15,35 @@
 #define BUFMGR_H
 
 #include "access/xlogdefs.h"
-#include "storage/buf_internals.h"
+#include "storage/buf.h"
+#include "storage/lock.h"
 #include "storage/relfilenode.h"
+#include "utils/rel.h"
 
 typedef void *Block;
 
+/* in globals.c ... this duplicates miscadmin.h */
+extern int	NBuffers;
+
+/* in buf_init.c */
+extern Block *BufferBlockPointers;
+extern long *PrivateRefCount;
+
+/* in localbuf.c */
+extern int	NLocBuffer;
+extern Block *LocalBufferBlockPointers;
+extern long *LocalRefCount;
+
 /* special pageno for bget */
 #define P_NEW	InvalidBlockNumber		/* grow the file to get a new page */
 
+/*
+ * Buffer context lock modes
+ */
+#define BUFFER_LOCK_UNLOCK		0
+#define BUFFER_LOCK_SHARE		1
+#define BUFFER_LOCK_EXCLUSIVE	2
+
 
 /**********************************************************************
 
@@ -32,18 +53,10 @@ typedef void *Block;
 
 /*
  * These routines are beaten on quite heavily, hence the macroization.
- * See buf_internals.h for a related comment.
  */
-#define BufferDescriptorGetBuffer(bdesc) ((bdesc)->buf_id + 1)
 
-extern int	ShowPinTrace;
-
-/*
- * Buffer context lock modes
- */
-#define BUFFER_LOCK_UNLOCK		0
-#define BUFFER_LOCK_SHARE		1
-#define BUFFER_LOCK_EXCLUSIVE	2
+#define BAD_BUFFER_ID(bid) ((bid) < 1 || (bid) > NBuffers)
+#define INVALID_DESCRIPTOR (-3)
 
 #define UnlockAndReleaseBuffer(buffer)	\
 ( \
@@ -136,9 +149,9 @@ extern int	ShowPinTrace;
 ( \
 	AssertMacro(BufferIsValid(buffer)), \
 	BufferIsLocal(buffer) ? \
-		((Block) MAKE_PTR(LocalBufferDescriptors[-(buffer) - 1].data)) \
+		LocalBufferBlockPointers[-(buffer) - 1] \
 	: \
-		((Block) MAKE_PTR(BufferDescriptors[(buffer) - 1].data)) \
+		BufferBlockPointers[(buffer) - 1] \
 )
 
 
@@ -184,4 +197,6 @@ extern void BufmgrCommit(void);
 extern void BufferSync(void);
 #endif
 
+extern void InitLocalBuffer(void);
+
 #endif
-- 
GitLab