PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

Definition at line 27 of file resowner.h.

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

Definition at line 56 of file resowner.h.

Enumeration Type Documentation

Enumerator
RESOURCE_RELEASE_BEFORE_LOCKS 
RESOURCE_RELEASE_LOCKS 
RESOURCE_RELEASE_AFTER_LOCKS 

Definition at line 45 of file resowner.h.

Function Documentation

void RegisterResourceReleaseCallback ( ResourceReleaseCallback  callback,
void *  arg 
)

Definition at line 793 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().

794 {
796 
797  item = (ResourceReleaseCallbackItem *)
800  item->callback = callback;
801  item->arg = arg;
804 }
static ResourceReleaseCallbackItem * ResourceRelease_callbacks
Definition: resowner.c:152
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
MemoryContext TopMemoryContext
Definition: mcxt.c:43
struct ResourceReleaseCallbackItem * next
Definition: resowner.c:147
ResourceReleaseCallback callback
Definition: resowner.c:148
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:707
void * arg
ResourceOwner ResourceOwnerCreate ( ResourceOwner  parent,
const char *  name 
)

Definition at line 416 of file resowner.c.

References ResourceOwnerData::bufferarr, BufferGetDatum, ResourceOwnerData::catlistrefarr, ResourceOwnerData::catrefarr, ResourceOwnerData::dsmarr, ResourceOwnerData::filearr, FileGetDatum, ResourceOwnerData::firstchild, InvalidBuffer, MemoryContextAllocZero(), ResourceOwnerData::name, name, ResourceOwnerData::nextchild, NULL, 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_slot_get_changes_guts(), test_shm_mq_main(), WalReceiverMain(), WalSndShutdown(), and WalWriterMain().

417 {
418  ResourceOwner owner;
419 
421  sizeof(ResourceOwnerData));
422  owner->name = name;
423 
424  if (parent)
425  {
426  owner->parent = parent;
427  owner->nextchild = parent->firstchild;
428  parent->firstchild = owner;
429  }
430 
438  ResourceArrayInit(&(owner->filearr), FileGetDatum(-1));
440 
441  return owner;
442 }
ResourceArray relrefarr
Definition: resowner.c:121
ResourceArray catrefarr
Definition: resowner.c:119
#define PointerGetDatum(X)
Definition: postgres.h:562
#define InvalidBuffer
Definition: buf.h:25
ResourceArray bufferarr
Definition: resowner.c:118
ResourceArray snapshotarr
Definition: resowner.c:124
struct ResourceOwnerData * ResourceOwner
Definition: resowner.h:27
const char * name
Definition: resowner.c:115
ResourceArray planrefarr
Definition: resowner.c:122
ResourceArray tupdescarr
Definition: resowner.c:123
static void ResourceArrayInit(ResourceArray *resarr, Datum invalidval)
Definition: resowner.c:183
MemoryContext TopMemoryContext
Definition: mcxt.c:43
ResourceOwner firstchild
Definition: resowner.c:113
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:742
#define BufferGetDatum(buffer)
Definition: resowner.c:41
#define FileGetDatum(file)
Definition: resowner.c:39
#define NULL
Definition: c.h:229
ResourceOwner parent
Definition: resowner.c:112
const char * name
Definition: encode.c:521
ResourceArray catlistrefarr
Definition: resowner.c:120
ResourceArray dsmarr
Definition: resowner.c:126
ResourceOwner nextchild
Definition: resowner.c:114
ResourceArray filearr
Definition: resowner.c:125
void ResourceOwnerDelete ( ResourceOwner  owner)

Definition at line 687 of file resowner.c.

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

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

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

Definition at line 736 of file resowner.c.

References ResourceOwnerData::parent.

Referenced by LockReassignCurrentOwner().

737 {
738  return owner->parent;
739 }
ResourceOwner parent
Definition: resowner.c:112
void ResourceOwnerNewParent ( ResourceOwner  owner,
ResourceOwner  newparent 
)

Definition at line 745 of file resowner.c.

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

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

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

Definition at line 471 of file resowner.c.

References CurrentResourceOwner, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, and ResourceOwnerReleaseInternal().

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

475 {
476  /* Rather than PG_TRY at every level of recursion, set it up once */
477  ResourceOwner save;
478 
479  save = CurrentResourceOwner;
480  PG_TRY();
481  {
482  ResourceOwnerReleaseInternal(owner, phase, isCommit, isTopLevel);
483  }
484  PG_CATCH();
485  {
486  CurrentResourceOwner = save;
487  PG_RE_THROW();
488  }
489  PG_END_TRY();
490  CurrentResourceOwner = save;
491 }
ResourceOwner CurrentResourceOwner
Definition: resowner.c:138
static void ResourceOwnerReleaseInternal(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
Definition: resowner.c:494
#define PG_CATCH()
Definition: elog.h:293
#define PG_RE_THROW()
Definition: elog.h:314
#define PG_TRY()
Definition: elog.h:284
#define PG_END_TRY()
Definition: elog.h:300
void UnregisterResourceReleaseCallback ( ResourceReleaseCallback  callback,
void *  arg 
)

Definition at line 807 of file resowner.c.

References ResourceReleaseCallbackItem::next, NULL, and pfree().

808 {
811 
812  prev = NULL;
813  for (item = ResourceRelease_callbacks; item; prev = item, item = item->next)
814  {
815  if (item->callback == callback && item->arg == arg)
816  {
817  if (prev)
818  prev->next = item->next;
819  else
821  pfree(item);
822  break;
823  }
824  }
825 }
static ResourceReleaseCallbackItem * ResourceRelease_callbacks
Definition: resowner.c:152
void pfree(void *pointer)
Definition: mcxt.c:950
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
struct ResourceReleaseCallbackItem * next
Definition: resowner.c:147
#define NULL
Definition: c.h:229
void * arg

Variable Documentation

PGDLLIMPORT ResourceOwner CurrentResourceOwner

Definition at line 138 of file resowner.c.

Referenced by ApplyWorkerMain(), AssignTransactionId(), AtAbort_ResourceOwner(), AtStart_ResourceOwner(), AtSubAbort_ResourceOwner(), AtSubStart_ResourceOwner(), BackgroundWriterMain(), BgBufferSync(), BufferSync(), 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(), GetTriggerTransitionTuplestore(), IncrBufferRefCount(), IncrTupleDescRefCount(), LocalBufferAlloc(), lock_and_open_sequence(), LockAcquireExtended(), LockReassignCurrentOwner(), LockReassignOwner(), LockRelease(), makeBufFile(), open_lo_relation(), OpenTemporaryFile(), ParallelWorkerMain(), PersistHoldablePortal(), 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(), RelationDecrementReferenceCount(), RelationIncrementReferenceCount(), ReleaseAndReadBuffer(), ReleaseBuffer(), ReleaseCachedPlan(), ReleaseCatCache(), ReleaseCatCacheList(), ReleaseLockIfHeld(), ResourceOwnerRelease(), ResourceOwnerReleaseInternal(), SearchCatCache(), SearchCatCacheList(), SnapBuildClearExportedSnapshot(), SnapBuildExportSnapshot(), test_shm_mq_main(), tuplestore_begin_common(), tuplestore_puttuple_common(), UnpinBuffer(), UnregisterSnapshot(), WalReceiverMain(), WalSndShutdown(), and WalWriterMain().