From 097fe194aa7c590b4fa43d5e40c083940859c286 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 1 Mar 2015 12:31:32 -0500 Subject: [PATCH] Move memory context callback declarations into palloc.h. Initial experience with this feature suggests that instances of MemoryContextCallback are likely to propagate into some widely-used headers over time. As things stood, that would result in pulling memutils.h or at least memnodes.h into common headers, which does not seem desirable. Instead, let's decide that this feature is part of the "ordinary palloc user" API rather than the "specialized context management" API, and as such should be declared in palloc.h not memutils.h. --- src/include/nodes/memnodes.h | 16 ---------------- src/include/utils/memutils.h | 2 -- src/include/utils/palloc.h | 20 ++++++++++++++++++++ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/include/nodes/memnodes.h b/src/include/nodes/memnodes.h index 3eeaad4928..5e036b9b6f 100644 --- a/src/include/nodes/memnodes.h +++ b/src/include/nodes/memnodes.h @@ -16,22 +16,6 @@ #include "nodes/nodes.h" -/* - * 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; - /* * MemoryContext * A logical context in which memory allocations occur. diff --git a/src/include/utils/memutils.h b/src/include/utils/memutils.h index dbb163a153..9e84d01103 100644 --- a/src/include/utils/memutils.h +++ b/src/include/utils/memutils.h @@ -97,8 +97,6 @@ extern void MemoryContextDelete(MemoryContext context); extern void MemoryContextResetOnly(MemoryContext context); extern void MemoryContextResetChildren(MemoryContext context); extern void MemoryContextDeleteChildren(MemoryContext context); -extern void MemoryContextRegisterResetCallback(MemoryContext context, - MemoryContextCallback *cb); extern void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent); extern Size GetMemoryChunkSpace(void *pointer); diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h index f586fd5535..39b318da43 100644 --- a/src/include/utils/palloc.h +++ b/src/include/utils/palloc.h @@ -35,6 +35,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() @@ -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(). -- 2.40.0