diff options
author | Bruce Momjian <bruce@momjian.us> | 1997-09-07 05:04:48 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 1997-09-07 05:04:48 +0000 |
commit | 1ccd423235a48739d6f7a4d7889705b5f9ecc69b (patch) | |
tree | 8001c4e839dfad8f29ceda7f8c5f5dbb8759b564 /src/include/storage | |
parent | 8fecd4febf8357f3cc20383ed29ced484877d5ac (diff) | |
download | postgresql-1ccd423235a48739d6f7a4d7889705b5f9ecc69b.tar.gz postgresql-1ccd423235a48739d6f7a4d7889705b5f9ecc69b.zip |
Massive commit to run PGINDENT on all *.c and *.h files.
Diffstat (limited to 'src/include/storage')
26 files changed, 1114 insertions, 1041 deletions
diff --git a/src/include/storage/backendid.h b/src/include/storage/backendid.h index c631d9c38ce..5abdd770e8c 100644 --- a/src/include/storage/backendid.h +++ b/src/include/storage/backendid.h @@ -1,31 +1,32 @@ /*------------------------------------------------------------------------- * * backendid.h-- - * POSTGRES backend id communication definitions + * POSTGRES backend id communication definitions * * * Copyright (c) 1994, Regents of the University of California * - * $Id: backendid.h,v 1.2 1996/11/05 06:10:52 scrappy Exp $ + * $Id: backendid.h,v 1.3 1997/09/07 05:00:40 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef BACKENDID_H +#ifndef BACKENDID_H #define BACKENDID_H /* ---------------- - * -cim 8/17/90 + * -cim 8/17/90 * ---------------- */ -typedef int16 BackendId; /* unique currently active backend identifier */ +typedef int16 BackendId; /* unique currently active backend + * identifier */ -#define InvalidBackendId (-1) +#define InvalidBackendId (-1) -typedef int32 BackendTag; /* unique backend identifier */ +typedef int32 BackendTag; /* unique backend identifier */ -#define InvalidBackendTag (-1) +#define InvalidBackendTag (-1) -extern BackendId MyBackendId; /* backend id of this backend */ -extern BackendTag MyBackendTag; /* backend tag of this backend */ +extern BackendId MyBackendId; /* backend id of this backend */ +extern BackendTag MyBackendTag; /* backend tag of this backend */ -#endif /* BACKENDID_H */ +#endif /* BACKENDID_H */ diff --git a/src/include/storage/block.h b/src/include/storage/block.h index 993d7f8257e..9702b53e2eb 100644 --- a/src/include/storage/block.h +++ b/src/include/storage/block.h @@ -1,16 +1,16 @@ /*------------------------------------------------------------------------- * * block.h-- - * POSTGRES disk block definitions. + * POSTGRES disk block definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: block.h,v 1.2 1996/10/31 09:49:40 scrappy Exp $ + * $Id: block.h,v 1.3 1997/09/07 05:00:42 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef BLOCK_H +#ifndef BLOCK_H #define BLOCK_H /* @@ -29,12 +29,12 @@ */ typedef uint32 BlockNumber; -#define InvalidBlockNumber ((BlockNumber) 0xFFFFFFFF) +#define InvalidBlockNumber ((BlockNumber) 0xFFFFFFFF) /* * BlockId: * - * this is a storage type for BlockNumber. in other words, this type + * this is a storage type for BlockNumber. in other words, this type * is used for on-disk structures (e.g., in HeapTupleData) whereas * BlockNumber is the type on which calculations are performed (e.g., * in access method code). @@ -47,66 +47,67 @@ typedef uint32 BlockNumber; * page and the header of each heap or index tuple, so it doesn't seem * wise to change this without good reason. */ -typedef struct BlockIdData { - uint16 bi_hi; - uint16 bi_lo; -} BlockIdData; +typedef struct BlockIdData +{ + uint16 bi_hi; + uint16 bi_lo; +} BlockIdData; -typedef BlockIdData *BlockId; /* block identifier */ +typedef BlockIdData *BlockId; /* block identifier */ /* ---------------- - * support macros + * support macros * ---------------- */ /* * BlockNumberIsValid -- - * True iff blockNumber is valid. + * True iff blockNumber is valid. */ #define BlockNumberIsValid(blockNumber) \ - ((bool) ((int32) (blockNumber) != InvalidBlockNumber)) + ((bool) ((int32) (blockNumber) != InvalidBlockNumber)) /* * BlockIdIsValid -- - * True iff the block identifier is valid. + * True iff the block identifier is valid. */ #define BlockIdIsValid(blockId) \ - ((bool) PointerIsValid(blockId)) + ((bool) PointerIsValid(blockId)) /* * BlockIdSet -- - * Sets a block identifier to the specified value. + * Sets a block identifier to the specified value. */ #define BlockIdSet(blockId, blockNumber) \ - Assert(PointerIsValid(blockId)); \ - (blockId)->bi_hi = (blockNumber) >> 16; \ - (blockId)->bi_lo = (blockNumber) & 0xffff + Assert(PointerIsValid(blockId)); \ + (blockId)->bi_hi = (blockNumber) >> 16; \ + (blockId)->bi_lo = (blockNumber) & 0xffff /* * BlockIdCopy -- - * Copy a block identifier. + * Copy a block identifier. */ #define BlockIdCopy(toBlockId, fromBlockId) \ - Assert(PointerIsValid(toBlockId)); \ - Assert(PointerIsValid(fromBlockId)); \ - (toBlockId)->bi_hi = (fromBlockId)->bi_hi; \ - (toBlockId)->bi_lo = (fromBlockId)->bi_lo + Assert(PointerIsValid(toBlockId)); \ + Assert(PointerIsValid(fromBlockId)); \ + (toBlockId)->bi_hi = (fromBlockId)->bi_hi; \ + (toBlockId)->bi_lo = (fromBlockId)->bi_lo /* * BlockIdEquals -- - * Check for block number equality. + * Check for block number equality. */ #define BlockIdEquals(blockId1, blockId2) \ - ((blockId1)->bi_hi == (blockId2)->bi_hi && \ - (blockId1)->bi_lo == (blockId2)->bi_lo) + ((blockId1)->bi_hi == (blockId2)->bi_hi && \ + (blockId1)->bi_lo == (blockId2)->bi_lo) /* * BlockIdGetBlockNumber -- - * Retrieve the block number from a block identifier. + * Retrieve the block number from a block identifier. */ #define BlockIdGetBlockNumber(blockId) \ - (AssertMacro(BlockIdIsValid(blockId)) ? \ - (BlockNumber) (((blockId)->bi_hi << 16) | ((uint16) (blockId)->bi_lo)) : \ - (BlockNumber) InvalidBlockNumber) + (AssertMacro(BlockIdIsValid(blockId)) ? \ + (BlockNumber) (((blockId)->bi_hi << 16) | ((uint16) (blockId)->bi_lo)) : \ + (BlockNumber) InvalidBlockNumber) -#endif /* BLOCK_H */ +#endif /* BLOCK_H */ diff --git a/src/include/storage/buf.h b/src/include/storage/buf.h index 439cb58ec9b..481033c4a73 100644 --- a/src/include/storage/buf.h +++ b/src/include/storage/buf.h @@ -1,16 +1,16 @@ /*------------------------------------------------------------------------- * * buf.h-- - * Basic buffer manager data types. + * Basic buffer manager data types. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: buf.h,v 1.1 1996/08/28 01:57:57 scrappy Exp $ + * $Id: buf.h,v 1.2 1997/09/07 05:00:45 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef BUF_H +#ifndef BUF_H #define BUF_H #define InvalidBuffer (0) @@ -20,28 +20,28 @@ typedef long Buffer; /* * BufferIsInvalid -- - * True iff the buffer is invalid. + * True iff the buffer is invalid. */ -#define BufferIsInvalid(buffer) ((buffer) == InvalidBuffer) +#define BufferIsInvalid(buffer) ((buffer) == InvalidBuffer) /* * BufferIsUnknown -- - * True iff the buffer is unknown. + * True iff the buffer is unknown. */ -#define BufferIsUnknown(buffer) ((buffer) == UnknownBuffer) +#define BufferIsUnknown(buffer) ((buffer) == UnknownBuffer) /* * BufferIsLocal -- - * True iff the buffer is local (not visible to other servers). + * True iff the buffer is local (not visible to other servers). */ #define BufferIsLocal(buffer) ((buffer) < 0) /* * If NO_BUFFERISVALID is defined, all error checking using BufferIsValid() - * are suppressed. Decision-making using BufferIsValid is not affected. + * are suppressed. Decision-making using BufferIsValid is not affected. * This should be set only if one is sure there will be no errors. * - plai 9/10/90 */ #undef NO_BUFFERISVALID -#endif /* BUF_H */ +#endif /* BUF_H */ diff --git a/src/include/storage/buf_internals.h b/src/include/storage/buf_internals.h index 24d22bd9c9a..aea48e15cb1 100644 --- a/src/include/storage/buf_internals.h +++ b/src/include/storage/buf_internals.h @@ -1,20 +1,20 @@ /*------------------------------------------------------------------------- * * buf_internals.h-- - * Internal definitions. + * Internal definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: buf_internals.h,v 1.14 1997/08/19 21:39:41 momjian Exp $ + * $Id: buf_internals.h,v 1.15 1997/09/07 05:00:52 momjian Exp $ * * NOTE - * If BUFFERPAGE0 is defined, then 0 will be used as a - * valid buffer page number. + * If BUFFERPAGE0 is defined, then 0 will be used as a + * valid buffer page number. * *------------------------------------------------------------------------- */ -#ifndef BUFMGR_INTERNALS_H +#ifndef BUFMGR_INTERNALS_H #define BUFMGR_INTERNALS_H #include <storage/lmgr.h> @@ -22,35 +22,37 @@ /* 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 NBuffers; +extern int Data_Descriptors; +extern int Free_List_Descriptor; +extern int Lookup_List_Descriptor; +extern int Num_Descriptors; /* * Flags for buffer descriptors */ -#define BM_DIRTY (1 << 0) -#define BM_PRIVATE (1 << 1) -#define BM_VALID (1 << 2) -#define BM_DELETED (1 << 3) -#define BM_FREE (1 << 4) -#define BM_IO_IN_PROGRESS (1 << 5) -#define BM_IO_ERROR (1 << 6) -#define BM_JUST_DIRTIED (1 << 7) +#define BM_DIRTY (1 << 0) +#define BM_PRIVATE (1 << 1) +#define BM_VALID (1 << 2) +#define BM_DELETED (1 << 3) +#define BM_FREE (1 << 4) +#define BM_IO_IN_PROGRESS (1 << 5) +#define BM_IO_ERROR (1 << 6) +#define BM_JUST_DIRTIED (1 << 7) -typedef bits16 BufFlags; +typedef bits16 BufFlags; typedef struct sbufdesc BufferDesc; typedef struct sbufdesc BufferHdr; typedef struct buftag BufferTag; + /* long * so alignment will be correct */ -typedef long **BufferBlock; +typedef long **BufferBlock; -struct buftag{ - LRelId relId; - BlockNumber blockNum; /* blknum relative to begin of reln */ +struct buftag +{ + LRelId relId; + BlockNumber blockNum; /* blknum relative to begin of reln */ }; #define CLEAR_BUFFERTAG(a)\ @@ -79,154 +81,162 @@ struct buftag{ #define INVALID_DESCRIPTOR (-3) /* - * bletch hack -- anyplace that we declare space for relation or - * database names, we just use '16', not a symbolic constant, to - * specify their lengths. BM_NAMESIZE is the length of these names, - * and is used in the buffer manager code. somebody with lots of - * spare time should do this for all the other modules, too. + * bletch hack -- anyplace that we declare space for relation or + * database names, we just use '16', not a symbolic constant, to + * specify their lengths. BM_NAMESIZE is the length of these names, + * and is used in the buffer manager code. somebody with lots of + * spare time should do this for all the other modules, too. */ -#define BM_NAMESIZE 16 +#define BM_NAMESIZE 16 /* - * struct sbufdesc -- shared buffer cache metadata for a single - * shared buffer descriptor. + * struct sbufdesc -- shared buffer cache metadata for a single + * shared buffer descriptor. * - * We keep the name of the database and relation in which this - * buffer appears in order to avoid a catalog lookup on cache - * flush if we don't have the reldesc in the cache. It is also - * possible that the relation to which this buffer belongs is - * not visible to all backends at the time that it gets flushed. - * Dbname, relname, dbid, and relid are enough to determine where - * to put the buffer, for all storage managers. + * We keep the name of the database and relation in which this + * buffer appears in order to avoid a catalog lookup on cache + * flush if we don't have the reldesc in the cache. It is also + * possible that the relation to which this buffer belongs is + * not visible to all backends at the time that it gets flushed. + * Dbname, relname, dbid, and relid are enough to determine where + * to put the buffer, for all storage managers. */ -#define PADDED_SBUFDESC_SIZE 128 +#define PADDED_SBUFDESC_SIZE 128 /* DO NOT CHANGE THIS NEXT STRUCTURE: It is used only to get padding information for the real sbufdesc structure It should match the sbufdesc structure exactly except for a missing sb_pad */ -struct sbufdesc_unpadded { - Buffer freeNext; - Buffer freePrev; - SHMEM_OFFSET data; - BufferTag tag; - int buf_id; - BufFlags flags; - int16 bufsmgr; - unsigned refcount; +struct sbufdesc_unpadded +{ + Buffer freeNext; + Buffer freePrev; + SHMEM_OFFSET data; + BufferTag tag; + int buf_id; + BufFlags flags; + int16 bufsmgr; + unsigned refcount; #ifdef HAS_TEST_AND_SET - slock_t io_in_progress_lock; -#endif /* HAS_TEST_AND_SET */ - char sb_dbname[NAMEDATALEN]; + slock_t io_in_progress_lock; +#endif /* HAS_TEST_AND_SET */ + char sb_dbname[NAMEDATALEN]; - /* NOTE NO PADDING OF THE MEMBER HERE */ - char sb_relname[NAMEDATALEN]; + /* NOTE NO PADDING OF THE MEMBER HERE */ + char sb_relname[NAMEDATALEN]; }; /* THE REAL STRUCTURE - the structure above must match it, minus sb_pad */ -struct sbufdesc { - Buffer freeNext; /* link for freelist chain */ - Buffer freePrev; - SHMEM_OFFSET data; /* pointer to data in buf pool */ +struct sbufdesc +{ + Buffer freeNext; /* link for freelist chain */ + Buffer freePrev; + SHMEM_OFFSET data; /* pointer to data in buf pool */ - /* tag and id must be together for table lookup to work */ - BufferTag tag; /* file/block identifier */ - int buf_id; /* maps global desc to local desc */ + /* tag and id must be together for table lookup to work */ + BufferTag tag; /* file/block identifier */ + int buf_id; /* maps global desc to local desc */ - BufFlags flags; /* described below */ - int16 bufsmgr; /* storage manager id for buffer */ - unsigned refcount; /* # of times buffer is pinned */ + BufFlags flags; /* described below */ + int16 bufsmgr; /* storage manager id for buffer */ + unsigned refcount; /* # of times buffer is pinned */ #ifdef HAS_TEST_AND_SET - /* can afford a dedicated lock if test-and-set locks are available */ - slock_t io_in_progress_lock; -#endif /* HAS_TEST_AND_SET */ - - char sb_dbname[NAMEDATALEN]; /* name of db in which buf belongs */ - - /* - * I padded this structure to a power of 2 (PADDED_SBUFDESC_SIZE) because - * BufferDescriptorGetBuffer is called a billion times and it does an - * C pointer subtraction (i.e., "x - y" -> array index of x relative - * to y, which is calculated using division by struct size). Integer - * ".div" hits you for 35 cycles, as opposed to a 1-cycle "sra" ... - * this hack cut 10% off of the time to create the Wisconsin database! - * It eats up more shared memory, of course, but we're (allegedly) - * going to make some of these types bigger soon anyway... -pma 1/2/93 - */ - - /* please, don't take the sizeof() this member and use it for - something important */ - - char sb_relname[NAMEDATALEN+ /* name of reln */ - PADDED_SBUFDESC_SIZE-sizeof(struct sbufdesc_unpadded)]; + /* can afford a dedicated lock if test-and-set locks are available */ + slock_t io_in_progress_lock; +#endif /* HAS_TEST_AND_SET */ + + char sb_dbname[NAMEDATALEN]; /* name of db in which buf + * belongs */ + + /* + * I padded this structure to a power of 2 (PADDED_SBUFDESC_SIZE) + * because BufferDescriptorGetBuffer is called a billion times and it + * does an C pointer subtraction (i.e., "x - y" -> array index of x + * relative to y, which is calculated using division by struct size). + * Integer ".div" hits you for 35 cycles, as opposed to a 1-cycle + * "sra" ... this hack cut 10% off of the time to create the Wisconsin + * database! It eats up more shared memory, of course, but we're + * (allegedly) going to make some of these types bigger soon anyway... + * -pma 1/2/93 + */ + + /* + * please, don't take the sizeof() this member and use it for + * something important + */ + + char sb_relname[NAMEDATALEN + /* name of reln */ + PADDED_SBUFDESC_SIZE - sizeof(struct sbufdesc_unpadded)]; }; /* - * mao tracing buffer allocation + * mao tracing buffer allocation */ /*#define BMTRACE*/ #ifdef BMTRACE -typedef struct _bmtrace { - int bmt_pid; - long bmt_buf; - long bmt_dbid; - long bmt_relid; - int bmt_blkno; - int bmt_op; +typedef struct _bmtrace +{ + int bmt_pid; + long bmt_buf; + long bmt_dbid; + long bmt_relid; + int bmt_blkno; + int bmt_op; -#define BMT_NOTUSED 0 +#define BMT_NOTUSED 0 #define BMT_ALLOCFND 1 -#define BMT_ALLOCNOTFND 2 -#define BMT_DEALLOC 3 +#define BMT_ALLOCNOTFND 2 +#define BMT_DEALLOC 3 -} bmtrace; +} bmtrace; -#endif /* BMTRACE */ +#endif /* BMTRACE */ -/* +/* * Bufmgr Interface: */ /* Internal routines: only called by buf.c */ /*freelist.c*/ -extern void AddBufferToFreelist(BufferDesc *bf); -extern void PinBuffer(BufferDesc *buf); -extern void PinBuffer_Debug(char *file, int line, BufferDesc *buf); -extern void UnpinBuffer(BufferDesc *buf); +extern void AddBufferToFreelist(BufferDesc * bf); +extern void PinBuffer(BufferDesc * buf); +extern void PinBuffer_Debug(char *file, int line, BufferDesc * buf); +extern void UnpinBuffer(BufferDesc * buf); extern BufferDesc *GetFreeBuffer(void); -extern void InitFreeList(bool init); +extern void InitFreeList(bool init); /* buf_table.c */ -extern void InitBufTable(void); -extern BufferDesc *BufTableLookup(BufferTag *tagPtr); -extern bool BufTableDelete(BufferDesc *buf); -extern bool BufTableInsert(BufferDesc *buf); +extern void InitBufTable(void); +extern BufferDesc *BufTableLookup(BufferTag * tagPtr); +extern bool BufTableDelete(BufferDesc * buf); +extern bool BufTableInsert(BufferDesc * buf); /* bufmgr.c */ -extern BufferDesc *BufferDescriptors; -extern BufferBlock BufferBlocks; -extern long *PrivateRefCount; -extern long *LastRefCount; -extern long *CommitInfoNeedsSave; -extern SPINLOCK BufMgrLock; +extern BufferDesc *BufferDescriptors; +extern BufferBlock BufferBlocks; +extern long *PrivateRefCount; +extern long *LastRefCount; +extern long *CommitInfoNeedsSave; +extern SPINLOCK BufMgrLock; /* localbuf.c */ -extern long *LocalRefCount; +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 release); -extern void InitLocalBuffer(void); -extern void LocalBufferSync(void); -extern void ResetLocalBufferPool(void); - -#endif /* BUFMGR_INTERNALS_H */ +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 release); +extern void InitLocalBuffer(void); +extern void LocalBufferSync(void); +extern void ResetLocalBufferPool(void); + +#endif /* BUFMGR_INTERNALS_H */ diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index c0ec42ddb83..d432506c7cb 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -1,16 +1,16 @@ /*------------------------------------------------------------------------- * * bufmgr.h-- - * POSTGRES buffer manager definitions. + * POSTGRES buffer manager definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: bufmgr.h,v 1.11 1997/08/19 21:39:45 momjian Exp $ + * $Id: bufmgr.h,v 1.12 1997/09/07 05:01:06 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef BUFMGR_H +#ifndef BUFMGR_H #define BUFMGR_H #include <stdio.h> @@ -27,13 +27,13 @@ * limited to 2^13 bytes because we have limited ItemIdData.lp_off and * ItemIdData.lp_len to 13 bits (see itemid.h). */ -#define MAXBLCKSZ 8192 +#define MAXBLCKSZ 8192 -typedef void *Block; +typedef void *Block; /* special pageno for bget */ -#define P_NEW InvalidBlockNumber /* grow the file to get a new page */ +#define P_NEW InvalidBlockNumber /* grow the file to get a new page */ typedef bits16 BufferLock; @@ -51,57 +51,58 @@ typedef bits16 BufferLock; /* * BufferIsPinned -- - * True iff the buffer is pinned (and therefore valid) + * True iff the buffer is pinned (and therefore valid) * * Note: - * Smenatics are identical to BufferIsValid - * XXX - need to remove either one eventually. + * Smenatics are identical to BufferIsValid + * XXX - need to remove either one eventually. */ #define BufferIsPinned BufferIsValid -extern int ShowPinTrace; +extern int ShowPinTrace; /* * BufferWriteModes (settable via SetBufferWriteMode) */ -#define BUFFER_FLUSH_WRITE 0 /* immediate write */ -#define BUFFER_LATE_WRITE 1 /* delayed write: mark as DIRTY */ +#define BUFFER_FLUSH_WRITE 0 /* immediate write */ +#define BUFFER_LATE_WRITE 1 /* delayed write: mark as DIRTY */ /* - * prototypes for functions in bufmgr.c + * prototypes for functions in bufmgr.c */ -extern Buffer RelationGetBufferWithBuffer(Relation relation, - BlockNumber blockNumber, Buffer buffer); -extern Buffer ReadBuffer(Relation reln, BlockNumber blockNum); -extern int WriteBuffer(Buffer buffer); -extern int WriteNoReleaseBuffer(Buffer buffer); -extern Buffer ReleaseAndReadBuffer(Buffer buffer, Relation relation, - BlockNumber blockNum); - -extern void InitBufferPool(IPCKey key); -extern void PrintBufferUsage(FILE *statfp); -extern void ResetBufferUsage(void); -extern void ResetBufferPool(void); -extern int BufferPoolCheckLeak(void); -extern void FlushBufferPool(int StableMainMemoryFlag); -extern bool BufferIsValid(Buffer bufnum); +extern Buffer +RelationGetBufferWithBuffer(Relation relation, + BlockNumber blockNumber, Buffer buffer); +extern Buffer ReadBuffer(Relation reln, BlockNumber blockNum); +extern int WriteBuffer(Buffer buffer); +extern int WriteNoReleaseBuffer(Buffer buffer); +extern Buffer +ReleaseAndReadBuffer(Buffer buffer, Relation relation, + BlockNumber blockNum); + +extern void InitBufferPool(IPCKey key); +extern void PrintBufferUsage(FILE * statfp); +extern void ResetBufferUsage(void); +extern void ResetBufferPool(void); +extern int BufferPoolCheckLeak(void); +extern void FlushBufferPool(int StableMainMemoryFlag); +extern bool BufferIsValid(Buffer bufnum); extern BlockNumber BufferGetBlockNumber(Buffer buffer); extern Relation BufferGetRelation(Buffer buffer); extern BlockNumber RelationGetNumberOfBlocks(Relation relation); -extern Block BufferGetBlock(Buffer buffer); -extern void ReleaseRelationBuffers(Relation rdesc); -extern void DropBuffers(Oid dbid); -extern void PrintBufferDescs(void); -extern void PrintPinnedBufs(void); -extern int BufferShmemSize(void); -extern void IncrBufferRefCount(Buffer buffer); -extern int ReleaseBuffer(Buffer buffer); - -extern void BufferRefCountReset(int *refcountsave); -extern void BufferRefCountRestore(int *refcountsave); -extern int SetBufferWriteMode (int mode); -extern void SetBufferCommitInfoNeedsSave(Buffer buffer); - -#endif /* !defined(BufMgrIncluded) */ - +extern Block BufferGetBlock(Buffer buffer); +extern void ReleaseRelationBuffers(Relation rdesc); +extern void DropBuffers(Oid dbid); +extern void PrintBufferDescs(void); +extern void PrintPinnedBufs(void); +extern int BufferShmemSize(void); +extern void IncrBufferRefCount(Buffer buffer); +extern int ReleaseBuffer(Buffer buffer); + +extern void BufferRefCountReset(int *refcountsave); +extern void BufferRefCountRestore(int *refcountsave); +extern int SetBufferWriteMode(int mode); +extern void SetBufferCommitInfoNeedsSave(Buffer buffer); + +#endif /* !defined(BufMgrIncluded) */ diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h index 3607e4e25e2..a252ccc3e44 100644 --- a/src/include/storage/bufpage.h +++ b/src/include/storage/bufpage.h @@ -1,16 +1,16 @@ /*------------------------------------------------------------------------- * * bufpage.h-- - * Standard POSTGRES buffer page definitions. + * Standard POSTGRES buffer page definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: bufpage.h,v 1.10 1997/08/26 23:31:58 momjian Exp $ + * $Id: bufpage.h,v 1.11 1997/09/07 05:01:10 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef BUFPAGE_H +#ifndef BUFPAGE_H #define BUFPAGE_H #include <storage/off.h> @@ -27,19 +27,19 @@ * disk page is always a slotted page of the form: * * +----------------+---------------------------------+ - * | PageHeaderData | linp0 linp1 linp2 ... | + * | PageHeaderData | linp0 linp1 linp2 ... | * +-----------+----+---------------------------------+ - * | ... linpN | | + * | ... linpN | | * +-----------+--------------------------------------+ - * | ^ pd_lower | - * | | - * | v pd_upper | + * | ^ pd_lower | + * | | + * | v pd_upper | * +-------------+------------------------------------+ - * | | tupleN ... | + * | | tupleN ... | * +-------------+------------------+-----------------+ - * | ... tuple2 tuple1 tuple0 | "special space" | + * | ... tuple2 tuple1 tuple0 | "special space" | * +--------------------------------+-----------------+ - * ^ pd_special + * ^ pd_special * * a page is full when nothing can be added between pd_lower and * pd_upper. @@ -66,19 +66,19 @@ * whenever the need arises. * * AM-generic per-page information is kept in the pd_opaque field of - * the PageHeaderData. (this is currently only the page size.) + * the PageHeaderData. (this is currently only the page size.) * AM-specific per-page data is kept in the area marked "special * space"; each AM has an "opaque" structure defined somewhere that is - * stored as the page trailer. an access method should always + * stored as the page trailer. an access method should always * initialize its pages with PageInit and then set its own opaque * fields. */ /* * PageIsValid -- - * True iff page is valid. + * True iff page is valid. */ -#define PageIsValid(page) PointerIsValid(page) +#define PageIsValid(page) PointerIsValid(page) /* @@ -93,39 +93,42 @@ typedef uint16 LocationIndex; /* * space management information generic to any page * - * od_pagesize - size in bytes. - * in reality, we need at least 64B to fit the - * page header, opaque space and a minimal tuple; - * on the high end, we can only support pages up - * to 8KB because lp_off/lp_len are 13 bits. + * od_pagesize - size in bytes. + * in reality, we need at least 64B to fit the + * page header, opaque space and a minimal tuple; + * on the high end, we can only support pages up + * to 8KB because lp_off/lp_len are 13 bits. */ -typedef struct OpaqueData { - uint16 od_pagesize; -} OpaqueData; - -typedef OpaqueData *Opaque; +typedef struct OpaqueData +{ + uint16 od_pagesize; +} OpaqueData; + +typedef OpaqueData *Opaque; /* * disk page organization */ -typedef struct PageHeaderData { - LocationIndex pd_lower; /* offset to start of free space */ - LocationIndex pd_upper; /* offset to end of free space */ - LocationIndex pd_special; /* offset to start of special space */ - OpaqueData pd_opaque; /* AM-generic information */ - ItemIdData pd_linp[1]; /* line pointers */ -} PageHeaderData; - -typedef PageHeaderData *PageHeader; - -typedef enum { - ShufflePageManagerMode, - OverwritePageManagerMode -} PageManagerMode; +typedef struct PageHeaderData +{ + LocationIndex pd_lower; /* offset to start of free space */ + LocationIndex pd_upper; /* offset to end of free space */ + LocationIndex pd_special; /* offset to start of special space */ + OpaqueData pd_opaque; /* AM-generic information */ + ItemIdData pd_linp[1]; /* line pointers */ +} PageHeaderData; + +typedef PageHeaderData *PageHeader; + +typedef enum +{ + ShufflePageManagerMode, + OverwritePageManagerMode +} PageManagerMode; /* ---------------- - * misc support macros + * misc support macros * ---------------- */ @@ -134,10 +137,10 @@ typedef enum { * AM-specific opaque space at the end of the page (as in btrees), ... * however, it at least serves as an upper bound for heap pages. */ -#define MAXTUPLEN (BLCKSZ - sizeof (PageHeaderData)) +#define MAXTUPLEN (BLCKSZ - sizeof (PageHeaderData)) /* ---------------------------------------------------------------- - * page support macros + * page support macros * ---------------------------------------------------------------- */ /* @@ -146,146 +149,147 @@ typedef enum { /* * PageIsUsed -- - * True iff the page size is used. + * True iff the page size is used. * * Note: - * Assumes page is valid. + * Assumes page is valid. */ #define PageIsUsed(page) \ - (AssertMacro(PageIsValid(page)) ? \ - ((bool) (((PageHeader) (page))->pd_lower != 0)) : false) + (AssertMacro(PageIsValid(page)) ? \ + ((bool) (((PageHeader) (page))->pd_lower != 0)) : false) /* * PageIsEmpty -- - * returns true iff no itemid has been allocated on the page + * returns true iff no itemid has been allocated on the page */ #define PageIsEmpty(page) \ - (((PageHeader) (page))->pd_lower == \ - (sizeof(PageHeaderData) - sizeof(ItemIdData)) ? true : false) + (((PageHeader) (page))->pd_lower == \ + (sizeof(PageHeaderData) - sizeof(ItemIdData)) ? true : false) /* - * PageIsNew -- - * returns true iff page is not initialized (by PageInit) + * PageIsNew -- + * returns true iff page is not initialized (by PageInit) */ -#define PageIsNew(page) (((PageHeader) (page))->pd_upper == 0) +#define PageIsNew(page) (((PageHeader) (page))->pd_upper == 0) /* * PageGetItemId -- - * Returns an item identifier of a page. + * Returns an item identifier of a page. */ #define PageGetItemId(page, offsetNumber) \ - ((ItemId) (&((PageHeader) (page))->pd_linp[(-1) + (offsetNumber)])) + ((ItemId) (&((PageHeader) (page))->pd_linp[(-1) + (offsetNumber)])) /* ---------------- - * macros to access opaque space + * macros to access opaque space * ---------------- */ /* * PageSizeIsValid -- - * True iff the page size is valid. + * True iff the page size is valid. * * XXX currently all page sizes are "valid" but we only actually - * use BLCKSZ. + * use BLCKSZ. */ #define PageSizeIsValid(pageSize) 1 /* * PageGetPageSize -- - * Returns the page size of a page. + * Returns the page size of a page. * * this can only be called on a formatted page (unlike * BufferGetPageSize, which can be called on an unformatted page). * however, it can be called on a page for which there is no buffer. */ #define PageGetPageSize(page) \ - ((Size) ((PageHeader) (page))->pd_opaque.od_pagesize) + ((Size) ((PageHeader) (page))->pd_opaque.od_pagesize) /* * PageSetPageSize -- - * Sets the page size of a page. + * Sets the page size of a page. */ #define PageSetPageSize(page, size) \ - ((PageHeader) (page))->pd_opaque.od_pagesize = (size) + ((PageHeader) (page))->pd_opaque.od_pagesize = (size) /* ---------------- - * page special data macros + * page special data macros * ---------------- */ /* * PageGetSpecialSize -- - * Returns size of special space on a page. + * Returns size of special space on a page. * * Note: - * Assumes page is locked. + * Assumes page is locked. */ #define PageGetSpecialSize(page) \ - ((uint16) (PageGetPageSize(page) - ((PageHeader)(page))->pd_special)) + ((uint16) (PageGetPageSize(page) - ((PageHeader)(page))->pd_special)) /* * PageGetSpecialPointer -- - * Returns pointer to special space on a page. + * Returns pointer to special space on a page. * * Note: - * Assumes page is locked. + * Assumes page is locked. */ #define PageGetSpecialPointer(page) \ - (AssertMacro(PageIsValid(page)) ? \ - (char *) ((char *) (page) + ((PageHeader) (page))->pd_special) \ - : (char *)0 ) + (AssertMacro(PageIsValid(page)) ? \ + (char *) ((char *) (page) + ((PageHeader) (page))->pd_special) \ + : (char *)0 ) /* * PageGetItem -- - * Retrieves an item on the given page. + * Retrieves an item on the given page. * * Note: - * This does change the status of any of the resources passed. - * The semantics may change in the future. + * This does change the status of any of the resources passed. + * The semantics may change in the future. */ #define PageGetItem(page, itemId) \ - (AssertMacro(PageIsValid(page)) ? \ - AssertMacro((itemId)->lp_flags & LP_USED) ? \ - (Item)(((char *)(page)) + (itemId)->lp_off) : false : false) + (AssertMacro(PageIsValid(page)) ? \ + AssertMacro((itemId)->lp_flags & LP_USED) ? \ + (Item)(((char *)(page)) + (itemId)->lp_off) : false : false) /* * BufferGetPageSize -- - * Returns the page size within a buffer. + * Returns the page size within a buffer. * * Notes: - * Assumes buffer is valid. + * Assumes buffer is valid. * - * The buffer can be a raw disk block and need not contain a valid - * (formatted) disk page. + * The buffer can be a raw disk block and need not contain a valid + * (formatted) disk page. */ /* XXX dig out of buffer descriptor */ #define BufferGetPageSize(buffer) \ - (AssertMacro(BufferIsValid(buffer)) ? \ - AssertMacro(PageSizeIsValid(pageSize)) ? \ - ((Size)BLCKSZ) : false : false) + (AssertMacro(BufferIsValid(buffer)) ? \ + AssertMacro(PageSizeIsValid(pageSize)) ? \ + ((Size)BLCKSZ) : false : false) /* * BufferGetPage -- - * Returns the page associated with a buffer. + * Returns the page associated with a buffer. */ #define BufferGetPage(buffer) ((Page)BufferGetBlock(buffer)) - + /* ---------------------------------------------------------------- - * extern declarations + * extern declarations * ---------------------------------------------------------------- */ -extern void PageInit(Page page, Size pageSize, Size specialSize); -extern OffsetNumber PageAddItem(Page page, Item item, Size size, - OffsetNumber offsetNumber, ItemIdFlags flags); -extern Page PageGetTempPage(Page page, Size specialSize); -extern void PageRestoreTempPage(Page tempPage, Page oldPage); +extern void PageInit(Page page, Size pageSize, Size specialSize); +extern OffsetNumber +PageAddItem(Page page, Item item, Size size, + OffsetNumber offsetNumber, ItemIdFlags flags); +extern Page PageGetTempPage(Page page, Size specialSize); +extern void PageRestoreTempPage(Page tempPage, Page oldPage); extern OffsetNumber PageGetMaxOffsetNumber(Page page); -extern void PageRepairFragmentation(Page page); -extern Size PageGetFreeSpace(Page page); -extern void PageManagerModeSet(PageManagerMode mode); -extern void PageIndexTupleDelete(Page page, OffsetNumber offset); +extern void PageRepairFragmentation(Page page); +extern Size PageGetFreeSpace(Page page); +extern void PageManagerModeSet(PageManagerMode mode); +extern void PageIndexTupleDelete(Page page, OffsetNumber offset); -#endif /* BUFPAGE_H */ +#endif /* BUFPAGE_H */ diff --git a/src/include/storage/fd.h b/src/include/storage/fd.h index bd76109ac0e..9fbe004d4a3 100644 --- a/src/include/storage/fd.h +++ b/src/include/storage/fd.h @@ -1,37 +1,37 @@ /*------------------------------------------------------------------------- * * fd.h-- - * Virtual file descriptor definitions. + * Virtual file descriptor definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: fd.h,v 1.8 1997/08/19 21:39:48 momjian Exp $ + * $Id: fd.h,v 1.9 1997/09/07 05:01:12 momjian Exp $ * *------------------------------------------------------------------------- */ /* * calls: - * - * File {Close, Read, Write, Seek, Tell, Sync} - * {File Name Open, Allocate, Free} File + * + * File {Close, Read, Write, Seek, Tell, Sync} + * {File Name Open, Allocate, Free} File * * These are NOT JUST RENAMINGS OF THE UNIX ROUTINES. * use them for all file activity... * - * fd = FilePathOpenFile("foo", O_RDONLY); - * File fd; + * fd = FilePathOpenFile("foo", O_RDONLY); + * File fd; * * use AllocateFile if you need a file descriptor in some other context. * it will make sure that there is a file descriptor free * - * use FreeFile to let the virtual file descriptor package know that + * use FreeFile to let the virtual file descriptor package know that * there is now a free fd (when you are done with it) * - * AllocateFile(); - * FreeFile(); + * AllocateFile(); + * FreeFile(); */ -#ifndef FD_H +#ifndef FD_H #define FD_H #include <stdio.h> @@ -42,37 +42,39 @@ typedef char *FileName; -typedef int File; +typedef int File; /* originally in libpq-fs.h */ -struct pgstat { /* just the fields we need from stat structure */ - int st_ino; - int st_mode; - unsigned int st_size; - unsigned int st_sizehigh; /* high order bits */ +struct pgstat +{ /* just the fields we need from stat + * structure */ + int st_ino; + int st_mode; + unsigned int st_size; + unsigned int st_sizehigh;/* high order bits */ /* 2^64 == 1.8 x 10^20 bytes */ - int st_uid; - int st_atime_s; /* just the seconds */ - int st_mtime_s; /* since SysV and the new BSD both have */ - int st_ctime_s; /* usec fields.. */ + int st_uid; + int st_atime_s; /* just the seconds */ + int st_mtime_s; /* since SysV and the new BSD both have */ + int st_ctime_s; /* usec fields.. */ }; /* * prototypes for functions in fd.c */ -extern File FileNameOpenFile(FileName fileName, int fileFlags, int fileMode); -extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode); -extern void FileClose(File file); -extern void FileUnlink(File file); -extern int FileRead(File file, char *buffer, int amount); -extern int FileWrite(File file, char *buffer, int amount); -extern long FileSeek(File file, long offset, int whence); -extern int FileTruncate(File file, int offset); -extern int FileSync(File file); -extern int FileNameUnlink(char *filename); -extern FILE *AllocateFile(char *name, char *mode); -extern void FreeFile(FILE *); -extern void closeAllVfds(void); -extern int pg_fsync(int fd); +extern File FileNameOpenFile(FileName fileName, int fileFlags, int fileMode); +extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode); +extern void FileClose(File file); +extern void FileUnlink(File file); +extern int FileRead(File file, char *buffer, int amount); +extern int FileWrite(File file, char *buffer, int amount); +extern long FileSeek(File file, long offset, int whence); +extern int FileTruncate(File file, int offset); +extern int FileSync(File file); +extern int FileNameUnlink(char *filename); +extern FILE *AllocateFile(char *name, char *mode); +extern void FreeFile(FILE *); +extern void closeAllVfds(void); +extern int pg_fsync(int fd); -#endif /* FD_H */ +#endif /* FD_H */ diff --git a/src/include/storage/ipc.h b/src/include/storage/ipc.h index 69f8b2ba862..9e08d6b94ee 100644 --- a/src/include/storage/ipc.h +++ b/src/include/storage/ipc.h @@ -1,171 +1,181 @@ /*------------------------------------------------------------------------- * * ipc.h-- - * POSTGRES inter-process communication definitions. + * POSTGRES inter-process communication definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: ipc.h,v 1.17 1997/08/19 21:39:50 momjian Exp $ + * $Id: ipc.h,v 1.18 1997/09/07 05:01:14 momjian Exp $ * * NOTES - * This file is very architecture-specific. This stuff should actually - * be factored into the port/ directories. + * This file is very architecture-specific. This stuff should actually + * be factored into the port/ directories. * - * Some files that would normally need to include only sys/ipc.h must + * Some files that would normally need to include only sys/ipc.h must * instead included this file because on Ultrix, sys/ipc.h is not designed * to be included multiple times. This file (by virtue of the ifndef IPC_H) * is. *------------------------------------------------------------------------- */ -#ifndef IPC_H +#ifndef IPC_H #define IPC_H #include <sys/types.h> -#include <sys/ipc.h> /* For IPC_PRIVATE */ +#include <sys/ipc.h> /* For IPC_PRIVATE */ #include <config.h> #if defined(HAS_TEST_AND_SET) -extern void S_LOCK(slock_t *lock); -extern void S_UNLOCK(slock_t *lock); -extern void S_INIT_LOCK(slock_t *lock); +extern void S_LOCK(slock_t * lock); +extern void S_UNLOCK(slock_t * lock); +extern void S_INIT_LOCK(slock_t * lock); #if (defined(alpha) && !defined(linuxalpha)) || \ - defined(hpux) || \ - defined(irix5) || \ - defined(nextstep) -extern int S_LOCK_FREE(slock_t *lock); + defined(hpux) || \ + defined(irix5) || \ + defined(nextstep) +extern int S_LOCK_FREE(slock_t * lock); + #else -#define S_LOCK_FREE(lock) ((*lock) == 0) +#define S_LOCK_FREE(lock) ((*lock) == 0) #endif -#endif /* HAS_TEST_AND_SET */ +#endif /* HAS_TEST_AND_SET */ #ifndef HAVE_UNION_SEMUN -union semun { - int val; - struct semid_ds *buf; - unsigned short *array; +union semun +{ + int val; + struct semid_ds *buf; + unsigned short *array; }; + #endif typedef uint16 SystemPortAddress; /* semaphore definitions */ -#define IPCProtection (0600) /* access/modify by user only */ +#define IPCProtection (0600) /* access/modify by user only */ -#define IPC_NMAXSEM 25 /* maximum number of semaphores */ +#define IPC_NMAXSEM 25 /* maximum number of semaphores */ #define IpcSemaphoreDefaultStartValue 255 -#define IpcSharedLock (-1) -#define IpcExclusiveLock (-255) +#define IpcSharedLock (-1) +#define IpcExclusiveLock (-255) -#define IpcUnknownStatus (-1) -#define IpcInvalidArgument (-2) -#define IpcSemIdExist (-3) -#define IpcSemIdNotExist (-4) +#define IpcUnknownStatus (-1) +#define IpcInvalidArgument (-2) +#define IpcSemIdExist (-3) +#define IpcSemIdNotExist (-4) -typedef uint32 IpcSemaphoreKey; /* semaphore key */ -typedef int IpcSemaphoreId; +typedef uint32 IpcSemaphoreKey;/* semaphore key */ +typedef int IpcSemaphoreId; -/* shared memory definitions */ +/* shared memory definitions */ #define IpcMemCreationFailed (-1) -#define IpcMemIdGetFailed (-2) -#define IpcMemAttachFailed 0 +#define IpcMemIdGetFailed (-2) +#define IpcMemAttachFailed 0 typedef uint32 IPCKey; + #define PrivateIPCKey IPC_PRIVATE #define DefaultIPCKey 17317 -typedef uint32 IpcMemoryKey; /* shared memory key */ -typedef int IpcMemoryId; +typedef uint32 IpcMemoryKey; /* shared memory key */ +typedef int IpcMemoryId; /* ipc.c */ -extern void exitpg(int code); -extern void quasi_exitpg(void); -extern int on_exitpg(void (*function)(), caddr_t arg); - -extern IpcSemaphoreId IpcSemaphoreCreate(IpcSemaphoreKey semKey, - int semNum, int permission, int semStartValue, - int removeOnExit, int *status); -extern void IpcSemaphoreKill(IpcSemaphoreKey key); -extern void IpcSemaphoreLock(IpcSemaphoreId semId, int sem, int lock); -extern void IpcSemaphoreUnlock(IpcSemaphoreId semId, int sem, int lock); -extern int IpcSemaphoreGetCount(IpcSemaphoreId semId, int sem); -extern int IpcSemaphoreGetValue(IpcSemaphoreId semId, int sem); -extern IpcMemoryId IpcMemoryCreate(IpcMemoryKey memKey, uint32 size, - int permission); +extern void exitpg(int code); +extern void quasi_exitpg(void); +extern int on_exitpg(void (*function) (), caddr_t arg); + +extern IpcSemaphoreId +IpcSemaphoreCreate(IpcSemaphoreKey semKey, + int semNum, int permission, int semStartValue, + int removeOnExit, int *status); +extern void IpcSemaphoreKill(IpcSemaphoreKey key); +extern void IpcSemaphoreLock(IpcSemaphoreId semId, int sem, int lock); +extern void IpcSemaphoreUnlock(IpcSemaphoreId semId, int sem, int lock); +extern int IpcSemaphoreGetCount(IpcSemaphoreId semId, int sem); +extern int IpcSemaphoreGetValue(IpcSemaphoreId semId, int sem); +extern IpcMemoryId +IpcMemoryCreate(IpcMemoryKey memKey, uint32 size, + int permission); extern IpcMemoryId IpcMemoryIdGet(IpcMemoryKey memKey, uint32 size); -extern char *IpcMemoryAttach(IpcMemoryId memId); -extern void IpcMemoryKill(IpcMemoryKey memKey); -extern void CreateAndInitSLockMemory(IPCKey key); -extern void AttachSLockMemory(IPCKey key); +extern char *IpcMemoryAttach(IpcMemoryId memId); +extern void IpcMemoryKill(IpcMemoryKey memKey); +extern void CreateAndInitSLockMemory(IPCKey key); +extern void AttachSLockMemory(IPCKey key); #ifdef HAS_TEST_AND_SET -#define NSLOCKS 2048 -#define NOLOCK 0 -#define SHAREDLOCK 1 +#define NSLOCKS 2048 +#define NOLOCK 0 +#define SHAREDLOCK 1 #define EXCLUSIVELOCK 2 -typedef enum _LockId_ { - BUFMGRLOCKID, - LOCKLOCKID, - OIDGENLOCKID, - SHMEMLOCKID, - BINDINGLOCKID, - LOCKMGRLOCKID, - SINVALLOCKID, +typedef enum _LockId_ +{ + BUFMGRLOCKID, + LOCKLOCKID, + OIDGENLOCKID, + SHMEMLOCKID, + BINDINGLOCKID, + LOCKMGRLOCKID, + SINVALLOCKID, #ifdef MAIN_MEMORY - MMCACHELOCKID, -#endif /* MAIN_MEMORY */ - - PROCSTRUCTLOCKID, - FIRSTFREELOCKID -} _LockId_; - -#define MAX_SPINS FIRSTFREELOCKID - -typedef struct slock { - slock_t locklock; - unsigned char flag; - short nshlocks; - slock_t shlock; - slock_t exlock; - slock_t comlock; - struct slock *next; -} SLock; - -extern void ExclusiveLock(int lockid); -extern void ExclusiveUnlock(int lockid); -extern bool LockIsFree(int lockid); -#else /* HAS_TEST_AND_SET */ - -typedef enum _LockId_ { - SHMEMLOCKID, - BINDINGLOCKID, - BUFMGRLOCKID, - LOCKMGRLOCKID, - SINVALLOCKID, + MMCACHELOCKID, +#endif /* MAIN_MEMORY */ + + PROCSTRUCTLOCKID, + FIRSTFREELOCKID +} _LockId_; + +#define MAX_SPINS FIRSTFREELOCKID + +typedef struct slock +{ + slock_t locklock; + unsigned char flag; + short nshlocks; + slock_t shlock; + slock_t exlock; + slock_t comlock; + struct slock *next; +} SLock; + +extern void ExclusiveLock(int lockid); +extern void ExclusiveUnlock(int lockid); +extern bool LockIsFree(int lockid); + +#else /* HAS_TEST_AND_SET */ + +typedef enum _LockId_ +{ + SHMEMLOCKID, + BINDINGLOCKID, + BUFMGRLOCKID, + LOCKMGRLOCKID, + SINVALLOCKID, #ifdef MAIN_MEMORY - MMCACHELOCKID, -#endif /* MAIN_MEMORY */ + MMCACHELOCKID, +#endif /* MAIN_MEMORY */ - PROCSTRUCTLOCKID, - OIDGENLOCKID, - FIRSTFREELOCKID -} _LockId_; + PROCSTRUCTLOCKID, + OIDGENLOCKID, + FIRSTFREELOCKID +} _LockId_; -#define MAX_SPINS FIRSTFREELOCKID +#define MAX_SPINS FIRSTFREELOCKID -#endif /* HAS_TEST_AND_SET */ +#endif /* HAS_TEST_AND_SET */ /* * the following are originally in ipci.h but the prototypes have circular @@ -176,42 +186,42 @@ typedef enum _LockId_ { /* * Note: - * These must not hash to DefaultIPCKey or PrivateIPCKey. + * These must not hash to DefaultIPCKey or PrivateIPCKey. */ #define SystemPortAddressGetIPCKey(address) \ - (28597 * (address) + 17491) + (28597 * (address) + 17491) /* * these keys are originally numbered from 1 to 12 consecutively but not - * all are used. The unused ones are removed. - ay 4/95. + * all are used. The unused ones are removed. - ay 4/95. */ #define IPCKeyGetBufferMemoryKey(key) \ - ((key == PrivateIPCKey) ? key : 1 + (key)) + ((key == PrivateIPCKey) ? key : 1 + (key)) #define IPCKeyGetSIBufferMemoryBlock(key) \ - ((key == PrivateIPCKey) ? key : 7 + (key)) + ((key == PrivateIPCKey) ? key : 7 + (key)) #define IPCKeyGetSLockSharedMemoryKey(key) \ - ((key == PrivateIPCKey) ? key : 10 + (key)) + ((key == PrivateIPCKey) ? key : 10 + (key)) #define IPCKeyGetSpinLockSemaphoreKey(key) \ - ((key == PrivateIPCKey) ? key : 11 + (key)) + ((key == PrivateIPCKey) ? key : 11 + (key)) #define IPCKeyGetWaitIOSemaphoreKey(key) \ - ((key == PrivateIPCKey) ? key : 12 + (key)) + ((key == PrivateIPCKey) ? key : 12 + (key)) /* -------------------------- * NOTE: This macro must always give the highest numbered key as every backend * process forked off by the postmaster will be trying to acquire a semaphore - * with a unique key value starting at key+14 and incrementing up. Each + * with a unique key value starting at key+14 and incrementing up. Each * backend uses the current key value then increments it by one. * -------------------------- */ #define IPCGetProcessSemaphoreInitKey(key) \ - ((key == PrivateIPCKey) ? key : 14 + (key)) + ((key == PrivateIPCKey) ? key : 14 + (key)) /* ipci.c */ -extern IPCKey SystemPortAddressCreateIPCKey(SystemPortAddress address); -extern void CreateSharedMemoryAndSemaphores(IPCKey key); -extern void AttachSharedMemoryAndSemaphores(IPCKey key); +extern IPCKey SystemPortAddressCreateIPCKey(SystemPortAddress address); +extern void CreateSharedMemoryAndSemaphores(IPCKey key); +extern void AttachSharedMemoryAndSemaphores(IPCKey key); -#endif /* IPC_H */ +#endif /* IPC_H */ diff --git a/src/include/storage/item.h b/src/include/storage/item.h index c943fc33f00..6541a717f9f 100644 --- a/src/include/storage/item.h +++ b/src/include/storage/item.h @@ -1,18 +1,18 @@ /*------------------------------------------------------------------------- * * item.h-- - * POSTGRES disk item definitions. + * POSTGRES disk item definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: item.h,v 1.2 1996/10/31 09:49:49 scrappy Exp $ + * $Id: item.h,v 1.3 1997/09/07 05:01:16 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef ITEM_H +#ifndef ITEM_H #define ITEM_H -typedef Pointer Item; +typedef Pointer Item; -#endif /* ITEM_H */ +#endif /* ITEM_H */ diff --git a/src/include/storage/itemid.h b/src/include/storage/itemid.h index 7e4fc5e28d6..9e5e6f94d4a 100644 --- a/src/include/storage/itemid.h +++ b/src/include/storage/itemid.h @@ -1,16 +1,16 @@ /*------------------------------------------------------------------------- * * itemid.h-- - * Standard POSTGRES buffer page item identifier definitions. + * Standard POSTGRES buffer page item identifier definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: itemid.h,v 1.1 1996/08/28 01:58:08 scrappy Exp $ + * $Id: itemid.h,v 1.2 1997/09/07 05:01:17 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef ITEMID_H +#ifndef ITEMID_H #define ITEMID_H typedef uint16 ItemOffset; @@ -20,56 +20,57 @@ typedef bits16 ItemIdFlags; -typedef struct ItemIdData { /* line pointers */ - unsigned lp_off:13, /* offset to find tup */ - /* can be reduced by 2 if necc. */ - lp_flags:6, /* flags on tuple */ - lp_len:13; /* length of tuple */ -} ItemIdData; +typedef struct ItemIdData +{ /* line pointers */ + unsigned lp_off:13, /* offset to find tup */ + /* can be reduced by 2 if necc. */ + lp_flags:6, /* flags on tuple */ + lp_len:13; /* length of tuple */ +} ItemIdData; -typedef struct ItemIdData *ItemId; +typedef struct ItemIdData *ItemId; -#ifndef LP_USED -#define LP_USED 0x01 /* this line pointer is being used */ +#ifndef LP_USED +#define LP_USED 0x01 /* this line pointer is being used */ #endif /* ---------------- - * support macros + * support macros * ---------------- */ -/* - * ItemIdGetLength +/* + * ItemIdGetLength */ #define ItemIdGetLength(itemId) \ ((itemId)->lp_len) -/* - * ItemIdGetOffset +/* + * ItemIdGetOffset */ #define ItemIdGetOffset(itemId) \ ((itemId)->lp_off) -/* - * ItemIdGetFlags +/* + * ItemIdGetFlags */ #define ItemIdGetFlags(itemId) \ ((itemId)->lp_flags) /* * ItemIdIsValid -- - * True iff disk item identifier is valid. + * True iff disk item identifier is valid. */ -#define ItemIdIsValid(itemId) PointerIsValid(itemId) +#define ItemIdIsValid(itemId) PointerIsValid(itemId) /* * ItemIdIsUsed -- - * True iff disk item identifier is in use. + * True iff disk item identifier is in use. * * Note: - * Assumes disk item identifier is valid. + * Assumes disk item identifier is valid. */ #define ItemIdIsUsed(itemId) \ - (AssertMacro(ItemIdIsValid(itemId)) ? \ - (bool) (((itemId)->lp_flags & LP_USED) != 0) : false) + (AssertMacro(ItemIdIsValid(itemId)) ? \ + (bool) (((itemId)->lp_flags & LP_USED) != 0) : false) -#endif /* ITEMID_H */ +#endif /* ITEMID_H */ diff --git a/src/include/storage/itempos.h b/src/include/storage/itempos.h index fc847df4ec9..bea9cd64746 100644 --- a/src/include/storage/itempos.h +++ b/src/include/storage/itempos.h @@ -1,43 +1,44 @@ /*------------------------------------------------------------------------- * * itempos.h-- - * Standard POSTGRES buffer page long item subposition definitions. + * Standard POSTGRES buffer page long item subposition definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: itempos.h,v 1.3 1996/11/05 06:10:58 scrappy Exp $ + * $Id: itempos.h,v 1.4 1997/09/07 05:01:20 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef ITEMPOS_H +#ifndef ITEMPOS_H #define ITEMPOS_H #include <storage/itemid.h> #include <storage/buf.h> -typedef struct ItemSubpositionData { - Buffer op_db; - ItemId op_lpp; - char *op_cp; /* XXX */ - uint32 op_len; -} ItemSubpositionData; +typedef struct ItemSubpositionData +{ + Buffer op_db; + ItemId op_lpp; + char *op_cp; /* XXX */ + uint32 op_len; +} ItemSubpositionData; -typedef ItemSubpositionData *ItemSubposition; +typedef ItemSubpositionData *ItemSubposition; /* - * PNOBREAK(OBJP, LEN) - * struct objpos *OBJP; - * unsigned LEN; + * PNOBREAK(OBJP, LEN) + * struct objpos *OBJP; + * unsigned LEN; */ -#define PNOBREAK(OBJP, LEN) ((OBJP)->op_len >= LEN) +#define PNOBREAK(OBJP, LEN) ((OBJP)->op_len >= LEN) /* - * PSKIP(OBJP, LEN) - * struct objpos *OBJP; - * unsigned LEN; + * PSKIP(OBJP, LEN) + * struct objpos *OBJP; + * unsigned LEN; */ #define PSKIP(OBJP, LEN)\ - { (OBJP)->op_cp += (LEN); (OBJP)->op_len -= (LEN); } + { (OBJP)->op_cp += (LEN); (OBJP)->op_len -= (LEN); } -#endif /* ITEMPOS_H */ +#endif /* ITEMPOS_H */ diff --git a/src/include/storage/itemptr.h b/src/include/storage/itemptr.h index f794141a6e0..3460cd19f9e 100644 --- a/src/include/storage/itemptr.h +++ b/src/include/storage/itemptr.h @@ -1,16 +1,16 @@ /*------------------------------------------------------------------------- * * itemptr.h-- - * POSTGRES disk item pointer definitions. + * POSTGRES disk item pointer definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: itemptr.h,v 1.4 1996/11/04 07:18:29 scrappy Exp $ + * $Id: itemptr.h,v 1.5 1997/09/07 05:01:22 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef ITEMPTR_H +#ifndef ITEMPTR_H #define ITEMPTR_H #include <storage/off.h> @@ -23,91 +23,91 @@ * blkid tells us which block, posid tells us which entry in the linp * (ItemIdData) array we want. */ -typedef struct ItemPointerData { - BlockIdData ip_blkid; - OffsetNumber ip_posid; -} ItemPointerData; +typedef struct ItemPointerData +{ + BlockIdData ip_blkid; + OffsetNumber ip_posid; +} ItemPointerData; -typedef ItemPointerData *ItemPointer; +typedef ItemPointerData *ItemPointer; /* ---------------- - * support macros + * support macros * ---------------- */ /* * ItemPointerIsValid -- - * True iff the disk item pointer is not NULL. + * True iff the disk item pointer is not NULL. */ #define ItemPointerIsValid(pointer) \ - ((bool) (PointerIsValid(pointer) && ((pointer)->ip_posid != 0))) + ((bool) (PointerIsValid(pointer) && ((pointer)->ip_posid != 0))) /* * ItemPointerGetBlockNumber -- - * Returns the block number of a disk item pointer. + * Returns the block number of a disk item pointer. */ #define ItemPointerGetBlockNumber(pointer) \ - (AssertMacro(ItemPointerIsValid(pointer)) ? \ - BlockIdGetBlockNumber(&(pointer)->ip_blkid) : (BlockNumber) 0) + (AssertMacro(ItemPointerIsValid(pointer)) ? \ + BlockIdGetBlockNumber(&(pointer)->ip_blkid) : (BlockNumber) 0) /* * ItemPointerGetOffsetNumber -- - * Returns the offset number of a disk item pointer. + * Returns the offset number of a disk item pointer. */ #define ItemPointerGetOffsetNumber(pointer) \ - (AssertMacro(ItemPointerIsValid(pointer)) ? \ - (pointer)->ip_posid : \ - InvalidOffsetNumber) + (AssertMacro(ItemPointerIsValid(pointer)) ? \ + (pointer)->ip_posid : \ + InvalidOffsetNumber) /* * ItemPointerSet -- - * Sets a disk item pointer to the specified block and offset. + * Sets a disk item pointer to the specified block and offset. */ #define ItemPointerSet(pointer, blockNumber, offNum) \ - Assert(PointerIsValid(pointer)); \ - BlockIdSet(&((pointer)->ip_blkid), blockNumber); \ - (pointer)->ip_posid = offNum + Assert(PointerIsValid(pointer)); \ + BlockIdSet(&((pointer)->ip_blkid), blockNumber); \ + (pointer)->ip_posid = offNum /* * ItemPointerSetBlockNumber -- - * Sets a disk item pointer to the specified block. + * Sets a disk item pointer to the specified block. */ #define ItemPointerSetBlockNumber(pointer, blockNumber) \ - Assert(PointerIsValid(pointer)); \ - BlockIdSet(&((pointer)->ip_blkid), blockNumber) + Assert(PointerIsValid(pointer)); \ + BlockIdSet(&((pointer)->ip_blkid), blockNumber) /* * ItemPointerSetOffsetNumber -- - * Sets a disk item pointer to the specified offset. + * Sets a disk item pointer to the specified offset. */ #define ItemPointerSetOffsetNumber(pointer, offsetNumber) \ - AssertMacro(PointerIsValid(pointer)); \ - (pointer)->ip_posid = (offsetNumber) + AssertMacro(PointerIsValid(pointer)); \ + (pointer)->ip_posid = (offsetNumber) /* * ItemPointerCopy -- - * Copies the contents of one disk item pointer to another. + * Copies the contents of one disk item pointer to another. */ #define ItemPointerCopy(fromPointer, toPointer) \ - Assert(PointerIsValid(toPointer)); \ - Assert(PointerIsValid(fromPointer)); \ - *(toPointer) = *(fromPointer) + Assert(PointerIsValid(toPointer)); \ + Assert(PointerIsValid(fromPointer)); \ + *(toPointer) = *(fromPointer) /* * ItemPointerSetInvalid -- - * Sets a disk item pointer to be invalid. + * Sets a disk item pointer to be invalid. */ #define ItemPointerSetInvalid(pointer) \ - Assert(PointerIsValid(pointer)); \ - BlockIdSet(&((pointer)->ip_blkid), InvalidBlockNumber); \ - (pointer)->ip_posid = InvalidOffsetNumber + Assert(PointerIsValid(pointer)); \ + BlockIdSet(&((pointer)->ip_blkid), InvalidBlockNumber); \ + (pointer)->ip_posid = InvalidOffsetNumber /* ---------------- - * externs + * externs * ---------------- */ -extern bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2); - -#endif /* ITEMPTR_H */ +extern bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2); +#endif /* ITEMPTR_H */ diff --git a/src/include/storage/large_object.h b/src/include/storage/large_object.h index b5ee9cc068a..1144d1ca02d 100644 --- a/src/include/storage/large_object.h +++ b/src/include/storage/large_object.h @@ -1,18 +1,18 @@ /*------------------------------------------------------------------------- * * large_object.h-- - * file of info for Postgres large objects. POSTGRES 4.2 supports - * zillions of large objects (internal, external, jaquith, inversion). - * Now we only support inversion. + * file of info for Postgres large objects. POSTGRES 4.2 supports + * zillions of large objects (internal, external, jaquith, inversion). + * Now we only support inversion. * * Copyright (c) 1994, Regents of the University of California * - * $Id: large_object.h,v 1.4 1997/08/19 21:39:52 momjian Exp $ + * $Id: large_object.h,v 1.5 1997/09/07 05:01:24 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef LARGE_OBJECT_H -#define LARGE_OBJECT_H +#ifndef LARGE_OBJECT_H +#define LARGE_OBJECT_H #include <sys/types.h> @@ -23,22 +23,22 @@ */ typedef struct LargeObjectDesc { - Relation heap_r; /* heap relation */ - Relation index_r; /* index relation on seqno attribute */ - IndexScanDesc iscan; /* index scan we're using */ - TupleDesc hdesc; /* heap relation tuple desc */ - TupleDesc idesc; /* index relation tuple desc */ - uint32 lowbyte; /* low byte on the current page */ - uint32 highbyte; /* high byte on the current page */ - uint32 offset; /* current seek pointer */ - ItemPointerData htid; /* tid of current heap tuple */ - -#define IFS_RDLOCK (1 << 0) -#define IFS_WRLOCK (1 << 1) -#define IFS_ATEOF (1 << 2) - - u_long flags; /* locking info, etc */ -} LargeObjectDesc; + Relation heap_r; /* heap relation */ + Relation index_r; /* index relation on seqno attribute */ + IndexScanDesc iscan; /* index scan we're using */ + TupleDesc hdesc; /* heap relation tuple desc */ + TupleDesc idesc; /* index relation tuple desc */ + uint32 lowbyte; /* low byte on the current page */ + uint32 highbyte; /* high byte on the current page */ + uint32 offset; /* current seek pointer */ + ItemPointerData htid; /* tid of current heap tuple */ + +#define IFS_RDLOCK (1 << 0) +#define IFS_WRLOCK (1 << 1) +#define IFS_ATEOF (1 << 2) + + u_long flags; /* locking info, etc */ +} LargeObjectDesc; /* * Function definitions... @@ -47,11 +47,11 @@ typedef struct LargeObjectDesc /* inversion stuff in inv_api.c */ extern LargeObjectDesc *inv_create(int flags); extern LargeObjectDesc *inv_open(Oid lobjId, int flags); -extern void inv_close(LargeObjectDesc *obj_desc); -extern int inv_destroy(Oid lobjId); -extern int inv_seek(LargeObjectDesc *obj_desc, int offset, int whence); -extern int inv_tell(LargeObjectDesc *obj_desc); -extern int inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes); -extern int inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes); - -#endif /* LARGE_OBJECT_H */ +extern void inv_close(LargeObjectDesc * obj_desc); +extern int inv_destroy(Oid lobjId); +extern int inv_seek(LargeObjectDesc * obj_desc, int offset, int whence); +extern int inv_tell(LargeObjectDesc * obj_desc); +extern int inv_read(LargeObjectDesc * obj_desc, char *buf, int nbytes); +extern int inv_write(LargeObjectDesc * obj_desc, char *buf, int nbytes); + +#endif /* LARGE_OBJECT_H */ diff --git a/src/include/storage/lmgr.h b/src/include/storage/lmgr.h index 0d65b29ba0b..debe950c7c5 100644 --- a/src/include/storage/lmgr.h +++ b/src/include/storage/lmgr.h @@ -1,75 +1,83 @@ /*------------------------------------------------------------------------- * * lmgr.h-- - * POSTGRES lock manager definitions. + * POSTGRES lock manager definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: lmgr.h,v 1.5 1997/08/19 21:39:54 momjian Exp $ + * $Id: lmgr.h,v 1.6 1997/09/07 05:01:25 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef LMGR_H +#ifndef LMGR_H #define LMGR_H #include <storage/lock.h> #include <utils/rel.h> -/* +/* * This was moved from pladt.h for the new lock manager. Want to obsolete * all of the old code. */ -typedef struct LRelId { - Oid relId; /* a relation identifier */ - Oid dbId; /* a database identifier */ -} LRelId; +typedef struct LRelId +{ + Oid relId; /* a relation identifier */ + Oid dbId; /* a database identifier */ +} LRelId; -typedef struct LockInfoData { - bool initialized; - LRelId lRelId; - TransactionId transactionIdData; - uint16 flags; -} LockInfoData; -typedef LockInfoData *LockInfo; +typedef struct LockInfoData +{ + bool initialized; + LRelId lRelId; + TransactionId transactionIdData; + uint16 flags; +} LockInfoData; +typedef LockInfoData *LockInfo; #define LockInfoIsValid(linfo) \ - ((PointerIsValid(linfo)) && ((LockInfo) linfo)->initialized) + ((PointerIsValid(linfo)) && ((LockInfo) linfo)->initialized) -extern LRelId RelationGetLRelId(Relation relation); -extern Oid LRelIdGetRelationId(LRelId lRelId); -extern void RelationInitLockInfo(Relation relation); -extern void RelationSetLockForDescriptorOpen(Relation relation); -extern void RelationSetLockForRead(Relation relation); -extern void RelationUnsetLockForRead(Relation relation); -extern void RelationSetLockForWrite(Relation relation); -extern void RelationUnsetLockForWrite(Relation relation); +extern LRelId RelationGetLRelId(Relation relation); +extern Oid LRelIdGetRelationId(LRelId lRelId); +extern void RelationInitLockInfo(Relation relation); +extern void RelationSetLockForDescriptorOpen(Relation relation); +extern void RelationSetLockForRead(Relation relation); +extern void RelationUnsetLockForRead(Relation relation); +extern void RelationSetLockForWrite(Relation relation); +extern void RelationUnsetLockForWrite(Relation relation); /* used in vaccum.c */ -extern void RelationSetLockForWritePage(Relation relation, - ItemPointer itemPointer); +extern void +RelationSetLockForWritePage(Relation relation, + ItemPointer itemPointer); /* used in nbtpage.c, hashpage.c */ -extern void RelationSetSingleWLockPage(Relation relation, - ItemPointer itemPointer); -extern void RelationUnsetSingleWLockPage(Relation relation, - ItemPointer itemPointer); -extern void RelationSetSingleRLockPage(Relation relation, - ItemPointer itemPointer); -extern void RelationUnsetSingleRLockPage(Relation relation, - ItemPointer itemPointer); -extern void RelationSetRIntentLock(Relation relation); -extern void RelationUnsetRIntentLock(Relation relation); -extern void RelationSetWIntentLock(Relation relation); -extern void RelationUnsetWIntentLock(Relation relation); +extern void +RelationSetSingleWLockPage(Relation relation, + ItemPointer itemPointer); +extern void +RelationUnsetSingleWLockPage(Relation relation, + ItemPointer itemPointer); +extern void +RelationSetSingleRLockPage(Relation relation, + ItemPointer itemPointer); +extern void +RelationUnsetSingleRLockPage(Relation relation, + ItemPointer itemPointer); +extern void RelationSetRIntentLock(Relation relation); +extern void RelationUnsetRIntentLock(Relation relation); +extern void RelationSetWIntentLock(Relation relation); +extern void RelationUnsetWIntentLock(Relation relation); /* single.c */ -extern bool SingleLockReln(LockInfo linfo, LOCKT lockt, int action); -extern bool SingleLockPage(LockInfo linfo, ItemPointer tidPtr, +extern bool SingleLockReln(LockInfo linfo, LOCKT lockt, int action); +extern bool +SingleLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKT lockt, int action); /* proc.c */ -extern void InitProcGlobal(IPCKey key); +extern void InitProcGlobal(IPCKey key); -#endif /* LMGR_H */ +#endif /* LMGR_H */ diff --git a/src/include/storage/lock.h b/src/include/storage/lock.h index 25b851dac3d..2b0f76649b4 100644 --- a/src/include/storage/lock.h +++ b/src/include/storage/lock.h @@ -1,12 +1,12 @@ /*------------------------------------------------------------------------- * * lock.h-- - * + * * * * Copyright (c) 1994, Regents of the University of California * - * $Id: lock.h,v 1.5 1997/08/19 21:39:55 momjian Exp $ + * $Id: lock.h,v 1.6 1997/09/07 05:01:26 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -17,16 +17,16 @@ #include <storage/itemptr.h> extern SPINLOCK LockMgrLock; -typedef int MASK; +typedef int MASK; -#define INIT_TABLE_SIZE 100 -#define MAX_TABLE_SIZE 1000 +#define INIT_TABLE_SIZE 100 +#define MAX_TABLE_SIZE 1000 /* ---------------------- * The following defines are used to estimate how much shared - * memory the lock manager is going to require. - * + * memory the lock manager is going to require. + * * NBACKENDS - The number of concurrently running backends * NLOCKS_PER_XACT - The number of unique locks acquired in a transaction * NLOCKENTS - The maximum number of lock entries in the lock table. @@ -36,9 +36,9 @@ typedef int MASK; #define NLOCKS_PER_XACT 40 #define NLOCKENTS NLOCKS_PER_XACT*NBACKENDS -typedef int LOCK_TYPE; -typedef int LOCKT; -typedef int LockTableId; +typedef int LOCK_TYPE; +typedef int LOCKT; +typedef int LockTableId; /* MAX_LOCKTYPES cannot be larger than the bits in MASK */ #define MAX_LOCKTYPES 6 @@ -55,53 +55,56 @@ typedef int LockTableId; /*typedef struct LOCK LOCK; */ -typedef struct ltag { - Oid relId; - Oid dbId; - ItemPointerData tupleId; -} LOCKTAG; +typedef struct ltag +{ + Oid relId; + Oid dbId; + ItemPointerData tupleId; +} LOCKTAG; #define TAGSIZE (sizeof(LOCKTAG)) -/* This is the control structure for a lock table. It +/* This is the control structure for a lock table. It * lives in shared memory: * * tableID -- the handle used by the lock table's clients to - * refer to the table. + * refer to the table. * * nLockTypes -- number of lock types (READ,WRITE,etc) that - * are defined on this lock table + * are defined on this lock table * * conflictTab -- this is an array of bitmasks showing lock - * type conflicts. conflictTab[i] is a mask with the j-th bit - * turned on if lock types i and j conflict. + * type conflicts. conflictTab[i] is a mask with the j-th bit + * turned on if lock types i and j conflict. * * prio -- each locktype has a priority, so, for example, waiting - * writers can be given priority over readers (to avoid - * starvation). + * writers can be given priority over readers (to avoid + * starvation). * * masterlock -- synchronizes access to the table * */ -typedef struct lockctl { - LockTableId tableId; - int nLockTypes; - int conflictTab[MAX_LOCKTYPES]; - int prio[MAX_LOCKTYPES]; - SPINLOCK masterLock; -} LOCKCTL; +typedef struct lockctl +{ + LockTableId tableId; + int nLockTypes; + int conflictTab[MAX_LOCKTYPES]; + int prio[MAX_LOCKTYPES]; + SPINLOCK masterLock; +} LOCKCTL; /* * lockHash -- hash table on lock Ids, * xidHash -- hash on xid and lockId in case - * multiple processes are holding the lock + * multiple processes are holding the lock * ctl - control structure described above. */ -typedef struct ltable { - HTAB *lockHash; - HTAB *xidHash; - LOCKCTL *ctl; -} LOCKTAB; +typedef struct ltable +{ + HTAB *lockHash; + HTAB *xidHash; + LOCKCTL *ctl; +} LOCKTAB; /* ----------------------- * A transaction never conflicts with its own locks. Hence, if @@ -132,29 +135,32 @@ typedef struct ltable { * ----------------------- */ -typedef struct XIDTAG { - SHMEM_OFFSET lock; - int pid; - TransactionId xid; -} XIDTAG; +typedef struct XIDTAG +{ + SHMEM_OFFSET lock; + int pid; + TransactionId xid; +} XIDTAG; -typedef struct XIDLookupEnt { - /* tag */ - XIDTAG tag; +typedef struct XIDLookupEnt +{ + /* tag */ + XIDTAG tag; - /* data */ - int holders[MAX_LOCKTYPES]; - int nHolding; - SHM_QUEUE queue; -} XIDLookupEnt; + /* data */ + int holders[MAX_LOCKTYPES]; + int nHolding; + SHM_QUEUE queue; +} XIDLookupEnt; #define XID_TAGSIZE (sizeof(XIDTAG)) /* originally in procq.h */ -typedef struct procQueue { - SHM_QUEUE links; - int size; -} PROC_QUEUE; +typedef struct procQueue +{ + SHM_QUEUE links; + int size; +} PROC_QUEUE; /* @@ -162,24 +168,25 @@ typedef struct procQueue { * * tag -- uniquely identifies the object being locked * mask -- union of the conflict masks of all lock types - * currently held on this object. + * currently held on this object. * waitProcs -- queue of processes waiting for this lock * holders -- count of each lock type currently held on the - * lock. + * lock. * nHolding -- total locks of all types. */ -typedef struct Lock { - /* hash key */ - LOCKTAG tag; - - /* data */ - int mask; - PROC_QUEUE waitProcs; - int holders[MAX_LOCKTYPES]; - int nHolding; - int activeHolders[MAX_LOCKTYPES]; - int nActive; -} LOCK; +typedef struct Lock +{ + /* hash key */ + LOCKTAG tag; + + /* data */ + int mask; + PROC_QUEUE waitProcs; + int holders[MAX_LOCKTYPES]; + int nHolding; + int activeHolders[MAX_LOCKTYPES]; + int nActive; +} LOCK; #define LockGetLock_nHolders(l) l->nHolders @@ -195,21 +202,24 @@ extern SPINLOCK LockMgrLock; /* * function prototypes */ -extern void InitLocks(void); -extern void LockDisable(int status); -extern LockTableId LockTabInit(char *tabName, MASK *conflictsP, int *prioP, - int ntypes); -extern bool LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKT lockt); -extern int LockResolveConflicts(LOCKTAB *ltable, LOCK *lock, LOCKT lockt, - TransactionId xid); -extern bool LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKT lockt); -extern void GrantLock(LOCK *lock, LOCKT lockt); -extern bool LockReleaseAll(LockTableId tableId, SHM_QUEUE *lockQueue); -extern int LockShmemSize(void); -extern bool LockingDisabled(void); +extern void InitLocks(void); +extern void LockDisable(int status); +extern LockTableId +LockTabInit(char *tabName, MASK * conflictsP, int *prioP, + int ntypes); +extern bool LockAcquire(LockTableId tableId, LOCKTAG * lockName, LOCKT lockt); +extern int +LockResolveConflicts(LOCKTAB * ltable, LOCK * lock, LOCKT lockt, + TransactionId xid); +extern bool LockRelease(LockTableId tableId, LOCKTAG * lockName, LOCKT lockt); +extern void GrantLock(LOCK * lock, LOCKT lockt); +extern bool LockReleaseAll(LockTableId tableId, SHM_QUEUE * lockQueue); +extern int LockShmemSize(void); +extern bool LockingDisabled(void); #ifdef DEADLOCK_DEBUG -extern void DumpLocks(void); +extern void DumpLocks(void); + #endif -#endif /* LOCK_H */ +#endif /* LOCK_H */ diff --git a/src/include/storage/multilev.h b/src/include/storage/multilev.h index d077455d872..befc6227ae9 100644 --- a/src/include/storage/multilev.h +++ b/src/include/storage/multilev.h @@ -1,13 +1,13 @@ /*------------------------------------------------------------------------- * * multilev.h-- - * multi level lock table consts/defs for single.c and multi.c and their - * clients + * multi level lock table consts/defs for single.c and multi.c and their + * clients * * * Copyright (c) 1994, Regents of the University of California * - * $Id: multilev.h,v 1.3 1997/08/19 21:39:56 momjian Exp $ + * $Id: multilev.h,v 1.4 1997/09/07 05:01:28 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -16,30 +16,30 @@ #include <storage/lmgr.h> -#define READ_LOCK 2 -#define WRITE_LOCK 1 +#define READ_LOCK 2 +#define WRITE_LOCK 1 -/* any time a small granularity READ/WRITE lock is set. +/* any time a small granularity READ/WRITE lock is set. * Higher granularity READ_INTENT/WRITE_INTENT locks must * also be set. A read intent lock is has value READ+INTENT. * in this implementation. */ -#define NO_LOCK 0 -#define INTENT 2 -#define READ_INTENT (READ_LOCK+INTENT) +#define NO_LOCK 0 +#define INTENT 2 +#define READ_INTENT (READ_LOCK+INTENT) #define WRITE_INTENT (WRITE_LOCK+INTENT) -#define EXTEND_LOCK 5 +#define EXTEND_LOCK 5 -#define SHORT_TERM 1 -#define LONG_TERM 2 -#define UNLOCK 0 +#define SHORT_TERM 1 +#define LONG_TERM 2 +#define UNLOCK 0 #define N_LEVELS 3 #define RELN_LEVEL 0 #define PAGE_LEVEL 1 #define TUPLE_LEVEL 2 -typedef int LOCK_LEVEL; +typedef int LOCK_LEVEL; /* multi.c */ @@ -50,9 +50,9 @@ extern LockTableId ShortTermTableId; * function prototypes */ extern LockTableId InitMultiLevelLockm(void); -extern bool MultiLockReln(LockInfo linfo, LOCKT lockt); -extern bool MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKT lockt); -extern bool MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKT lockt); -extern bool MultiReleaseReln(LockInfo linfo, LOCKT lockt); +extern bool MultiLockReln(LockInfo linfo, LOCKT lockt); +extern bool MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKT lockt); +extern bool MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKT lockt); +extern bool MultiReleaseReln(LockInfo linfo, LOCKT lockt); -#endif /* MULTILEV_H */ +#endif /* MULTILEV_H */ diff --git a/src/include/storage/off.h b/src/include/storage/off.h index 759b30278a3..3eadb842a78 100644 --- a/src/include/storage/off.h +++ b/src/include/storage/off.h @@ -1,16 +1,16 @@ /*------------------------------------------------------------------------- * * off.h-- - * POSTGRES disk "offset" definitions. + * POSTGRES disk "offset" definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: off.h,v 1.2 1996/10/31 09:49:58 scrappy Exp $ + * $Id: off.h,v 1.3 1997/09/07 05:01:29 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef OFF_H +#ifndef OFF_H #define OFF_H /* @@ -19,38 +19,38 @@ * this is a 1-based index into the linp (ItemIdData) array in the * header of each disk page. */ -typedef uint16 OffsetNumber; +typedef uint16 OffsetNumber; -#define InvalidOffsetNumber ((OffsetNumber) 0) -#define FirstOffsetNumber ((OffsetNumber) 1) -#define MaxOffsetNumber ((OffsetNumber) (BLCKSZ / sizeof(ItemIdData))) -#define OffsetNumberMask (0xffff) /* valid uint16 bits */ +#define InvalidOffsetNumber ((OffsetNumber) 0) +#define FirstOffsetNumber ((OffsetNumber) 1) +#define MaxOffsetNumber ((OffsetNumber) (BLCKSZ / sizeof(ItemIdData))) +#define OffsetNumberMask (0xffff) /* valid uint16 bits */ /* ---------------- - * support macros + * support macros * ---------------- */ /* * OffsetNumberIsValid -- - * True iff the offset number is valid. + * True iff the offset number is valid. */ #define OffsetNumberIsValid(offsetNumber) \ - ((bool) ((offsetNumber != InvalidOffsetNumber) && \ - (offsetNumber <= MaxOffsetNumber))) + ((bool) ((offsetNumber != InvalidOffsetNumber) && \ + (offsetNumber <= MaxOffsetNumber))) /* * OffsetNumberNext -- * OffsetNumberPrev -- - * Increments/decrements the argument. These macros look pointless - * but they help us disambiguate the different manipulations on - * OffsetNumbers (e.g., sometimes we substract one from an - * OffsetNumber to move back, and sometimes we do so to form a - * real C array index). + * Increments/decrements the argument. These macros look pointless + * but they help us disambiguate the different manipulations on + * OffsetNumbers (e.g., sometimes we substract one from an + * OffsetNumber to move back, and sometimes we do so to form a + * real C array index). */ #define OffsetNumberNext(offsetNumber) \ - ((OffsetNumber) (1 + (offsetNumber))) + ((OffsetNumber) (1 + (offsetNumber))) #define OffsetNumberPrev(offsetNumber) \ - ((OffsetNumber) (-1 + (offsetNumber))) + ((OffsetNumber) (-1 + (offsetNumber))) -#endif /* OFF_H */ +#endif /* OFF_H */ diff --git a/src/include/storage/page.h b/src/include/storage/page.h index f2f6c1fcba5..17d29746c9c 100644 --- a/src/include/storage/page.h +++ b/src/include/storage/page.h @@ -1,24 +1,24 @@ /*------------------------------------------------------------------------- * * page.h-- - * POSTGRES buffer page abstraction definitions. + * POSTGRES buffer page abstraction definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: page.h,v 1.2 1996/10/31 09:49:59 scrappy Exp $ + * $Id: page.h,v 1.3 1997/09/07 05:01:30 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef PAGE_H +#ifndef PAGE_H #define PAGE_H -typedef Pointer Page; +typedef Pointer Page; /* * PageIsValid -- - * True iff page is valid. + * True iff page is valid. */ -#define PageIsValid(page) PointerIsValid(page) +#define PageIsValid(page) PointerIsValid(page) -#endif /* PAGE_H */ +#endif /* PAGE_H */ diff --git a/src/include/storage/pagenum.h b/src/include/storage/pagenum.h index 1e4ff7b2120..edd0dc116be 100644 --- a/src/include/storage/pagenum.h +++ b/src/include/storage/pagenum.h @@ -1,16 +1,16 @@ /*------------------------------------------------------------------------- * * pagenum.h-- - * POSTGRES page number definitions. + * POSTGRES page number definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: pagenum.h,v 1.3 1996/11/05 06:11:02 scrappy Exp $ + * $Id: pagenum.h,v 1.4 1997/09/07 05:01:32 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef PAGENUM_H +#ifndef PAGENUM_H #define PAGENUM_H @@ -18,14 +18,14 @@ typedef uint16 PageNumber; typedef uint32 LogicalPageNumber; -#define InvalidLogicalPageNumber 0 +#define InvalidLogicalPageNumber 0 /* * LogicalPageNumberIsValid -- - * True iff the logical page number is valid. + * True iff the logical page number is valid. */ #define LogicalPageNumberIsValid(pageNumber) \ - ((bool)((pageNumber) != InvalidLogicalPageNumber)) + ((bool)((pageNumber) != InvalidLogicalPageNumber)) -#endif /* PAGENUM_H */ +#endif /* PAGENUM_H */ diff --git a/src/include/storage/pos.h b/src/include/storage/pos.h index b08faa481fd..c5611ba0c12 100644 --- a/src/include/storage/pos.h +++ b/src/include/storage/pos.h @@ -1,16 +1,16 @@ /*------------------------------------------------------------------------- * * pos.h-- - * POSTGRES "position" definitions. + * POSTGRES "position" definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: pos.h,v 1.2 1996/10/31 09:50:04 scrappy Exp $ + * $Id: pos.h,v 1.3 1997/09/07 05:01:33 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef POS_H +#ifndef POS_H #define POS_H /* @@ -18,45 +18,45 @@ * been changed to just <offset> as the notion of having multiple pages * within a block has been removed. * - * the 'offset' abstraction is somewhat confusing. it is NOT a byte + * the 'offset' abstraction is somewhat confusing. it is NOT a byte * offset within the page; instead, it is an offset into the line * pointer array contained on every page that store (heap or index) * tuples. */ -typedef bits16 PositionIdData; -typedef PositionIdData *PositionId; +typedef bits16 PositionIdData; +typedef PositionIdData *PositionId; /* ---------------- - * support macros + * support macros * ---------------- */ /* * PositionIdIsValid -- - * True iff the position identifier is valid. + * True iff the position identifier is valid. */ #define PositionIdIsValid(positionId) \ - PointerIsValid(positionId) + PointerIsValid(positionId) /* * PositionIdSetInvalid -- - * Make an invalid position. + * Make an invalid position. */ #define PositionIdSetInvalid(positionId) \ - *(positionId) = (bits16) 0 + *(positionId) = (bits16) 0 /* * PositionIdSet -- - * Sets a position identifier to the specified value. + * Sets a position identifier to the specified value. */ #define PositionIdSet(positionId, offsetNumber) \ - *(positionId) = (offsetNumber) + *(positionId) = (offsetNumber) /* * PositionIdGetOffsetNumber -- - * Retrieve the offset number from a position identifier. + * Retrieve the offset number from a position identifier. */ #define PositionIdGetOffsetNumber(positionId) \ - ((OffsetNumber) *(positionId)) + ((OffsetNumber) *(positionId)) -#endif /* POS_H */ +#endif /* POS_H */ diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 4e0b9b27806..92829732714 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -1,12 +1,12 @@ /*------------------------------------------------------------------------- * * proc.h-- - * + * * * * Copyright (c) 1994, Regents of the University of California * - * $Id: proc.h,v 1.5 1997/08/19 21:39:58 momjian Exp $ + * $Id: proc.h,v 1.6 1997/09/07 05:01:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -15,46 +15,46 @@ #include <storage/lock.h> -typedef struct { - int sleeplock; - int semNum; - IpcSemaphoreId semId; - IpcSemaphoreKey semKey; -} SEMA; +typedef struct +{ + int sleeplock; + int semNum; + IpcSemaphoreId semId; + IpcSemaphoreKey semKey; +} SEMA; /* * Each backend has: */ -typedef struct proc { +typedef struct proc +{ - /* proc->links MUST BE THE FIRST ELEMENT OF STRUCT (see ProcWakeup()) */ + /* proc->links MUST BE THE FIRST ELEMENT OF STRUCT (see ProcWakeup()) */ - SHM_QUEUE links; /* proc can be waiting for one event(lock) */ - SEMA sem; /* ONE semaphore to sleep on */ - int errType; /* error code tells why we woke up */ + SHM_QUEUE links; /* proc can be waiting for one event(lock) */ + SEMA sem; /* ONE semaphore to sleep on */ + int errType; /* error code tells why we woke up */ - int procId; /* unique number for this structure - * NOT unique per backend, these things - * are reused after the backend dies. - */ + int procId; /* unique number for this structure NOT + * unique per backend, these things are + * reused after the backend dies. */ - int critSects; /* If critSects > 0, we are in sensitive - * routines that cannot be recovered when - * the process fails. - */ + int critSects; /* If critSects > 0, we are in sensitive + * routines that cannot be recovered when + * the process fails. */ - int prio; /* priority for sleep queue */ + int prio; /* priority for sleep queue */ - TransactionId xid; /* transaction currently being executed - * by this proc - */ + TransactionId xid; /* transaction currently being executed by + * this proc */ - LOCK * waitLock; /* Lock we're sleeping on */ - int token; /* info for proc wakeup routines */ - int pid; /* This procs process id */ - short sLocks[MAX_SPINS]; /* Spin lock stats */ - SHM_QUEUE lockQueue; /* locks associated with current transaction */ -} PROC; + LOCK *waitLock; /* Lock we're sleeping on */ + int token; /* info for proc wakeup routines */ + int pid; /* This procs process id */ + short sLocks[MAX_SPINS]; /* Spin lock stats */ + SHM_QUEUE lockQueue; /* locks associated with current + * transaction */ +} PROC; /* @@ -63,17 +63,18 @@ typedef struct proc { * of semaphores in each (sys-V) semaphore set allocated. (Be careful not * to set it to greater 32. Otherwise, the bitmap will overflow.) */ -#define MAX_PROC_SEMS 128 -#define PROC_NSEMS_PER_SET 16 +#define MAX_PROC_SEMS 128 +#define PROC_NSEMS_PER_SET 16 -typedef struct procglobal { - SHMEM_OFFSET freeProcs; - int numProcs; - IPCKey currKey; - int32 freeSemMap[MAX_PROC_SEMS/PROC_NSEMS_PER_SET]; -} PROC_HDR; +typedef struct procglobal +{ + SHMEM_OFFSET freeProcs; + int numProcs; + IPCKey currKey; + int32 freeSemMap[MAX_PROC_SEMS / PROC_NSEMS_PER_SET]; +} PROC_HDR; -extern PROC *MyProc; +extern PROC *MyProc; #define PROC_INCR_SLOCK(lock) if (MyProc) (MyProc->sLocks[(lock)])++ #define PROC_DECR_SLOCK(lock) if (MyProc) (MyProc->sLocks[(lock)])-- @@ -81,30 +82,32 @@ extern PROC *MyProc; /* * flags explaining why process woke up */ -#define NO_ERROR 0 -#define ERR_TIMEOUT 1 +#define NO_ERROR 0 +#define ERR_TIMEOUT 1 #define ERR_BUFFER_IO 2 -#define MAX_PRIO 50 -#define MIN_PRIO (-1) +#define MAX_PRIO 50 +#define MIN_PRIO (-1) extern SPINLOCK ProcStructLock; /* * Function Prototypes */ -extern void InitProcess(IPCKey key); -extern void ProcReleaseLocks(void); -extern bool ProcRemove(int pid); +extern void InitProcess(IPCKey key); +extern void ProcReleaseLocks(void); +extern bool ProcRemove(int pid); + /* extern bool ProcKill(int exitStatus, int pid); */ /* make static in storage/lmgr/proc.c -- jolly */ -extern void ProcQueueInit(PROC_QUEUE *queue); -extern int ProcSleep(PROC_QUEUE *queue, SPINLOCK spinlock, int token, - int prio, LOCK *lock); -extern int ProcLockWakeup(PROC_QUEUE *queue, char * ltable, char * lock); -extern void ProcAddLock(SHM_QUEUE *elem); -extern void ProcReleaseSpins(PROC *proc); -extern void ProcFreeAllSemaphores(void); +extern void ProcQueueInit(PROC_QUEUE * queue); +extern int +ProcSleep(PROC_QUEUE * queue, SPINLOCK spinlock, int token, + int prio, LOCK * lock); +extern int ProcLockWakeup(PROC_QUEUE * queue, char *ltable, char *lock); +extern void ProcAddLock(SHM_QUEUE * elem); +extern void ProcReleaseSpins(PROC * proc); +extern void ProcFreeAllSemaphores(void); -#endif /* PROC_H */ +#endif /* PROC_H */ diff --git a/src/include/storage/shmem.h b/src/include/storage/shmem.h index fb52742d362..5812a718717 100644 --- a/src/include/storage/shmem.h +++ b/src/include/storage/shmem.h @@ -1,16 +1,16 @@ /*------------------------------------------------------------------------- * * shmem.h-- - * shared memory management structures + * shared memory management structures * * * Copyright (c) 1994, Regents of the University of California * - * $Id: shmem.h,v 1.5 1997/08/19 21:40:01 momjian Exp $ + * $Id: shmem.h,v 1.6 1997/09/07 05:01:35 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef SHMEM_H +#ifndef SHMEM_H #define SHMEM_H #include <utils/hsearch.h> @@ -22,11 +22,12 @@ * offsets relative to the start of the shared memory region(s). */ typedef unsigned long SHMEM_OFFSET; + #define INVALID_OFFSET (-1) #define BAD_LOCATION (-1) /* start of the lowest shared memory region. For now, assume that - * there is only one shared memory region + * there is only one shared memory region */ extern SHMEM_OFFSET ShmemBase; @@ -51,54 +52,57 @@ extern SPINLOCK ShmemLock; extern SPINLOCK BindingLock; /* shmemqueue.c */ -typedef struct SHM_QUEUE { - SHMEM_OFFSET prev; - SHMEM_OFFSET next; -} SHM_QUEUE; +typedef struct SHM_QUEUE +{ + SHMEM_OFFSET prev; + SHMEM_OFFSET next; +} SHM_QUEUE; /* shmem.c */ -extern void ShmemBindingTabReset(void); -extern void ShmemCreate(unsigned int key, unsigned int size); -extern int InitShmem(unsigned int key, unsigned int size); -extern long *ShmemAlloc(unsigned long size); -extern int ShmemIsValid(unsigned long addr); -extern HTAB *ShmemInitHash(char *name, long init_size, long max_size, - HASHCTL *infoP, int hash_flags); -extern bool ShmemPIDLookup(int pid, SHMEM_OFFSET* locationPtr); +extern void ShmemBindingTabReset(void); +extern void ShmemCreate(unsigned int key, unsigned int size); +extern int InitShmem(unsigned int key, unsigned int size); +extern long *ShmemAlloc(unsigned long size); +extern int ShmemIsValid(unsigned long addr); +extern HTAB * +ShmemInitHash(char *name, long init_size, long max_size, + HASHCTL * infoP, int hash_flags); +extern bool ShmemPIDLookup(int pid, SHMEM_OFFSET * locationPtr); extern SHMEM_OFFSET ShmemPIDDestroy(int pid); -extern long *ShmemInitStruct(char *name, unsigned long size, - bool *foundPtr); -extern bool TransactionIdIsInProgress (TransactionId xid); +extern long * +ShmemInitStruct(char *name, unsigned long size, + bool * foundPtr); +extern bool TransactionIdIsInProgress(TransactionId xid); -typedef int TableID; +typedef int TableID; /* size constants for the binding table */ - /* max size of data structure string name */ -#define BTABLE_KEYSIZE (50) - /* data in binding table hash bucket */ + /* max size of data structure string name */ +#define BTABLE_KEYSIZE (50) + /* data in binding table hash bucket */ #define BTABLE_DATASIZE (sizeof(BindingEnt) - BTABLE_KEYSIZE) - /* maximum size of the binding table */ -#define BTABLE_SIZE (100) + /* maximum size of the binding table */ +#define BTABLE_SIZE (100) /* this is a hash bucket in the binding table */ -typedef struct { - char key[BTABLE_KEYSIZE]; /* string name */ - unsigned long location; /* location in shared mem */ - unsigned long size; /* numbytes allocated for the - * structure - */ -} BindingEnt; +typedef struct +{ + char key[BTABLE_KEYSIZE]; /* string name */ + unsigned long location; /* location in shared mem */ + unsigned long size; /* numbytes allocated for the structure */ +} BindingEnt; /* * prototypes for functions in shmqueue.c */ -extern void SHMQueueInit(SHM_QUEUE *queue); -extern void SHMQueueElemInit(SHM_QUEUE *queue); -extern void SHMQueueDelete(SHM_QUEUE *queue); -extern void SHMQueueInsertTL(SHM_QUEUE *queue, SHM_QUEUE *elem); -extern void SHMQueueFirst(SHM_QUEUE *queue, Pointer *nextPtrPtr, - SHM_QUEUE *nextQueue); -extern bool SHMQueueEmpty(SHM_QUEUE *queue); - -#endif /* SHMEM_H */ +extern void SHMQueueInit(SHM_QUEUE * queue); +extern void SHMQueueElemInit(SHM_QUEUE * queue); +extern void SHMQueueDelete(SHM_QUEUE * queue); +extern void SHMQueueInsertTL(SHM_QUEUE * queue, SHM_QUEUE * elem); +extern void +SHMQueueFirst(SHM_QUEUE * queue, Pointer * nextPtrPtr, + SHM_QUEUE * nextQueue); +extern bool SHMQueueEmpty(SHM_QUEUE * queue); + +#endif /* SHMEM_H */ diff --git a/src/include/storage/sinval.h b/src/include/storage/sinval.h index 87f8e00ba6e..fd9025e875f 100644 --- a/src/include/storage/sinval.h +++ b/src/include/storage/sinval.h @@ -1,16 +1,16 @@ /*------------------------------------------------------------------------- * * sinval.h-- - * POSTGRES shared cache invalidation communication definitions. + * POSTGRES shared cache invalidation communication definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: sinval.h,v 1.4 1996/11/10 03:06:00 momjian Exp $ + * $Id: sinval.h,v 1.5 1997/09/07 05:01:36 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef SINVAL_H +#ifndef SINVAL_H #define SINVAL_H #include <storage/itemptr.h> @@ -18,13 +18,14 @@ extern SPINLOCK SInvalLock; -extern void CreateSharedInvalidationState(IPCKey key); -extern void AttachSharedInvalidationState(IPCKey key); -extern void InitSharedInvalidationState(void); -extern void RegisterSharedInvalid(int cacheId, Index hashIndex, - ItemPointer pointer); -extern void InvalidateSharedInvalid(void (*invalFunction)(), - void (*resetFunction)()); +extern void CreateSharedInvalidationState(IPCKey key); +extern void AttachSharedInvalidationState(IPCKey key); +extern void InitSharedInvalidationState(void); +extern void +RegisterSharedInvalid(int cacheId, Index hashIndex, + ItemPointer pointer); +extern void InvalidateSharedInvalid(void (*invalFunction) (), + void (*resetFunction) ()); -#endif /* SINVAL_H */ +#endif /* SINVAL_H */ diff --git a/src/include/storage/sinvaladt.h b/src/include/storage/sinvaladt.h index 9735cb476b1..12efeb2c8b8 100644 --- a/src/include/storage/sinvaladt.h +++ b/src/include/storage/sinvaladt.h @@ -1,12 +1,12 @@ /*------------------------------------------------------------------------- * * sinvaladt.h-- - * POSTGRES shared cache invalidation segment definitions. + * POSTGRES shared cache invalidation segment definitions. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: sinvaladt.h,v 1.3 1996/11/05 06:11:06 scrappy Exp $ + * $Id: sinvaladt.h,v 1.4 1997/09/07 05:01:37 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -15,109 +15,119 @@ #include <storage/itemptr.h> #include <storage/ipc.h> - + /* * The structure of the shared cache invaidation segment * */ /* A------------- Header info -------------- - criticalSectionSemaphoreId - generalSemaphoreId - startEntrySection (offset a) - endEntrySection (offset a + b) - startFreeSpace (offset relative to B) - startEntryChain (offset relatiev to B) - endEntryChain (offset relative to B) - numEntries - maxNumEntries - procState[MaxBackendId] --> limit - resetState (bool) -a tag (POSTID) + criticalSectionSemaphoreId + generalSemaphoreId + startEntrySection (offset a) + endEntrySection (offset a + b) + startFreeSpace (offset relative to B) + startEntryChain (offset relatiev to B) + endEntryChain (offset relative to B) + numEntries + maxNumEntries + procState[MaxBackendId] --> limit + resetState (bool) +a tag (POSTID) B------------- Start entry section ------- - SISegEntry --> entryData --> ... (see SharedInvalidData!) - isfree (bool) - next (offset to next entry in chain ) -b .... (dynamically growing down) -C----------------End shared segment ------- + SISegEntry --> entryData --> ... (see SharedInvalidData!) + isfree (bool) + next (offset to next entry in chain ) +b .... (dynamically growing down) +C----------------End shared segment ------- */ /* Parameters (configurable) *******************************************/ -#define MaxBackendId 32 /* maximum number of backends */ -#define MAXNUMMESSAGES 1000 /* maximum number of messages in seg*/ - - -#define InvalidOffset 1000000000 /* a invalid offset (End of chain) */ - -typedef struct ProcState { - int limit; /* the number of read messages */ - bool resetState; /* true, if backend has to reset its state */ - int tag; /* special tag, recieved from the postmaster */ -} ProcState; - - -typedef struct SISeg { - IpcSemaphoreId criticalSectionSemaphoreId; /* semaphore id */ - IpcSemaphoreId generalSemaphoreId; /* semaphore id */ - Offset startEntrySection; /* (offset a) */ - Offset endEntrySection; /* (offset a + b) */ - Offset startFreeSpace; /* (offset relative to B) */ - Offset startEntryChain; /* (offset relative to B) */ - Offset endEntryChain; /* (offset relative to B) */ - int numEntries; - int maxNumEntries; - ProcState procState[MaxBackendId]; /* reflects the invalidation state */ - /* here starts the entry section, controlled by offsets */ -} SISeg; -#define SizeSISeg sizeof(SISeg) - -typedef struct SharedInvalidData { - int cacheId; /* XXX */ - Index hashIndex; - ItemPointerData pointerData; -} SharedInvalidData; - -typedef SharedInvalidData *SharedInvalid; - - -typedef struct SISegEntry { - SharedInvalidData entryData; /* the message data */ - bool isfree; /* entry free? */ - Offset next; /* offset to next entry*/ -} SISegEntry; +#define MaxBackendId 32 /* maximum number of backends */ +#define MAXNUMMESSAGES 1000 /* maximum number of messages in seg */ + + +#define InvalidOffset 1000000000 /* a invalid offset (End of + * chain) */ + +typedef struct ProcState +{ + int limit; /* the number of read messages */ + bool resetState; /* true, if backend has to reset its state */ + int tag; /* special tag, recieved from the + * postmaster */ +} ProcState; + + +typedef struct SISeg +{ + IpcSemaphoreId criticalSectionSemaphoreId; /* semaphore id */ + IpcSemaphoreId generalSemaphoreId; /* semaphore id */ + Offset startEntrySection; /* (offset a) */ + Offset endEntrySection; /* (offset a + b) */ + Offset startFreeSpace; /* (offset relative to B) */ + Offset startEntryChain; /* (offset relative to B) */ + Offset endEntryChain; /* (offset relative to B) */ + int numEntries; + int maxNumEntries; + ProcState procState[MaxBackendId]; /* reflects the + * invalidation state */ + /* here starts the entry section, controlled by offsets */ +} SISeg; + +#define SizeSISeg sizeof(SISeg) + +typedef struct SharedInvalidData +{ + int cacheId; /* XXX */ + Index hashIndex; + ItemPointerData pointerData; +} SharedInvalidData; + +typedef SharedInvalidData *SharedInvalid; + + +typedef struct SISegEntry +{ + SharedInvalidData entryData;/* the message data */ + bool isfree; /* entry free? */ + Offset next; /* offset to next entry */ +} SISegEntry; #define SizeOfOneSISegEntry sizeof(SISegEntry) - -typedef struct SISegOffsets { - Offset startSegment; /* always 0 (for now) */ - Offset offsetToFirstEntry; /* A + a = B */ - Offset offsetToEndOfSegemnt; /* A + a + b */ -} SISegOffsets; + +typedef struct SISegOffsets +{ + Offset startSegment; /* always 0 (for now) */ + Offset offsetToFirstEntry; /* A + a = B */ + Offset offsetToEndOfSegemnt; /* A + a + b */ +} SISegOffsets; /****************************************************************************/ -/* synchronization of the shared buffer access */ -/* access to the buffer is synchronized by the lock manager !! */ +/* synchronization of the shared buffer access */ +/* access to the buffer is synchronized by the lock manager !! */ /****************************************************************************/ #define SI_LockStartValue 255 -#define SI_SharedLock (-1) +#define SI_SharedLock (-1) #define SI_ExclusiveLock (-255) -extern SISeg *shmInvalBuffer; +extern SISeg *shmInvalBuffer; /* * prototypes for functions in sinvaladt.c */ -extern int SIBackendInit(SISeg *segInOutP); -extern int SISegmentInit(bool killExistingSegment, IPCKey key); - -extern bool SISetDataEntry(SISeg *segP, SharedInvalidData *data); -extern void SISetProcStateInvalid(SISeg *segP); -extern bool SIDelDataEntry(SISeg *segP); -extern void SIReadEntryData(SISeg *segP, int backendId, - void (*invalFunction)(), void (*resetFunction)()); -extern void SIDelExpiredDataEntries(SISeg *segP); - -#endif /* SINVALADT_H */ +extern int SIBackendInit(SISeg * segInOutP); +extern int SISegmentInit(bool killExistingSegment, IPCKey key); + +extern bool SISetDataEntry(SISeg * segP, SharedInvalidData * data); +extern void SISetProcStateInvalid(SISeg * segP); +extern bool SIDelDataEntry(SISeg * segP); +extern void +SIReadEntryData(SISeg * segP, int backendId, + void (*invalFunction) (), void (*resetFunction) ()); +extern void SIDelExpiredDataEntries(SISeg * segP); + +#endif /* SINVALADT_H */ diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h index 32f4be36357..38c2164f891 100644 --- a/src/include/storage/smgr.h +++ b/src/include/storage/smgr.h @@ -1,12 +1,12 @@ /*------------------------------------------------------------------------- * * smgr.h-- - * storage manager switch public interface declarations. + * storage manager switch public interface declarations. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: smgr.h,v 1.7 1997/08/19 21:40:03 momjian Exp $ + * $Id: smgr.h,v 1.8 1997/09/07 05:01:38 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -17,75 +17,81 @@ #include <storage/block.h> #include <utils/rel.h> -#define SM_FAIL 0 -#define SM_SUCCESS 1 +#define SM_FAIL 0 +#define SM_SUCCESS 1 -#define DEFAULT_SMGR 0 +#define DEFAULT_SMGR 0 -extern int smgrinit(void); -extern int smgrcreate(int16 which, Relation reln); -extern int smgrunlink(int16 which, Relation reln); -extern int smgrextend(int16 which, Relation reln, char *buffer); -extern int smgropen(int16 which, Relation reln); -extern int smgrclose(int16 which, Relation reln); -extern int smgrread(int16 which, Relation reln, BlockNumber blocknum, - char *buffer); -extern int smgrwrite(int16 which, Relation reln, BlockNumber blocknum, - char *buffer); -extern int smgrflush(int16 which, Relation reln, BlockNumber blocknum, - char *buffer); -extern int smgrblindwrt(int16 which, char *dbname, char *relname, Oid dbid, - Oid relid, BlockNumber blkno, char *buffer); -extern int smgrnblocks(int16 which, Relation reln); -extern int smgrtruncate(int16 which, Relation reln, int nblocks); -extern int smgrcommit(void); -extern bool smgriswo(int16 smgrno); +extern int smgrinit(void); +extern int smgrcreate(int16 which, Relation reln); +extern int smgrunlink(int16 which, Relation reln); +extern int smgrextend(int16 which, Relation reln, char *buffer); +extern int smgropen(int16 which, Relation reln); +extern int smgrclose(int16 which, Relation reln); +extern int +smgrread(int16 which, Relation reln, BlockNumber blocknum, + char *buffer); +extern int +smgrwrite(int16 which, Relation reln, BlockNumber blocknum, + char *buffer); +extern int +smgrflush(int16 which, Relation reln, BlockNumber blocknum, + char *buffer); +extern int +smgrblindwrt(int16 which, char *dbname, char *relname, Oid dbid, + Oid relid, BlockNumber blkno, char *buffer); +extern int smgrnblocks(int16 which, Relation reln); +extern int smgrtruncate(int16 which, Relation reln, int nblocks); +extern int smgrcommit(void); +extern bool smgriswo(int16 smgrno); /* internals: move me elsewhere -- ay 7/94 */ /* in md.c */ -extern int mdinit(void); -extern int mdcreate(Relation reln); -extern int mdunlink(Relation reln); -extern int mdextend(Relation reln, char *buffer); -extern int mdopen(Relation reln); -extern int mdclose(Relation reln); -extern int mdread(Relation reln, BlockNumber blocknum, char *buffer); -extern int mdwrite(Relation reln, BlockNumber blocknum, char *buffer); -extern int mdflush(Relation reln, BlockNumber blocknum, char *buffer); -extern int mdblindwrt(char *dbstr, char *relstr, Oid dbid, Oid relid, - BlockNumber blkno, char *buffer); -extern int mdnblocks(Relation reln); -extern int mdtruncate(Relation reln, int nblocks); -extern int mdcommit(void); -extern int mdabort(void); +extern int mdinit(void); +extern int mdcreate(Relation reln); +extern int mdunlink(Relation reln); +extern int mdextend(Relation reln, char *buffer); +extern int mdopen(Relation reln); +extern int mdclose(Relation reln); +extern int mdread(Relation reln, BlockNumber blocknum, char *buffer); +extern int mdwrite(Relation reln, BlockNumber blocknum, char *buffer); +extern int mdflush(Relation reln, BlockNumber blocknum, char *buffer); +extern int +mdblindwrt(char *dbstr, char *relstr, Oid dbid, Oid relid, + BlockNumber blkno, char *buffer); +extern int mdnblocks(Relation reln); +extern int mdtruncate(Relation reln, int nblocks); +extern int mdcommit(void); +extern int mdabort(void); /* mm.c */ extern SPINLOCK MMCacheLock; -extern int mminit(void); -extern int mmshutdown(void); -extern int mmcreate(Relation reln); -extern int mmunlink(Relation reln); -extern int mmextend(Relation reln, char *buffer); -extern int mmopen(Relation reln); -extern int mmclose(Relation reln); -extern int mmread(Relation reln, BlockNumber blocknum, char *buffer); -extern int mmwrite(Relation reln, BlockNumber blocknum, char *buffer); -extern int mmflush(Relation reln, BlockNumber blocknum, char *buffer); -extern int mmblindwrt(char *dbstr, char *relstr, Oid dbid, Oid relid, - BlockNumber blkno, char *buffer); -extern int mmnblocks(Relation reln); -extern int mmcommit(void); -extern int mmabort(void); -extern int MMShmemSize(void); +extern int mminit(void); +extern int mmshutdown(void); +extern int mmcreate(Relation reln); +extern int mmunlink(Relation reln); +extern int mmextend(Relation reln, char *buffer); +extern int mmopen(Relation reln); +extern int mmclose(Relation reln); +extern int mmread(Relation reln, BlockNumber blocknum, char *buffer); +extern int mmwrite(Relation reln, BlockNumber blocknum, char *buffer); +extern int mmflush(Relation reln, BlockNumber blocknum, char *buffer); +extern int +mmblindwrt(char *dbstr, char *relstr, Oid dbid, Oid relid, + BlockNumber blkno, char *buffer); +extern int mmnblocks(Relation reln); +extern int mmcommit(void); +extern int mmabort(void); +extern int MMShmemSize(void); /* smgrtype.c */ -extern char *smgrout(int2 i); -extern int2 smgrin(char *s); -extern bool smgreq(int2 a, int2 b); -extern bool smgrne(int2 a, int2 b); +extern char *smgrout(int2 i); +extern int2 smgrin(char *s); +extern bool smgreq(int2 a, int2 b); +extern bool smgrne(int2 a, int2 b); -#endif /* SMGR_H */ +#endif /* SMGR_H */ diff --git a/src/include/storage/spin.h b/src/include/storage/spin.h index 0000af883b1..0ee24b5ab4b 100644 --- a/src/include/storage/spin.h +++ b/src/include/storage/spin.h @@ -1,21 +1,21 @@ /*------------------------------------------------------------------------- * * spin.h-- - * synchronization routines + * synchronization routines * * * Copyright (c) 1994, Regents of the University of California * - * $Id: spin.h,v 1.3 1997/08/19 21:40:03 momjian Exp $ + * $Id: spin.h,v 1.4 1997/09/07 05:01:39 momjian Exp $ * *------------------------------------------------------------------------- */ -#ifndef SPIN_H +#ifndef SPIN_H #define SPIN_H #include <storage/ipc.h> -/* +/* * two implementations of spin locks * * sequent, sparc, sun3: real spin locks. uses a TAS instruction; see @@ -25,11 +25,11 @@ * */ -typedef int SPINLOCK; +typedef int SPINLOCK; -extern bool CreateSpinlocks(IPCKey key); -extern bool InitSpinLocks(int init, IPCKey key); -extern void SpinAcquire(SPINLOCK lock); -extern void SpinRelease(SPINLOCK lock); +extern bool CreateSpinlocks(IPCKey key); +extern bool InitSpinLocks(int init, IPCKey key); +extern void SpinAcquire(SPINLOCK lock); +extern void SpinRelease(SPINLOCK lock); -#endif /* SPIN_H */ +#endif /* SPIN_H */ |