Header And Logo

PostgreSQL
| The world's most advanced open source database.

resowner.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * resowner.h
00004  *    POSTGRES resource owner definitions.
00005  *
00006  * Query-lifespan resources are tracked by associating them with
00007  * ResourceOwner objects.  This provides a simple mechanism for ensuring
00008  * that such resources are freed at the right time.
00009  * See utils/resowner/README for more info.
00010  *
00011  *
00012  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00013  * Portions Copyright (c) 1994, Regents of the University of California
00014  *
00015  * src/include/utils/resowner.h
00016  *
00017  *-------------------------------------------------------------------------
00018  */
00019 #ifndef RESOWNER_H
00020 #define RESOWNER_H
00021 
00022 
00023 /*
00024  * ResourceOwner objects are an opaque data structure known only within
00025  * resowner.c.
00026  */
00027 typedef struct ResourceOwnerData *ResourceOwner;
00028 
00029 
00030 /*
00031  * Globally known ResourceOwners
00032  */
00033 extern PGDLLIMPORT ResourceOwner CurrentResourceOwner;
00034 extern PGDLLIMPORT ResourceOwner CurTransactionResourceOwner;
00035 extern PGDLLIMPORT ResourceOwner TopTransactionResourceOwner;
00036 
00037 /*
00038  * Resource releasing is done in three phases: pre-locks, locks, and
00039  * post-locks.  The pre-lock phase must release any resources that are
00040  * visible to other backends (such as pinned buffers); this ensures that
00041  * when we release a lock that another backend may be waiting on, it will
00042  * see us as being fully out of our transaction.  The post-lock phase
00043  * should be used for backend-internal cleanup.
00044  */
00045 typedef enum
00046 {
00047     RESOURCE_RELEASE_BEFORE_LOCKS,
00048     RESOURCE_RELEASE_LOCKS,
00049     RESOURCE_RELEASE_AFTER_LOCKS
00050 } ResourceReleasePhase;
00051 
00052 /*
00053  *  Dynamically loaded modules can get control during ResourceOwnerRelease
00054  *  by providing a callback of this form.
00055  */
00056 typedef void (*ResourceReleaseCallback) (ResourceReleasePhase phase,
00057                                                      bool isCommit,
00058                                                      bool isTopLevel,
00059                                                      void *arg);
00060 
00061 
00062 /*
00063  * Functions in resowner.c
00064  */
00065 
00066 /* generic routines */
00067 extern ResourceOwner ResourceOwnerCreate(ResourceOwner parent,
00068                     const char *name);
00069 extern void ResourceOwnerRelease(ResourceOwner owner,
00070                      ResourceReleasePhase phase,
00071                      bool isCommit,
00072                      bool isTopLevel);
00073 extern void ResourceOwnerDelete(ResourceOwner owner);
00074 extern ResourceOwner ResourceOwnerGetParent(ResourceOwner owner);
00075 extern void ResourceOwnerNewParent(ResourceOwner owner,
00076                        ResourceOwner newparent);
00077 extern void RegisterResourceReleaseCallback(ResourceReleaseCallback callback,
00078                                 void *arg);
00079 extern void UnregisterResourceReleaseCallback(ResourceReleaseCallback callback,
00080                                   void *arg);
00081 
00082 #endif   /* RESOWNER_H */