1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-08 11:42:09 +03:00

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.
This commit is contained in:
Tom Lane
2015-03-01 12:31:32 -05:00
parent e059e02e43
commit 097fe194aa
3 changed files with 20 additions and 18 deletions

View File

@ -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().