resowner.h 4.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/*-------------------------------------------------------------------------
 *
 * resowner.h
 *	  POSTGRES resource owner definitions.
 *
 * Query-lifespan resources are tracked by associating them with
 * ResourceOwner objects.  This provides a simple mechanism for ensuring
 * that such resources are freed at the right time.
 * See utils/resowner/README for more info.
 *
 *
12
 * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
13 14
 * Portions Copyright (c) 1994, Regents of the University of California
 *
15
 * $PostgreSQL: pgsql/src/include/utils/resowner.h,v 1.11 2007/03/13 00:33:43 tgl Exp $
16 17 18 19 20 21 22 23
 *
 *-------------------------------------------------------------------------
 */
#ifndef RESOWNER_H
#define RESOWNER_H

#include "storage/buf.h"
#include "utils/catcache.h"
24
#include "utils/plancache.h"
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42


/*
 * ResourceOwner objects are an opaque data structure known only within
 * resowner.c.
 */
typedef struct ResourceOwnerData *ResourceOwner;


/*
 * Globally known ResourceOwners
 */
extern DLLIMPORT ResourceOwner CurrentResourceOwner;
extern DLLIMPORT ResourceOwner CurTransactionResourceOwner;
extern DLLIMPORT ResourceOwner TopTransactionResourceOwner;

/*
 * Resource releasing is done in three phases: pre-locks, locks, and
Bruce Momjian's avatar
Bruce Momjian committed
43
 * post-locks.	The pre-lock phase must release any resources that are
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
 * visible to other backends (such as pinned buffers); this ensures that
 * when we release a lock that another backend may be waiting on, it will
 * see us as being fully out of our transaction.  The post-lock phase
 * should be used for backend-internal cleanup.
 */
typedef enum
{
	RESOURCE_RELEASE_BEFORE_LOCKS,
	RESOURCE_RELEASE_LOCKS,
	RESOURCE_RELEASE_AFTER_LOCKS
} ResourceReleasePhase;

/*
 *	Dynamically loaded modules can get control during ResourceOwnerRelease
 *	by providing a callback of this form.
 */
typedef void (*ResourceReleaseCallback) (ResourceReleasePhase phase,
Bruce Momjian's avatar
Bruce Momjian committed
61 62 63
													 bool isCommit,
													 bool isTopLevel,
													 void *arg);
64 65 66 67 68 69 70 71


/*
 * Functions in resowner.c
 */

/* generic routines */
extern ResourceOwner ResourceOwnerCreate(ResourceOwner parent,
Bruce Momjian's avatar
Bruce Momjian committed
72
					const char *name);
73
extern void ResourceOwnerRelease(ResourceOwner owner,
Bruce Momjian's avatar
Bruce Momjian committed
74 75 76
					 ResourceReleasePhase phase,
					 bool isCommit,
					 bool isTopLevel);
77
extern void ResourceOwnerDelete(ResourceOwner owner);
78
extern ResourceOwner ResourceOwnerGetParent(ResourceOwner owner);
79
extern void ResourceOwnerNewParent(ResourceOwner owner,
Bruce Momjian's avatar
Bruce Momjian committed
80
					   ResourceOwner newparent);
81
extern void RegisterResourceReleaseCallback(ResourceReleaseCallback callback,
Bruce Momjian's avatar
Bruce Momjian committed
82
								void *arg);
83
extern void UnregisterResourceReleaseCallback(ResourceReleaseCallback callback,
Bruce Momjian's avatar
Bruce Momjian committed
84
								  void *arg);
85 86 87 88 89 90 91 92 93

/* support for buffer refcount management */
extern void ResourceOwnerEnlargeBuffers(ResourceOwner owner);
extern void ResourceOwnerRememberBuffer(ResourceOwner owner, Buffer buffer);
extern void ResourceOwnerForgetBuffer(ResourceOwner owner, Buffer buffer);

/* support for catcache refcount management */
extern void ResourceOwnerEnlargeCatCacheRefs(ResourceOwner owner);
extern void ResourceOwnerRememberCatCacheRef(ResourceOwner owner,
Bruce Momjian's avatar
Bruce Momjian committed
94
								 HeapTuple tuple);
95
extern void ResourceOwnerForgetCatCacheRef(ResourceOwner owner,
Bruce Momjian's avatar
Bruce Momjian committed
96
							   HeapTuple tuple);
97 98
extern void ResourceOwnerEnlargeCatCacheListRefs(ResourceOwner owner);
extern void ResourceOwnerRememberCatCacheListRef(ResourceOwner owner,
Bruce Momjian's avatar
Bruce Momjian committed
99
									 CatCList *list);
100
extern void ResourceOwnerForgetCatCacheListRef(ResourceOwner owner,
Bruce Momjian's avatar
Bruce Momjian committed
101
								   CatCList *list);
102 103 104 105

/* support for relcache refcount management */
extern void ResourceOwnerEnlargeRelationRefs(ResourceOwner owner);
extern void ResourceOwnerRememberRelationRef(ResourceOwner owner,
Bruce Momjian's avatar
Bruce Momjian committed
106
								 Relation rel);
107
extern void ResourceOwnerForgetRelationRef(ResourceOwner owner,
Bruce Momjian's avatar
Bruce Momjian committed
108
							   Relation rel);
109

110 111 112 113 114 115 116
/* support for plancache refcount management */
extern void ResourceOwnerEnlargePlanCacheRefs(ResourceOwner owner);
extern void ResourceOwnerRememberPlanCacheRef(ResourceOwner owner,
											  CachedPlan *plan);
extern void ResourceOwnerForgetPlanCacheRef(ResourceOwner owner,
											CachedPlan *plan);

117 118 119
/* support for tupledesc refcount management */
extern void ResourceOwnerEnlargeTupleDescs(ResourceOwner owner);
extern void ResourceOwnerRememberTupleDesc(ResourceOwner owner,
Bruce Momjian's avatar
Bruce Momjian committed
120
							   TupleDesc tupdesc);
121
extern void ResourceOwnerForgetTupleDesc(ResourceOwner owner,
Bruce Momjian's avatar
Bruce Momjian committed
122
							 TupleDesc tupdesc);
123

124
#endif   /* RESOWNER_H */