diff options
author | Tom Lane | 2015-02-27 22:16:40 +0000 |
---|---|---|
committer | Tom Lane | 2015-02-27 22:16:43 +0000 |
commit | f65e8270587f3e9b8224e20f7d020ed1f816dfe1 (patch) | |
tree | 0a285e9914555d3d876dfa1c5a9eb56825c4acd7 /src/include/nodes/memnodes.h | |
parent | 654809e770ce270c0bb9de726c5df1ab193d60f0 (diff) |
Invent a memory context reset/delete callback mechanism.
This allows cleanup actions to be registered to be called just before a
particular memory context's contents are flushed (either by deletion or
MemoryContextReset). The patch in itself has no use-cases for this, but
several likely reasons for wanting this exist.
In passing, per discussion, rearrange some boolean fields in struct
MemoryContextData so as to avoid wasted padding space. For safety,
this requires making allowInCritSection's existence unconditional;
but I think that's a better approach than what was there anyway.
Diffstat (limited to 'src/include/nodes/memnodes.h')
-rw-r--r-- | src/include/nodes/memnodes.h | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/include/nodes/memnodes.h b/src/include/nodes/memnodes.h index ca9c3dea3cb..3eeaad49288 100644 --- a/src/include/nodes/memnodes.h +++ b/src/include/nodes/memnodes.h @@ -17,6 +17,22 @@ #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. * @@ -54,15 +70,15 @@ typedef struct MemoryContextMethods typedef struct MemoryContextData { NodeTag type; /* identifies exact kind of context */ + /* these two fields are placed here to minimize alignment wastage: */ + bool isReset; /* T = no space alloced since last reset */ + bool allowInCritSection; /* allow palloc in critical section */ MemoryContextMethods *methods; /* virtual function table */ MemoryContext parent; /* NULL if no parent (toplevel context) */ MemoryContext firstchild; /* head of linked list of children */ MemoryContext nextchild; /* next child of same parent */ char *name; /* context name (just for debugging) */ - bool isReset; /* T = no space alloced since last reset */ -#ifdef USE_ASSERT_CHECKING - bool allowInCritSection; /* allow palloc in critical section */ -#endif + MemoryContextCallback *reset_cbs; /* list of reset/delete callbacks */ } MemoryContextData; /* utils/palloc.h contains typedef struct MemoryContextData *MemoryContext */ |