8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.93 2006/07/14 14:52:22 momjian Exp $
11
+ * $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.94 2006/07/22 23:04:39 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -211,9 +211,6 @@ InitShmemIndex(void)
211
211
{
212
212
HASHCTL info ;
213
213
int hash_flags ;
214
- ShmemIndexEnt * result ,
215
- item ;
216
- bool found ;
217
214
218
215
/*
219
216
* Since ShmemInitHash calls ShmemInitStruct, which expects the ShmemIndex
@@ -227,32 +224,11 @@ InitShmemIndex(void)
227
224
info .entrysize = sizeof (ShmemIndexEnt );
228
225
hash_flags = HASH_ELEM ;
229
226
230
- /* This will acquire the shmem index lock, but not release it. */
231
227
ShmemIndex = ShmemInitHash ("ShmemIndex" ,
232
228
SHMEM_INDEX_SIZE , SHMEM_INDEX_SIZE ,
233
229
& info , hash_flags );
234
230
if (!ShmemIndex )
235
231
elog (FATAL , "could not initialize Shmem Index" );
236
-
237
- /*
238
- * Now, create an entry in the hashtable for the index itself.
239
- */
240
- if (!IsUnderPostmaster )
241
- {
242
- MemSet (item .key , 0 , SHMEM_INDEX_KEYSIZE );
243
- strncpy (item .key , "ShmemIndex" , SHMEM_INDEX_KEYSIZE );
244
-
245
- result = (ShmemIndexEnt * )
246
- hash_search (ShmemIndex , (void * ) & item , HASH_ENTER , & found );
247
-
248
- Assert (!found );
249
-
250
- result -> location = MAKE_OFFSET (ShmemIndex -> hctl );
251
- result -> size = SHMEM_INDEX_SIZE ;
252
- }
253
-
254
- /* now release the lock acquired in ShmemInitStruct */
255
- LWLockRelease (ShmemIndexLock );
256
232
}
257
233
258
234
/*
@@ -295,7 +271,7 @@ ShmemInitHash(const char *name, /* table string name for shmem index */
295
271
296
272
/* look it up in the shmem index */
297
273
location = ShmemInitStruct (name ,
298
- sizeof ( HASHHDR ) + infoP -> dsize * sizeof ( HASHSEGMENT ),
274
+ hash_get_shared_size ( infoP , hash_flags ),
299
275
& found );
300
276
301
277
/*
@@ -312,9 +288,8 @@ ShmemInitHash(const char *name, /* table string name for shmem index */
312
288
if (found )
313
289
hash_flags |= HASH_ATTACH ;
314
290
315
- /* Now provide the header and directory pointers */
291
+ /* Pass location of hashtable header to hash_create */
316
292
infoP -> hctl = (HASHHDR * ) location ;
317
- infoP -> dir = (HASHSEGMENT * ) (((char * ) location ) + sizeof (HASHHDR ));
318
293
319
294
return hash_create (name , init_size , infoP , hash_flags );
320
295
}
@@ -363,14 +338,16 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
363
338
* If the shmem index doesn't exist, we are bootstrapping: we must
364
339
* be trying to init the shmem index itself.
365
340
*
366
- * Notice that the ShmemIndexLock is held until the shmem index
367
- * has been completely initialized.
341
+ * Notice that the ShmemIndexLock is released before the shmem
342
+ * index has been initialized. This should be OK because no
343
+ * other process can be accessing shared memory yet.
368
344
*/
369
345
Assert (shmemseghdr -> indexoffset == 0 );
370
346
structPtr = ShmemAlloc (size );
371
347
shmemseghdr -> indexoffset = MAKE_OFFSET (structPtr );
372
348
* foundPtr = FALSE;
373
349
}
350
+ LWLockRelease (ShmemIndexLock );
374
351
return structPtr ;
375
352
}
376
353
0 commit comments