|
|
|
@ -258,7 +258,7 @@ BogusGetChunkSpace(void *pointer) |
|
|
|
void |
|
|
|
void |
|
|
|
MemoryContextInit(void) |
|
|
|
MemoryContextInit(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AssertState(TopMemoryContext == NULL); |
|
|
|
Assert(TopMemoryContext == NULL); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* First, initialize TopMemoryContext, which is the parent of all others. |
|
|
|
* First, initialize TopMemoryContext, which is the parent of all others. |
|
|
|
@ -302,7 +302,7 @@ MemoryContextInit(void) |
|
|
|
void |
|
|
|
void |
|
|
|
MemoryContextReset(MemoryContext context) |
|
|
|
MemoryContextReset(MemoryContext context) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
|
|
|
|
|
|
|
|
/* save a function call in common case where there are no children */ |
|
|
|
/* save a function call in common case where there are no children */ |
|
|
|
if (context->firstchild != NULL) |
|
|
|
if (context->firstchild != NULL) |
|
|
|
@ -321,7 +321,7 @@ MemoryContextReset(MemoryContext context) |
|
|
|
void |
|
|
|
void |
|
|
|
MemoryContextResetOnly(MemoryContext context) |
|
|
|
MemoryContextResetOnly(MemoryContext context) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
|
|
|
|
|
|
|
|
/* Nothing to do if no pallocs since startup or last reset */ |
|
|
|
/* Nothing to do if no pallocs since startup or last reset */ |
|
|
|
if (!context->isReset) |
|
|
|
if (!context->isReset) |
|
|
|
@ -354,7 +354,7 @@ MemoryContextResetChildren(MemoryContext context) |
|
|
|
{ |
|
|
|
{ |
|
|
|
MemoryContext child; |
|
|
|
MemoryContext child; |
|
|
|
|
|
|
|
|
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
|
|
|
|
|
|
|
|
for (child = context->firstchild; child != NULL; child = child->nextchild) |
|
|
|
for (child = context->firstchild; child != NULL; child = child->nextchild) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -375,7 +375,7 @@ MemoryContextResetChildren(MemoryContext context) |
|
|
|
void |
|
|
|
void |
|
|
|
MemoryContextDelete(MemoryContext context) |
|
|
|
MemoryContextDelete(MemoryContext context) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
/* We had better not be deleting TopMemoryContext ... */ |
|
|
|
/* We had better not be deleting TopMemoryContext ... */ |
|
|
|
Assert(context != TopMemoryContext); |
|
|
|
Assert(context != TopMemoryContext); |
|
|
|
/* And not CurrentMemoryContext, either */ |
|
|
|
/* And not CurrentMemoryContext, either */ |
|
|
|
@ -420,7 +420,7 @@ MemoryContextDelete(MemoryContext context) |
|
|
|
void |
|
|
|
void |
|
|
|
MemoryContextDeleteChildren(MemoryContext context) |
|
|
|
MemoryContextDeleteChildren(MemoryContext context) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* MemoryContextDelete will delink the child from me, so just iterate as |
|
|
|
* MemoryContextDelete will delink the child from me, so just iterate as |
|
|
|
@ -450,7 +450,7 @@ void |
|
|
|
MemoryContextRegisterResetCallback(MemoryContext context, |
|
|
|
MemoryContextRegisterResetCallback(MemoryContext context, |
|
|
|
MemoryContextCallback *cb) |
|
|
|
MemoryContextCallback *cb) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
|
|
|
|
|
|
|
|
/* Push onto head so this will be called before older registrants. */ |
|
|
|
/* Push onto head so this will be called before older registrants. */ |
|
|
|
cb->next = context->reset_cbs; |
|
|
|
cb->next = context->reset_cbs; |
|
|
|
@ -493,7 +493,7 @@ MemoryContextCallResetCallbacks(MemoryContext context) |
|
|
|
void |
|
|
|
void |
|
|
|
MemoryContextSetIdentifier(MemoryContext context, const char *id) |
|
|
|
MemoryContextSetIdentifier(MemoryContext context, const char *id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
context->ident = id; |
|
|
|
context->ident = id; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -518,8 +518,8 @@ MemoryContextSetIdentifier(MemoryContext context, const char *id) |
|
|
|
void |
|
|
|
void |
|
|
|
MemoryContextSetParent(MemoryContext context, MemoryContext new_parent) |
|
|
|
MemoryContextSetParent(MemoryContext context, MemoryContext new_parent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
AssertArg(context != new_parent); |
|
|
|
Assert(context != new_parent); |
|
|
|
|
|
|
|
|
|
|
|
/* Fast path if it's got correct parent already */ |
|
|
|
/* Fast path if it's got correct parent already */ |
|
|
|
if (new_parent == context->parent) |
|
|
|
if (new_parent == context->parent) |
|
|
|
@ -545,7 +545,7 @@ MemoryContextSetParent(MemoryContext context, MemoryContext new_parent) |
|
|
|
/* And relink */ |
|
|
|
/* And relink */ |
|
|
|
if (new_parent) |
|
|
|
if (new_parent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AssertArg(MemoryContextIsValid(new_parent)); |
|
|
|
Assert(MemoryContextIsValid(new_parent)); |
|
|
|
context->parent = new_parent; |
|
|
|
context->parent = new_parent; |
|
|
|
context->prevchild = NULL; |
|
|
|
context->prevchild = NULL; |
|
|
|
context->nextchild = new_parent->firstchild; |
|
|
|
context->nextchild = new_parent->firstchild; |
|
|
|
@ -575,7 +575,7 @@ MemoryContextSetParent(MemoryContext context, MemoryContext new_parent) |
|
|
|
void |
|
|
|
void |
|
|
|
MemoryContextAllowInCriticalSection(MemoryContext context, bool allow) |
|
|
|
MemoryContextAllowInCriticalSection(MemoryContext context, bool allow) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
|
|
|
|
|
|
|
|
context->allowInCritSection = allow; |
|
|
|
context->allowInCritSection = allow; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -612,7 +612,7 @@ GetMemoryChunkSpace(void *pointer) |
|
|
|
MemoryContext |
|
|
|
MemoryContext |
|
|
|
MemoryContextGetParent(MemoryContext context) |
|
|
|
MemoryContextGetParent(MemoryContext context) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
|
|
|
|
|
|
|
|
return context->parent; |
|
|
|
return context->parent; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -624,7 +624,7 @@ MemoryContextGetParent(MemoryContext context) |
|
|
|
bool |
|
|
|
bool |
|
|
|
MemoryContextIsEmpty(MemoryContext context) |
|
|
|
MemoryContextIsEmpty(MemoryContext context) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* For now, we consider a memory context nonempty if it has any children; |
|
|
|
* For now, we consider a memory context nonempty if it has any children; |
|
|
|
@ -645,7 +645,7 @@ MemoryContextMemAllocated(MemoryContext context, bool recurse) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Size total = context->mem_allocated; |
|
|
|
Size total = context->mem_allocated; |
|
|
|
|
|
|
|
|
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
|
|
|
|
|
|
|
|
if (recurse) |
|
|
|
if (recurse) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -737,7 +737,7 @@ MemoryContextStatsInternal(MemoryContext context, int level, |
|
|
|
MemoryContext child; |
|
|
|
MemoryContext child; |
|
|
|
int ichild; |
|
|
|
int ichild; |
|
|
|
|
|
|
|
|
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
|
|
|
|
|
|
|
|
/* Examine the context itself */ |
|
|
|
/* Examine the context itself */ |
|
|
|
context->methods->stats(context, |
|
|
|
context->methods->stats(context, |
|
|
|
@ -902,7 +902,7 @@ MemoryContextCheck(MemoryContext context) |
|
|
|
{ |
|
|
|
{ |
|
|
|
MemoryContext child; |
|
|
|
MemoryContext child; |
|
|
|
|
|
|
|
|
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
|
|
|
|
|
|
|
|
context->methods->check(context); |
|
|
|
context->methods->check(context); |
|
|
|
for (child = context->firstchild; child != NULL; child = child->nextchild) |
|
|
|
for (child = context->firstchild; child != NULL; child = child->nextchild) |
|
|
|
@ -995,7 +995,7 @@ MemoryContextAlloc(MemoryContext context, Size size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
void *ret; |
|
|
|
void *ret; |
|
|
|
|
|
|
|
|
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
|
|
|
|
|
|
|
|
if (!AllocSizeIsValid(size)) |
|
|
|
if (!AllocSizeIsValid(size)) |
|
|
|
@ -1038,7 +1038,7 @@ MemoryContextAllocZero(MemoryContext context, Size size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
void *ret; |
|
|
|
void *ret; |
|
|
|
|
|
|
|
|
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
|
|
|
|
|
|
|
|
if (!AllocSizeIsValid(size)) |
|
|
|
if (!AllocSizeIsValid(size)) |
|
|
|
@ -1076,7 +1076,7 @@ MemoryContextAllocZeroAligned(MemoryContext context, Size size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
void *ret; |
|
|
|
void *ret; |
|
|
|
|
|
|
|
|
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
|
|
|
|
|
|
|
|
if (!AllocSizeIsValid(size)) |
|
|
|
if (!AllocSizeIsValid(size)) |
|
|
|
@ -1111,7 +1111,7 @@ MemoryContextAllocExtended(MemoryContext context, Size size, int flags) |
|
|
|
{ |
|
|
|
{ |
|
|
|
void *ret; |
|
|
|
void *ret; |
|
|
|
|
|
|
|
|
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
|
|
|
|
|
|
|
|
if (!((flags & MCXT_ALLOC_HUGE) != 0 ? AllocHugeSizeIsValid(size) : |
|
|
|
if (!((flags & MCXT_ALLOC_HUGE) != 0 ? AllocHugeSizeIsValid(size) : |
|
|
|
@ -1202,7 +1202,7 @@ palloc(Size size) |
|
|
|
void *ret; |
|
|
|
void *ret; |
|
|
|
MemoryContext context = CurrentMemoryContext; |
|
|
|
MemoryContext context = CurrentMemoryContext; |
|
|
|
|
|
|
|
|
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
|
|
|
|
|
|
|
|
if (!AllocSizeIsValid(size)) |
|
|
|
if (!AllocSizeIsValid(size)) |
|
|
|
@ -1233,7 +1233,7 @@ palloc0(Size size) |
|
|
|
void *ret; |
|
|
|
void *ret; |
|
|
|
MemoryContext context = CurrentMemoryContext; |
|
|
|
MemoryContext context = CurrentMemoryContext; |
|
|
|
|
|
|
|
|
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
|
|
|
|
|
|
|
|
if (!AllocSizeIsValid(size)) |
|
|
|
if (!AllocSizeIsValid(size)) |
|
|
|
@ -1266,7 +1266,7 @@ palloc_extended(Size size, int flags) |
|
|
|
void *ret; |
|
|
|
void *ret; |
|
|
|
MemoryContext context = CurrentMemoryContext; |
|
|
|
MemoryContext context = CurrentMemoryContext; |
|
|
|
|
|
|
|
|
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
|
|
|
|
|
|
|
|
if (!((flags & MCXT_ALLOC_HUGE) != 0 ? AllocHugeSizeIsValid(size) : |
|
|
|
if (!((flags & MCXT_ALLOC_HUGE) != 0 ? AllocHugeSizeIsValid(size) : |
|
|
|
@ -1406,7 +1406,7 @@ MemoryContextAllocHuge(MemoryContext context, Size size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
void *ret; |
|
|
|
void *ret; |
|
|
|
|
|
|
|
|
|
|
|
AssertArg(MemoryContextIsValid(context)); |
|
|
|
Assert(MemoryContextIsValid(context)); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
AssertNotInCriticalSection(context); |
|
|
|
|
|
|
|
|
|
|
|
if (!AllocHugeSizeIsValid(size)) |
|
|
|
if (!AllocHugeSizeIsValid(size)) |
|
|
|
|