10
10
* Portions Copyright (c) 1994, Regents of the University of California
11
11
*
12
12
* IDENTIFICATION
13
- * $Header: /cvsroot/pgsql/src/backend/port/sysv_shmem.c,v 1.24 2003/10/27 18:30:07 momjian Exp $
13
+ * $Header: /cvsroot/pgsql/src/backend/port/sysv_shmem.c,v 1.25 2003/11/07 21:55:49 tgl Exp $
14
14
*
15
15
*-------------------------------------------------------------------------
16
16
*/
@@ -134,7 +134,7 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size)
134
134
135
135
/* OK, should be able to attach to the segment */
136
136
#ifdef SHM_SHARE_MMU
137
- /* use intimate shared memory on SPARC Solaris */
137
+ /* use intimate shared memory on Solaris */
138
138
memAddress = shmat (shmid , 0 , SHM_SHARE_MMU );
139
139
#else
140
140
memAddress = shmat (shmid , 0 , 0 );
@@ -244,7 +244,7 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port)
244
244
/* Room for a header? */
245
245
Assert (size > MAXALIGN (sizeof (PGShmemHeader )));
246
246
247
- /* Just attach and return the pointer */
247
+ /* If Exec case, just attach and return the pointer */
248
248
if (ExecBackend && UsedShmemSegAddr != NULL && !makePrivate )
249
249
{
250
250
if ((hdr = PGSharedMemoryAttach (UsedShmemSegID , & shmid )) == NULL )
@@ -253,6 +253,9 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port)
253
253
return hdr ;
254
254
}
255
255
256
+ /* Make sure PGSharedMemoryAttach doesn't fail without need */
257
+ UsedShmemSegAddr = NULL ;
258
+
256
259
/* Loop till we find a free IPC key */
257
260
NextShmemSegID = port * 1000 ;
258
261
@@ -326,16 +329,32 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port)
326
329
hdr -> totalsize = size ;
327
330
hdr -> freeoffset = MAXALIGN (sizeof (PGShmemHeader ));
328
331
329
-
330
- if (ExecBackend && UsedShmemSegAddr == NULL && !makePrivate )
331
- {
332
- UsedShmemSegAddr = memAddress ;
333
- UsedShmemSegID = NextShmemSegID ;
334
- }
332
+ /* Save info for possible future use */
333
+ UsedShmemSegAddr = memAddress ;
334
+ UsedShmemSegID = NextShmemSegID ;
335
335
336
336
return hdr ;
337
337
}
338
338
339
+ /*
340
+ * PGSharedMemoryDetach
341
+ *
342
+ * Detach from the shared memory segment, if still attached. This is not
343
+ * intended for use by the process that originally created the segment
344
+ * (it will have an on_shmem_exit callback registered to do that). Rather,
345
+ * this is for subprocesses that have inherited an attachment and want to
346
+ * get rid of it.
347
+ */
348
+ void
349
+ PGSharedMemoryDetach (void )
350
+ {
351
+ if (UsedShmemSegAddr != NULL )
352
+ {
353
+ if (shmdt (UsedShmemSegAddr ) < 0 )
354
+ elog (LOG , "shmdt(%p) failed: %m" , UsedShmemSegAddr );
355
+ UsedShmemSegAddr = NULL ;
356
+ }
357
+ }
339
358
340
359
/*
341
360
* Attach to shared memory and make sure it has a Postgres header
0 commit comments