The extra semaphore that proc.c now allocates for checkpoint processes
authorTom Lane <[email protected]>
Tue, 6 Nov 2001 00:38:26 +0000 (00:38 +0000)
committerTom Lane <[email protected]>
Tue, 6 Nov 2001 00:38:26 +0000 (00:38 +0000)
should be accounted for in the PROC_SEM_MAP_ENTRIES() macro.  Otherwise
the ports that rely on this macro to size data structures are broken.
Mea culpa.

src/backend/storage/lmgr/proc.c
src/include/storage/proc.h

index bda8d174470006e4c96c5d8d9075474d3875f109..72bb0a792182e631a5f91f464056c80ecc622239 100644 (file)
@@ -124,10 +124,13 @@ InitProcGlobal(int maxBackends)
 
        /*
         * Compute size for ProcGlobal structure.  Note we need one more sema
-        * besides those used for regular backends.
+        * besides those used for regular backends; this is accounted for in
+        * the PROC_SEM_MAP_ENTRIES macro.  (We do it that way so that other
+        * modules that use PROC_SEM_MAP_ENTRIES(maxBackends) to size data
+        * structures don't have to know about this explicitly.)
         */
        Assert(maxBackends > 0);
-       semMapEntries = PROC_SEM_MAP_ENTRIES(maxBackends + 1);
+       semMapEntries = PROC_SEM_MAP_ENTRIES(maxBackends);
        procGlobalSize = sizeof(PROC_HDR) + (semMapEntries - 1) *sizeof(SEM_MAP_ENTRY);
 
        /* Create or attach to the ProcGlobal shared structure */
index 57a5b6fb934edfaf5831c903a82516c600a11c5c..b242fc910c7fff23d66e7b61ccf0ef4a3b4379ff 100644 (file)
@@ -93,10 +93,12 @@ extern PROC *MyProc;
  * in each set for identification purposes.)
  *
  * PROC_SEM_MAP_ENTRIES is the number of semaphore sets we need to allocate
- * to keep track of up to maxBackends backends.
+ * to keep track of up to maxBackends backends.  Note that we need one extra
+ * semaphore (see storage/lmgr/proc.c), so the computation may look wrong,
+ * but it's right.
  */
 #define  PROC_NSEMS_PER_SET            16
-#define  PROC_SEM_MAP_ENTRIES(maxBackends)     (((maxBackends)-1)/PROC_NSEMS_PER_SET+1)
+#define  PROC_SEM_MAP_ENTRIES(maxBackends)     ((maxBackends)/PROC_NSEMS_PER_SET+1)
 
 typedef struct
 {