From: Robert Haas Date: Thu, 30 Oct 2014 18:55:23 +0000 (-0400) Subject: Extend dsm API with a new function dsm_unpin_mapping. X-Git-Tag: REL9_5_ALPHA1~1286 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f7102b04638a882b38cbba7670471a073a939865;p=postgresql Extend dsm API with a new function dsm_unpin_mapping. 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. --- 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);