8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.153 2004/08 /29 05:06:48 momjian Exp $
11
+ * $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.154 2004/09 /29 15:15:55 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -89,6 +89,22 @@ static void DummyProcKill(int code, Datum arg);
89
89
static bool CheckStatementTimeout (void );
90
90
91
91
92
+ /*
93
+ * Report shared-memory space needed by InitProcGlobal.
94
+ */
95
+ int
96
+ ProcGlobalShmemSize (int maxBackends )
97
+ {
98
+ int size = 0 ;
99
+
100
+ size += MAXALIGN (sizeof (PROC_HDR )); /* ProcGlobal */
101
+ size += MAXALIGN (NUM_DUMMY_PROCS * sizeof (PGPROC )); /* DummyProcs */
102
+ size += MAXALIGN (maxBackends * sizeof (PGPROC )); /* MyProcs */
103
+ size += MAXALIGN (sizeof (slock_t )); /* ProcStructLock */
104
+
105
+ return size ;
106
+ }
107
+
92
108
/*
93
109
* Report number of semaphores needed by InitProcGlobal.
94
110
*/
@@ -134,7 +150,7 @@ InitProcGlobal(int maxBackends)
134
150
* processes, too. These do not get linked into the freeProcs list.
135
151
*/
136
152
DummyProcs = (PGPROC * )
137
- ShmemInitStruct ("DummyProcs" , sizeof (PGPROC ) * NUM_DUMMY_PROCS ,
153
+ ShmemInitStruct ("DummyProcs" , NUM_DUMMY_PROCS * sizeof (PGPROC ),
138
154
& foundDummy );
139
155
140
156
if (foundProcGlobal || foundDummy )
@@ -147,6 +163,7 @@ InitProcGlobal(int maxBackends)
147
163
/*
148
164
* We're the first - initialize.
149
165
*/
166
+ PGPROC * procs ;
150
167
int i ;
151
168
152
169
ProcGlobal -> freeProcs = INVALID_OFFSET ;
@@ -155,22 +172,20 @@ InitProcGlobal(int maxBackends)
155
172
* Pre-create the PGPROC structures and create a semaphore for
156
173
* each.
157
174
*/
175
+ procs = (PGPROC * ) ShmemAlloc (maxBackends * sizeof (PGPROC ));
176
+ if (!procs )
177
+ ereport (FATAL ,
178
+ (errcode (ERRCODE_OUT_OF_MEMORY ),
179
+ errmsg ("out of shared memory" )));
180
+ MemSet (procs , 0 , maxBackends * sizeof (PGPROC ));
158
181
for (i = 0 ; i < maxBackends ; i ++ )
159
182
{
160
- PGPROC * proc ;
161
-
162
- proc = (PGPROC * ) ShmemAlloc (sizeof (PGPROC ));
163
- if (!proc )
164
- ereport (FATAL ,
165
- (errcode (ERRCODE_OUT_OF_MEMORY ),
166
- errmsg ("out of shared memory" )));
167
- MemSet (proc , 0 , sizeof (PGPROC ));
168
- PGSemaphoreCreate (& proc -> sem );
169
- proc -> links .next = ProcGlobal -> freeProcs ;
170
- ProcGlobal -> freeProcs = MAKE_OFFSET (proc );
183
+ PGSemaphoreCreate (& (procs [i ].sem ));
184
+ procs [i ].links .next = ProcGlobal -> freeProcs ;
185
+ ProcGlobal -> freeProcs = MAKE_OFFSET (& procs [i ]);
171
186
}
172
187
173
- MemSet (DummyProcs , 0 , sizeof (PGPROC ) * NUM_DUMMY_PROCS );
188
+ MemSet (DummyProcs , 0 , NUM_DUMMY_PROCS * sizeof (PGPROC ));
174
189
for (i = 0 ; i < NUM_DUMMY_PROCS ; i ++ )
175
190
{
176
191
DummyProcs [i ].pid = 0 ; /* marks dummy proc as not in use */
0 commit comments