summaryrefslogtreecommitdiff
path: root/src/include/nodes/memnodes.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/nodes/memnodes.h')
-rw-r--r--src/include/nodes/memnodes.h41
1 files changed, 34 insertions, 7 deletions
diff --git a/src/include/nodes/memnodes.h b/src/include/nodes/memnodes.h
index 854bd5d225..37d27032c2 100644
--- a/src/include/nodes/memnodes.h
+++ b/src/include/nodes/memnodes.h
@@ -14,7 +14,15 @@
#ifndef MEMNODES_H
#define MEMNODES_H
-#include "nodes/nodes.h"
+/*
+ * List of valid memory context types.
+ */
+typedef enum
+{
+ MemoryContext_AllocSet,
+ MemoryContext_Generation,
+ MemoryContext_Slab
+} MemoryContextType;
/*
* MemoryContextCounters
@@ -75,7 +83,7 @@ typedef struct MemoryContextMethods
typedef struct MemoryContextData
{
- NodeTag type; /* identifies exact kind of context */
+ char type; /* MemoryContextType for this 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 */
@@ -99,10 +107,29 @@ typedef struct MemoryContextData
*
* Add new context types to the set accepted by this macro.
*/
-#define MemoryContextIsValid(context) \
- ((context) != NULL && \
- (IsA((context), AllocSetContext) || \
- IsA((context), SlabContext) || \
- IsA((context), GenerationContext)))
+static inline bool
+MemoryContextIsValid(MemoryContext context)
+{
+ return context != NULL &&
+ (context->type == MemoryContext_AllocSet ||
+ context->type == MemoryContext_Slab ||
+ context->type == MemoryContext_Generation);
+}
+
+/*
+ * MemoryContextCast
+ * Cast a MemoryContext to a context of a given type, checking the type.
+ *
+ * NB: The static inline function avoids multiple evaluation.
+ */
+static inline MemoryContext
+MemoryContextCastImpl(MemoryContextType type, MemoryContext context)
+{
+ Assert(context == NULL || context->type == type);
+ return context;
+}
+#define MemoryContextCast(_type_, context) \
+ ((_type_##Context *) \
+ MemoryContextCastImpl(MemoryContext_##_type_, context))
#endif /* MEMNODES_H */