1 /*
2  * memutils.h
3  *   utility functions to help with postgres' memory management primitives
4  */
5 
6 #ifndef CITUS_MEMUTILS_H
7 #define CITUS_MEMUTILS_H
8 
9 #include "utils/palloc.h"
10 
11 
12 /*
13  * EnsureReleaseResource is an abstraction on MemoryContextRegisterResetCallback that
14  * allocates the space for the MemoryContextCallback and registers it to the current
15  * MemoryContext, ensuring the call of callback with arg as its argument during either the
16  * Reset of Delete of a MemoryContext.
17  */
18 static inline void
EnsureReleaseResource(MemoryContextCallbackFunction callback,void * arg)19 EnsureReleaseResource(MemoryContextCallbackFunction callback, void *arg)
20 {
21 	MemoryContextCallback *cb = MemoryContextAllocZero(CurrentMemoryContext,
22 													   sizeof(MemoryContextCallback));
23 	cb->func = callback;
24 	cb->arg = arg;
25 	MemoryContextRegisterResetCallback(CurrentMemoryContext, cb);
26 }
27 
28 
29 #endif /*CITUS_MEMUTILS_H */
30