Skip to content

Commit f7102b0

Browse files
committed
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.
1 parent fd0f651 commit f7102b0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/backend/storage/ipc/dsm.c

+18
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,24 @@ dsm_pin_mapping(dsm_segment *seg)
795795
}
796796
}
797797

798+
/*
799+
* Arrange to remove a dynamic shared memory mapping at cleanup time.
800+
*
801+
* dsm_pin_mapping() can be used to preserve a mapping for the entire
802+
* lifetime of a process; this function reverses that decision, making
803+
* the segment owned by the current resource owner. This may be useful
804+
* just before performing some operation that will invalidate the segment
805+
* for future use by this backend.
806+
*/
807+
void
808+
dsm_unpin_mapping(dsm_segment *seg)
809+
{
810+
Assert(seg->resowner == NULL);
811+
ResourceOwnerEnlargeDSMs(CurrentResourceOwner);
812+
seg->resowner = CurrentResourceOwner;
813+
ResourceOwnerRememberDSM(seg->resowner, seg);
814+
}
815+
798816
/*
799817
* Keep a dynamic shared memory segment until postmaster shutdown.
800818
*

src/include/storage/dsm.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extern void dsm_detach(dsm_segment *seg);
3737

3838
/* Resource management functions. */
3939
extern void dsm_pin_mapping(dsm_segment *seg);
40+
extern void dsm_unpin_mapping(dsm_segment *seg);
4041
extern void dsm_pin_segment(dsm_segment *seg);
4142
extern dsm_segment *dsm_find_mapping(dsm_handle h);
4243

0 commit comments

Comments
 (0)