]> granicus.if.org Git - postgresql/blobdiff - src/include/storage/shmem.h
Update copyright for 2009.
[postgresql] / src / include / storage / shmem.h
index c2563509bef141c5df6ec9a6d5430382046ad83d..ad9f21582e2092abc5fee20535fe53c84e5c8145 100644 (file)
 /*-------------------------------------------------------------------------
  *
- * shmem.h--
- *    shared memory management structures
+ * shmem.h
+ *       shared memory management structures
  *
+ * Historical note:
+ * A long time ago, Postgres' shared memory region was allowed to be mapped
+ * at a different address in each process, and shared memory "pointers" were
+ * passed around as offsets relative to the start of the shared memory region.
+ * That is no longer the case: each process must map the shared memory region
+ * at the same address.  This means shared memory pointers can be passed
+ * around directly between different processes.
  *
- * Copyright (c) 1994, Regents of the University of California
+ * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: shmem.h,v 1.3 1996/11/10 03:05:56 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/storage/shmem.h,v 1.55 2009/01/01 17:24:01 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
-#ifndef        SHMEM_H
+#ifndef SHMEM_H
 #define SHMEM_H
 
-#include <utils/hsearch.h>
-#include <storage/spin.h>
+#include "utils/hsearch.h"
 
 
-/* The shared memory region can start at a different address
- * in every process.  Shared memory "pointers" are actually
- * 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 
- */
-extern SHMEM_OFFSET ShmemBase;
-
-
-/* coerce an offset into a pointer in this process's address space */
-#define MAKE_PTR(xx_offs)\
-  (ShmemBase+((unsigned long)(xx_offs)))
-
-/* coerce a pointer into a shmem offset */
-#define MAKE_OFFSET(xx_ptr)\
-  (SHMEM_OFFSET) (((unsigned long)(xx_ptr))-ShmemBase)
-
-#define SHM_PTR_VALID(xx_ptr)\
-  (((unsigned long)xx_ptr) > ShmemBase)
-
-/* cannot have an offset to ShmemFreeStart (offset 0) */
-#define SHM_OFFSET_VALID(xx_offs)\
-  ((xx_offs != 0) && (xx_offs != INVALID_OFFSET))
-
-
-extern SPINLOCK ShmemLock;
-extern SPINLOCK BindingLock;
-
-/* shmemqueue.c */
-typedef struct SHM_QUEUE {
-    SHMEM_OFFSET       prev;
-    SHMEM_OFFSET       next;
+/* shmqueue.c */
+typedef struct SHM_QUEUE
+{
+       struct SHM_QUEUE *prev;
+       struct SHM_QUEUE *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 SHMEM_OFFSET ShmemPIDDestroy(int pid);
-extern long *ShmemInitStruct(char *name, unsigned long size,
-                            bool *foundPtr);
-
-
-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 */
-#define BTABLE_DATASIZE (sizeof(BindingEnt) - BTABLE_KEYSIZE)
-        /* 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;
+extern void InitShmemAccess(void *seghdr);
+extern void InitShmemAllocation(void);
+extern void *ShmemAlloc(Size size);
+extern bool ShmemAddrIsValid(void *addr);
+extern void InitShmemIndex(void);
+extern HTAB *ShmemInitHash(const char *name, long init_size, long max_size,
+                         HASHCTL *infoP, int hash_flags);
+extern void *ShmemInitStruct(const char *name, Size size, bool *foundPtr);
+extern Size add_size(Size s1, Size s2);
+extern Size mul_size(Size s1, Size s2);
+
+/* ipci.c */
+extern void RequestAddinShmemSpace(Size size);
+
+/* size constants for the shmem index table */
+ /* max size of data structure string name */
+#define SHMEM_INDEX_KEYSIZE             (48)
+ /* estimated size of the shmem index table (not a hard limit) */
+#define SHMEM_INDEX_SIZE                (32)
+
+/* this is a hash bucket in the shmem index table */
+typedef struct
+{
+       char            key[SHMEM_INDEX_KEYSIZE];               /* string name */
+       void       *location;                   /* location in shared mem */
+       Size            size;                           /* # bytes allocated for the structure */
+} ShmemIndexEnt;
 
 /*
  * prototypes for functions in shmqueue.c
  */
 extern void SHMQueueInit(SHM_QUEUE *queue);
-extern bool SHMQueueIsDetached(SHM_QUEUE *queue);
 extern void SHMQueueElemInit(SHM_QUEUE *queue);
 extern void SHMQueueDelete(SHM_QUEUE *queue);
-extern void SHMQueueInsertHD(SHM_QUEUE *queue, SHM_QUEUE *elem);
-extern void SHMQueueInsertTL(SHM_QUEUE *queue, SHM_QUEUE *elem);
-extern void SHMQueueFirst(SHM_QUEUE *queue, Pointer *nextPtrPtr,
-                         SHM_QUEUE *nextQueue);
+extern void SHMQueueInsertBefore(SHM_QUEUE *queue, SHM_QUEUE *elem);
+extern Pointer SHMQueueNext(SHM_QUEUE *queue, SHM_QUEUE *curElem,
+                        Size linkOffset);
 extern bool SHMQueueEmpty(SHM_QUEUE *queue);
 
-#endif /* SHMEM_H */
+#endif   /* SHMEM_H */