diff options
| author | Robert Haas | 2014-03-10 18:04:47 +0000 |
|---|---|---|
| committer | Robert Haas | 2014-03-10 18:04:47 +0000 |
| commit | 8722017bbcbc95e311bbaa6d21cd028e296e5e35 (patch) | |
| tree | 3fe4426fd8888edcde9360f553f2c290c2bb1dd8 /src/backend/storage/ipc/dsm.c | |
| parent | 5a991ef8692ed0d170b44958a81a6bd70e90585c (diff) | |
Allow dynamic shared memory segments to be kept until shutdown.
Amit Kapila, reviewed by Kyotaro Horiguchi, with some further
changes by me.
Diffstat (limited to 'src/backend/storage/ipc/dsm.c')
| -rw-r--r-- | src/backend/storage/ipc/dsm.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/backend/storage/ipc/dsm.c b/src/backend/storage/ipc/dsm.c index 31e592e06e7..232c099c18a 100644 --- a/src/backend/storage/ipc/dsm.c +++ b/src/backend/storage/ipc/dsm.c @@ -886,6 +886,33 @@ dsm_keep_mapping(dsm_segment *seg) } /* + * Keep a dynamic shared memory segment until postmaster shutdown. + * + * This function should not be called more than once per segment; + * on Windows, doing so will create unnecessary handles which will + * consume system resources to no benefit. + * + * Note that this function does not arrange for the current process to + * keep the segment mapped indefinitely; if that behavior is desired, + * dsm_keep_mapping() should be used from each process that needs to + * retain the mapping. + */ +void +dsm_keep_segment(dsm_segment *seg) +{ + /* + * Bump reference count for this segment in shared memory. This will + * ensure that even if there is no session which is attached to this + * segment, it will remain until postmaster shutdown. + */ + LWLockAcquire(DynamicSharedMemoryControlLock, LW_EXCLUSIVE); + dsm_control->item[seg->control_slot].refcnt++; + LWLockRelease(DynamicSharedMemoryControlLock); + + dsm_impl_keep_segment(seg->handle, seg->impl_private); +} + +/* * Find an existing mapping for a shared memory segment, if there is one. */ dsm_segment * |
