diff options
Diffstat (limited to 'src/include/utils/palloc.h')
-rw-r--r-- | src/include/utils/palloc.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h index f586fd5535b..39b318da43a 100644 --- a/src/include/utils/palloc.h +++ b/src/include/utils/palloc.h @@ -36,6 +36,22 @@ typedef struct MemoryContextData *MemoryContext; /* + * A memory context can have callback functions registered on it. Any such + * function will be called once just before the context is next reset or + * deleted. The MemoryContextCallback struct describing such a callback + * typically would be allocated within the context itself, thereby avoiding + * any need to manage it explicitly (the reset/delete action will free it). + */ +typedef void (*MemoryContextCallbackFunction) (void *arg); + +typedef struct MemoryContextCallback +{ + MemoryContextCallbackFunction func; /* function to call */ + void *arg; /* argument to pass it */ + struct MemoryContextCallback *next; /* next in list of callbacks */ +} MemoryContextCallback; + +/* * CurrentMemoryContext is the default allocation context for palloc(). * Avoid accessing it directly! Instead, use MemoryContextSwitchTo() * to change the setting. @@ -107,6 +123,10 @@ MemoryContextSwitchTo(MemoryContext context) #endif /* PG_USE_INLINE || MCXT_INCLUDE_DEFINITIONS */ #endif /* FRONTEND */ +/* Registration of memory context reset/delete callbacks */ +extern void MemoryContextRegisterResetCallback(MemoryContext context, + MemoryContextCallback *cb); + /* * These are like standard strdup() except the copied string is * allocated in a context, not with malloc(). |