aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/ipc/dsm.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2014-03-18 07:58:53 -0400
committerRobert Haas <rhaas@postgresql.org>2014-03-18 07:58:53 -0400
commit79a4d24f31e09eb3c421deb34829eee0bf6acd67 (patch)
tree8b0bba2d25d63961f2c4ac287034347372d6e7de /src/backend/storage/ipc/dsm.c
parent551fb5ac742eb7dbf92aa80743aa5a52b8a0189f (diff)
downloadpostgresql-79a4d24f31e09eb3c421deb34829eee0bf6acd67.tar.gz
postgresql-79a4d24f31e09eb3c421deb34829eee0bf6acd67.zip
Make it easy to detach completely from shared memory.
The new function dsm_detach_all() can be used either by postmaster children that don't wish to take any risk of accidentally corrupting shared memory; or by forked children of regular backends with the same need. This patch also updates the postmaster children that already do PGSharedMemoryDetach() to do dsm_detach_all() as well. Per discussion with Tom Lane.
Diffstat (limited to 'src/backend/storage/ipc/dsm.c')
-rw-r--r--src/backend/storage/ipc/dsm.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/backend/storage/ipc/dsm.c b/src/backend/storage/ipc/dsm.c
index 232c099c18a..c967177c4b1 100644
--- a/src/backend/storage/ipc/dsm.c
+++ b/src/backend/storage/ipc/dsm.c
@@ -722,6 +722,8 @@ dsm_attach(dsm_handle h)
/*
* At backend shutdown time, detach any segments that are still attached.
+ * (This is similar to dsm_detach_all, except that there's no reason to
+ * unmap the control segment before exiting, so we don't bother.)
*/
void
dsm_backend_shutdown(void)
@@ -736,6 +738,31 @@ dsm_backend_shutdown(void)
}
/*
+ * Detach all shared memory segments, including the control segments. This
+ * should be called, along with PGSharedMemoryDetach, in processes that
+ * might inherit mappings but are not intended to be connected to dynamic
+ * shared memory.
+ */
+void
+dsm_detach_all(void)
+{
+ void *control_address = dsm_control;
+
+ while (!dlist_is_empty(&dsm_segment_list))
+ {
+ dsm_segment *seg;
+
+ seg = dlist_head_element(dsm_segment, node, &dsm_segment_list);
+ dsm_detach(seg);
+ }
+
+ if (control_address != NULL)
+ dsm_impl_op(DSM_OP_DETACH, dsm_control_handle, 0,
+ &dsm_control_impl_private, &control_address,
+ &dsm_control_mapped_size, ERROR);
+}
+
+/*
* Resize an existing shared memory segment.
*
* This may cause the shared memory segment to be remapped at a different