88 *
99 *
1010 * 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 $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -211,9 +211,6 @@ InitShmemIndex(void)
211211{
212212HASHCTL info ;
213213int hash_flags ;
214- ShmemIndexEnt * result ,
215- item ;
216- bool found ;
217214
218215/*
219216 * Since ShmemInitHash calls ShmemInitStruct, which expects the ShmemIndex
@@ -227,32 +224,11 @@ InitShmemIndex(void)
227224info .entrysize = sizeof (ShmemIndexEnt );
228225hash_flags = HASH_ELEM ;
229226
230- /* This will acquire the shmem index lock, but not release it. */
231227ShmemIndex = ShmemInitHash ("ShmemIndex" ,
232228SHMEM_INDEX_SIZE ,SHMEM_INDEX_SIZE ,
233229& info ,hash_flags );
234230if (!ShmemIndex )
235231elog (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 );
256232}
257233
258234/*
@@ -295,7 +271,7 @@ ShmemInitHash(const char *name, /* table string name for shmem index */
295271
296272/* look it up in the shmem index */
297273location = ShmemInitStruct (name ,
298- sizeof ( HASHHDR ) + infoP -> dsize * sizeof ( HASHSEGMENT ),
274+ hash_get_shared_size ( infoP , hash_flags ),
299275& found );
300276
301277/*
@@ -312,9 +288,8 @@ ShmemInitHash(const char *name, /* table string name for shmem index */
312288if (found )
313289hash_flags |=HASH_ATTACH ;
314290
315- /*Now provide the headerand directory pointers */
291+ /*Pass location of hashtable headerto hash_create */
316292infoP -> hctl = (HASHHDR * )location ;
317- infoP -> dir = (HASHSEGMENT * ) (((char * )location )+ sizeof (HASHHDR ));
318293
319294return hash_create (name ,init_size ,infoP ,hash_flags );
320295}
@@ -363,14 +338,16 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
363338 * If the shmem index doesn't exist, we are bootstrapping: we must
364339 * be trying to init the shmem index itself.
365340 *
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.
368344 */
369345Assert (shmemseghdr -> indexoffset == 0 );
370346structPtr = ShmemAlloc (size );
371347shmemseghdr -> indexoffset = MAKE_OFFSET (structPtr );
372348* foundPtr = FALSE;
373349}
350+ LWLockRelease (ShmemIndexLock );
374351return structPtr ;
375352}
376353