PostgreSQL Source Code  git master
resowner.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct ResourceOwnerDataResourceOwner
 
typedef void(* ResourceReleaseCallback) (ResourceReleasePhase phase, bool isCommit, bool isTopLevel, void *arg)
 

Enumerations

enum  ResourceReleasePhase { RESOURCE_RELEASE_BEFORE_LOCKS, RESOURCE_RELEASE_LOCKS, RESOURCE_RELEASE_AFTER_LOCKS }
 

Functions

ResourceOwner ResourceOwnerCreate (ResourceOwner parent, const char *name)
 
void ResourceOwnerRelease (ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
 
void ResourceOwnerDelete (ResourceOwner owner)
 
ResourceOwner ResourceOwnerGetParent (ResourceOwner owner)
 
void ResourceOwnerNewParent (ResourceOwner owner, ResourceOwner newparent)
 
void RegisterResourceReleaseCallback (ResourceReleaseCallback callback, void *arg)
 
void UnregisterResourceReleaseCallback (ResourceReleaseCallback callback, void *arg)
 

Variables

PGDLLIMPORT ResourceOwner CurrentResourceOwner
 
PGDLLIMPORT ResourceOwner CurTransactionResourceOwner
 
PGDLLIMPORT ResourceOwner TopTransactionResourceOwner
 

Typedef Documentation

◆ ResourceOwner

Definition at line 27 of file resowner.h.

◆ ResourceReleaseCallback

typedef void(* ResourceReleaseCallback) (ResourceReleasePhase phase, bool isCommit, bool isTopLevel, void *arg)

Definition at line 56 of file resowner.h.

Enumeration Type Documentation

◆ ResourceReleasePhase

Enumerator
RESOURCE_RELEASE_BEFORE_LOCKS 
RESOURCE_RELEASE_LOCKS 
RESOURCE_RELEASE_AFTER_LOCKS 

Definition at line 45 of file resowner.h.

Function Documentation

◆ RegisterResourceReleaseCallback()

void RegisterResourceReleaseCallback ( ResourceReleaseCallback  callback,
void *  arg 
)

Definition at line 792 of file resowner.c.

References arg, ResourceReleaseCallbackItem::arg, callback(), ResourceReleaseCallbackItem::callback, MemoryContextAlloc(), ResourceReleaseCallbackItem::next, ResourceRelease_callbacks, and TopMemoryContext.

Referenced by px_find_cipher(), and px_find_digest().

793 {
795 
796  item = (ResourceReleaseCallbackItem *)
799  item->callback = callback;
800  item->arg = arg;
803 }
static ResourceReleaseCallbackItem * ResourceRelease_callbacks
Definition: resowner.c:154
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
MemoryContext TopMemoryContext
Definition: mcxt.c:44
struct ResourceReleaseCallbackItem * next
Definition: resowner.c:149
ResourceReleaseCallback callback
Definition: resowner.c:150
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:771
void * arg

◆ ResourceOwnerCreate()

ResourceOwner ResourceOwnerCreate ( ResourceOwner  parent,
const char *  name 
)

Definition at line 418 of file resowner.c.

References ResourceOwnerData::bufferarr, BufferGetDatum, ResourceOwnerData::catlistrefarr, ResourceOwnerData::catrefarr, ResourceOwnerData::dsmarr, ResourceOwnerData::filearr, FileGetDatum, ResourceOwnerData::firstchild, InvalidBuffer, ResourceOwnerData::jitarr, MemoryContextAllocZero(), ResourceOwnerData::name, name, ResourceOwnerData::nextchild, ResourceOwnerData::parent, ResourceOwnerData::planrefarr, PointerGetDatum, ResourceOwnerData::relrefarr, ResourceArrayInit(), ResourceOwnerData::snapshotarr, TopMemoryContext, and ResourceOwnerData::tupdescarr.

Referenced by ApplyWorkerMain(), AtStart_ResourceOwner(), AtSubStart_ResourceOwner(), BackgroundWriterMain(), CheckpointerMain(), CreatePortal(), ParallelWorkerMain(), pg_logical_replication_slot_advance(), pg_logical_slot_get_changes_guts(), test_shm_mq_main(), WalReceiverMain(), and WalWriterMain().

419 {
420  ResourceOwner owner;
421 
423  sizeof(ResourceOwnerData));
424  owner->name = name;
425 
426  if (parent)
427  {
428  owner->parent = parent;
429  owner->nextchild = parent->firstchild;
430  parent->firstchild = owner;
431  }
432 
434  ResourceArrayInit(&(owner->catrefarr), PointerGetDatum(NULL));
436  ResourceArrayInit(&(owner->relrefarr), PointerGetDatum(NULL));
437  ResourceArrayInit(&(owner->planrefarr), PointerGetDatum(NULL));
438  ResourceArrayInit(&(owner->tupdescarr), PointerGetDatum(NULL));
440  ResourceArrayInit(&(owner->filearr), FileGetDatum(-1));
441  ResourceArrayInit(&(owner->dsmarr), PointerGetDatum(NULL));
442  ResourceArrayInit(&(owner->jitarr), PointerGetDatum(NULL));
443 
444  return owner;
445 }
ResourceArray relrefarr
Definition: resowner.c:122
ResourceArray catrefarr
Definition: resowner.c:120
#define PointerGetDatum(X)
Definition: postgres.h:541
#define InvalidBuffer
Definition: buf.h:25
ResourceArray bufferarr
Definition: resowner.c:119
ResourceArray snapshotarr
Definition: resowner.c:125
struct ResourceOwnerData * ResourceOwner
Definition: resowner.h:27
const char * name
Definition: resowner.c:116
ResourceArray planrefarr
Definition: resowner.c:123
ResourceArray tupdescarr
Definition: resowner.c:124
static void ResourceArrayInit(ResourceArray *resarr, Datum invalidval)
Definition: resowner.c:185
MemoryContext TopMemoryContext
Definition: mcxt.c:44
ResourceOwner firstchild
Definition: resowner.c:114
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:814
#define BufferGetDatum(buffer)
Definition: resowner.c:42
#define FileGetDatum(file)
Definition: resowner.c:40
ResourceArray jitarr
Definition: resowner.c:128
ResourceOwner parent
Definition: resowner.c:113
const char * name
Definition: encode.c:521
ResourceArray catlistrefarr
Definition: resowner.c:121
ResourceArray dsmarr
Definition: resowner.c:127
ResourceOwner nextchild
Definition: resowner.c:115
ResourceArray filearr
Definition: resowner.c:126

◆ ResourceOwnerDelete()

void ResourceOwnerDelete ( ResourceOwner  owner)

Definition at line 684 of file resowner.c.

References Assert, ResourceOwnerData::bufferarr, ResourceOwnerData::catlistrefarr, ResourceOwnerData::catrefarr, ResourceOwnerData::dsmarr, ResourceOwnerData::filearr, ResourceOwnerData::firstchild, ResourceOwnerData::jitarr, MAX_RESOWNER_LOCKS, ResourceArray::nitems, ResourceOwnerData::nlocks, pfree(), ResourceOwnerData::planrefarr, ResourceOwnerData::relrefarr, ResourceArrayFree(), ResourceOwnerDelete(), ResourceOwnerNewParent(), ResourceOwnerData::snapshotarr, and ResourceOwnerData::tupdescarr.

Referenced by CleanupSubTransaction(), CleanupTransaction(), CommitSubTransaction(), CommitTransaction(), PortalDrop(), PrepareTransaction(), and ResourceOwnerDelete().

685 {
686  /* We had better not be deleting CurrentResourceOwner ... */
687  Assert(owner != CurrentResourceOwner);
688 
689  /* And it better not own any resources, either */
690  Assert(owner->bufferarr.nitems == 0);
691  Assert(owner->catrefarr.nitems == 0);
692  Assert(owner->catlistrefarr.nitems == 0);
693  Assert(owner->relrefarr.nitems == 0);
694  Assert(owner->planrefarr.nitems == 0);
695  Assert(owner->tupdescarr.nitems == 0);
696  Assert(owner->snapshotarr.nitems == 0);
697  Assert(owner->filearr.nitems == 0);
698  Assert(owner->dsmarr.nitems == 0);
699  Assert(owner->jitarr.nitems == 0);
700  Assert(owner->nlocks == 0 || owner->nlocks == MAX_RESOWNER_LOCKS + 1);
701 
702  /*
703  * Delete children. The recursive call will delink the child from me, so
704  * just iterate as long as there is a child.
705  */
706  while (owner->firstchild != NULL)
708 
709  /*
710  * We delink the owner from its parent before deleting it, so that if
711  * there's an error we won't have deleted/busted owners still attached to
712  * the owner tree. Better a leak than a crash.
713  */
714  ResourceOwnerNewParent(owner, NULL);
715 
716  /* And free the object. */
717  ResourceArrayFree(&(owner->bufferarr));
718  ResourceArrayFree(&(owner->catrefarr));
719  ResourceArrayFree(&(owner->catlistrefarr));
720  ResourceArrayFree(&(owner->relrefarr));
721  ResourceArrayFree(&(owner->planrefarr));
722  ResourceArrayFree(&(owner->tupdescarr));
723  ResourceArrayFree(&(owner->snapshotarr));
724  ResourceArrayFree(&(owner->filearr));
725  ResourceArrayFree(&(owner->dsmarr));
726  ResourceArrayFree(&(owner->jitarr));
727 
728  pfree(owner);
729 }
ResourceArray relrefarr
Definition: resowner.c:122
ResourceArray catrefarr
Definition: resowner.c:120
ResourceOwner CurrentResourceOwner
Definition: resowner.c:140
void ResourceOwnerDelete(ResourceOwner owner)
Definition: resowner.c:684
ResourceArray bufferarr
Definition: resowner.c:119
ResourceArray snapshotarr
Definition: resowner.c:125
#define MAX_RESOWNER_LOCKS
Definition: resowner.c:106
void pfree(void *pointer)
Definition: mcxt.c:1031
ResourceArray planrefarr
Definition: resowner.c:123
static void ResourceArrayFree(ResourceArray *resarr)
Definition: resowner.c:398
ResourceArray tupdescarr
Definition: resowner.c:124
ResourceOwner firstchild
Definition: resowner.c:114
#define Assert(condition)
Definition: c.h:699
ResourceArray jitarr
Definition: resowner.c:128
void ResourceOwnerNewParent(ResourceOwner owner, ResourceOwner newparent)
Definition: resowner.c:744
ResourceArray catlistrefarr
Definition: resowner.c:121
ResourceArray dsmarr
Definition: resowner.c:127
uint32 nitems
Definition: resowner.c:66
ResourceArray filearr
Definition: resowner.c:126

◆ ResourceOwnerGetParent()

ResourceOwner ResourceOwnerGetParent ( ResourceOwner  owner)

Definition at line 735 of file resowner.c.

References ResourceOwnerData::parent.

Referenced by LockReassignCurrentOwner().

736 {
737  return owner->parent;
738 }
ResourceOwner parent
Definition: resowner.c:113

◆ ResourceOwnerNewParent()

void ResourceOwnerNewParent ( ResourceOwner  owner,
ResourceOwner  newparent 
)

Definition at line 744 of file resowner.c.

References Assert, ResourceOwnerData::firstchild, ResourceOwnerData::nextchild, and ResourceOwnerData::parent.

Referenced by AtSubAbort_Portals(), AtSubCommit_Portals(), and ResourceOwnerDelete().

746 {
747  ResourceOwner oldparent = owner->parent;
748 
749  if (oldparent)
750  {
751  if (owner == oldparent->firstchild)
752  oldparent->firstchild = owner->nextchild;
753  else
754  {
755  ResourceOwner child;
756 
757  for (child = oldparent->firstchild; child; child = child->nextchild)
758  {
759  if (owner == child->nextchild)
760  {
761  child->nextchild = owner->nextchild;
762  break;
763  }
764  }
765  }
766  }
767 
768  if (newparent)
769  {
770  Assert(owner != newparent);
771  owner->parent = newparent;
772  owner->nextchild = newparent->firstchild;
773  newparent->firstchild = owner;
774  }
775  else
776  {
777  owner->parent = NULL;
778  owner->nextchild = NULL;
779  }
780 }
ResourceOwner firstchild
Definition: resowner.c:114
#define Assert(condition)
Definition: c.h:699
ResourceOwner parent
Definition: resowner.c:113
ResourceOwner nextchild
Definition: resowner.c:115

◆ ResourceOwnerRelease()

void ResourceOwnerRelease ( ResourceOwner  owner,
ResourceReleasePhase  phase,
bool  isCommit,
bool  isTopLevel 
)

Definition at line 474 of file resowner.c.

References ResourceOwnerReleaseInternal().

Referenced by AbortSubTransaction(), AbortTransaction(), AutoVacLauncherMain(), BackgroundWriterMain(), CheckpointerMain(), CommitSubTransaction(), CommitTransaction(), PortalDrop(), PrepareTransaction(), and WalWriterMain().

478 {
479  /* There's not currently any setup needed before recursing */
480  ResourceOwnerReleaseInternal(owner, phase, isCommit, isTopLevel);
481 }
static void ResourceOwnerReleaseInternal(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
Definition: resowner.c:484

◆ UnregisterResourceReleaseCallback()

void UnregisterResourceReleaseCallback ( ResourceReleaseCallback  callback,
void *  arg 
)

Definition at line 806 of file resowner.c.

References ResourceReleaseCallbackItem::next, and pfree().

807 {
810 
811  prev = NULL;
812  for (item = ResourceRelease_callbacks; item; prev = item, item = item->next)
813  {
814  if (item->callback == callback && item->arg == arg)
815  {
816  if (prev)
817  prev->next = item->next;
818  else
820  pfree(item);
821  break;
822  }
823  }
824 }
static ResourceReleaseCallbackItem * ResourceRelease_callbacks
Definition: resowner.c:154
void pfree(void *pointer)
Definition: mcxt.c:1031
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
struct ResourceReleaseCallbackItem * next
Definition: resowner.c:149
void * arg

Variable Documentation

◆ CurrentResourceOwner

PGDLLIMPORT ResourceOwner CurrentResourceOwner

Definition at line 140 of file resowner.c.

Referenced by ApplyWorkerMain(), AssignTransactionId(), AtAbort_ResourceOwner(), AtStart_ResourceOwner(), AtSubAbort_ResourceOwner(), AtSubStart_ResourceOwner(), AutoVacLauncherMain(), BackgroundWriterMain(), BgBufferSync(), BufferSync(), BufFileCreateShared(), BufFileOpenShared(), CheckpointerMain(), cipher_free_callback(), CleanupSubTransaction(), CleanupTransaction(), close_lo_relation(), CommitSubTransaction(), CommitTransaction(), DecrTupleDescRefCount(), digest_free_callback(), dsm_create_descriptor(), dsm_unpin_mapping(), exec_init_tuple_store(), exec_stmt_block(), extendBufFile(), FlushDatabaseBuffers(), FlushRelationBuffers(), GetCachedPlan(), GetCurrentFDWTuplestore(), IncrBufferRefCount(), IncrTupleDescRefCount(), llvm_create_context(), LocalBufferAlloc(), lock_and_open_sequence(), LockAcquireExtended(), LockReassignCurrentOwner(), LockReassignOwner(), LockRelease(), makeBufFile(), MakeTransitionCaptureState(), open_lo_relation(), OpenTemporaryFile(), ParallelWorkerMain(), PathNameCreateTemporaryFile(), PathNameOpenTemporaryFile(), PersistHoldablePortal(), pg_logical_replication_slot_advance(), pg_logical_slot_get_changes_guts(), PinBuffer(), PinBuffer_Locked(), plperl_spi_exec(), plperl_spi_exec_prepared(), plperl_spi_fetchrow(), plperl_spi_prepare(), plperl_spi_query(), plperl_spi_query_prepared(), plpgsql_estate_setup(), pltcl_func_handler(), pltcl_init_tuple_store(), pltcl_returnnext(), pltcl_SPI_execute(), pltcl_SPI_execute_plan(), pltcl_SPI_prepare(), pltcl_subtrans_abort(), pltcl_subtrans_commit(), pltcl_subtransaction(), PLy_abort_open_subtransactions(), PLy_cursor_fetch(), PLy_cursor_iternext(), PLy_cursor_plan(), PLy_cursor_query(), PLy_spi_execute_plan(), PLy_spi_execute_query(), PLy_spi_prepare(), PLy_spi_subtransaction_abort(), PLy_spi_subtransaction_commit(), PLy_subtransaction_enter(), PLy_subtransaction_exit(), PopTransaction(), PortalCleanup(), PortalRun(), PortalRunFetch(), PortalStart(), PrepareTransaction(), px_find_cipher(), px_find_digest(), ReadBuffer_common(), RegisterSnapshot(), RegisterTemporaryFile(), RelationDecrementReferenceCount(), RelationIncrementReferenceCount(), ReleaseAndReadBuffer(), ReleaseBuffer(), ReleaseCachedPlan(), ReleaseCatCache(), ReleaseCatCacheList(), ReleaseLockIfHeld(), ResourceOwnerReleaseInternal(), SearchCatCacheInternal(), SearchCatCacheList(), SearchCatCacheMiss(), SnapBuildClearExportedSnapshot(), SnapBuildExportSnapshot(), test_shm_mq_main(), tuplestore_begin_common(), tuplestore_puttuple_common(), UnpinBuffer(), UnregisterSnapshot(), WalReceiverMain(), and WalWriterMain().

◆ CurTransactionResourceOwner

◆ TopTransactionResourceOwner