From f7102b04638a882b38cbba7670471a073a939865 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Thu, 30 Oct 2014 14:55:23 -0400 Subject: [PATCH] Extend dsm API with a new function dsm_unpin_mapping. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reassociates a dynamic shared memory handle previous passed to dsm_pin_mapping with the current resource owner, so that it will be cleaned up at the end of the current query. Patch by me. Review of the function name by Andres Freund, Amit Kapila, Jim Nasby, Petr Jelinek, and Álvaro Herrera. --- src/backend/storage/ipc/dsm.c | 18 ++++++++++++++++++ src/include/storage/dsm.h | 1 + 2 files changed, 19 insertions(+) diff --git a/src/backend/storage/ipc/dsm.c b/src/backend/storage/ipc/dsm.c index 7ce45caaf9..6ff1c7ea2a 100644 --- a/src/backend/storage/ipc/dsm.c +++ b/src/backend/storage/ipc/dsm.c @@ -795,6 +795,24 @@ dsm_pin_mapping(dsm_segment *seg) } } +/* + * Arrange to remove a dynamic shared memory mapping at cleanup time. + * + * dsm_pin_mapping() can be used to preserve a mapping for the entire + * lifetime of a process; this function reverses that decision, making + * the segment owned by the current resource owner. This may be useful + * just before performing some operation that will invalidate the segment + * for future use by this backend. + */ +void +dsm_unpin_mapping(dsm_segment *seg) +{ + Assert(seg->resowner == NULL); + ResourceOwnerEnlargeDSMs(CurrentResourceOwner); + seg->resowner = CurrentResourceOwner; + ResourceOwnerRememberDSM(seg->resowner, seg); +} + /* * Keep a dynamic shared memory segment until postmaster shutdown. * diff --git a/src/include/storage/dsm.h b/src/include/storage/dsm.h index a83b35fd66..cfe5d48e87 100644 --- a/src/include/storage/dsm.h +++ b/src/include/storage/dsm.h @@ -37,6 +37,7 @@ extern void dsm_detach(dsm_segment *seg); /* Resource management functions. */ extern void dsm_pin_mapping(dsm_segment *seg); +extern void dsm_unpin_mapping(dsm_segment *seg); extern void dsm_pin_segment(dsm_segment *seg); extern dsm_segment *dsm_find_mapping(dsm_handle h);