| 1 | /*------------------------------------------------------------------------- |
| 2 | * |
| 3 | * resowner.h |
| 4 | * POSTGRES resource owner definitions. |
| 5 | * |
| 6 | * Query-lifespan resources are tracked by associating them with |
| 7 | * ResourceOwner objects. This provides a simple mechanism for ensuring |
| 8 | * that such resources are freed at the right time. |
| 9 | * See utils/resowner/README for more info. |
| 10 | * |
| 11 | * |
| 12 | * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group |
| 13 | * Portions Copyright (c) 1994, Regents of the University of California |
| 14 | * |
| 15 | * src/include/utils/resowner.h |
| 16 | * |
| 17 | *------------------------------------------------------------------------- |
| 18 | */ |
| 19 | #ifndef RESOWNER_H |
| 20 | #define RESOWNER_H |
| 21 | |
| 22 | |
| 23 | /* |
| 24 | * ResourceOwner objects are an opaque data structure known only within |
| 25 | * resowner.c. |
| 26 | */ |
| 27 | typedef struct ResourceOwnerData *ResourceOwner; |
| 28 | |
| 29 | |
| 30 | /* |
| 31 | * Globally known ResourceOwners |
| 32 | */ |
| 33 | extern PGDLLIMPORT ResourceOwner CurrentResourceOwner; |
| 34 | extern PGDLLIMPORT ResourceOwner CurTransactionResourceOwner; |
| 35 | extern PGDLLIMPORT ResourceOwner TopTransactionResourceOwner; |
| 36 | extern PGDLLIMPORT ResourceOwner AuxProcessResourceOwner; |
| 37 | |
| 38 | /* |
| 39 | * Resource releasing is done in three phases: pre-locks, locks, and |
| 40 | * post-locks. The pre-lock phase must release any resources that are |
| 41 | * visible to other backends (such as pinned buffers); this ensures that |
| 42 | * when we release a lock that another backend may be waiting on, it will |
| 43 | * see us as being fully out of our transaction. The post-lock phase |
| 44 | * should be used for backend-internal cleanup. |
| 45 | */ |
| 46 | typedef enum |
| 47 | { |
| 48 | RESOURCE_RELEASE_BEFORE_LOCKS, |
| 49 | RESOURCE_RELEASE_LOCKS, |
| 50 | RESOURCE_RELEASE_AFTER_LOCKS |
| 51 | } ResourceReleasePhase; |
| 52 | |
| 53 | /* |
| 54 | * Dynamically loaded modules can get control during ResourceOwnerRelease |
| 55 | * by providing a callback of this form. |
| 56 | */ |
| 57 | typedef void (*ResourceReleaseCallback) (ResourceReleasePhase phase, |
| 58 | bool isCommit, |
| 59 | bool isTopLevel, |
| 60 | void *arg); |
| 61 | |
| 62 | |
| 63 | /* |
| 64 | * Functions in resowner.c |
| 65 | */ |
| 66 | |
| 67 | /* generic routines */ |
| 68 | extern ResourceOwner ResourceOwnerCreate(ResourceOwner parent, |
| 69 | const char *name); |
| 70 | extern void ResourceOwnerRelease(ResourceOwner owner, |
| 71 | ResourceReleasePhase phase, |
| 72 | bool isCommit, |
| 73 | bool isTopLevel); |
| 74 | extern void ResourceOwnerDelete(ResourceOwner owner); |
| 75 | extern ResourceOwner ResourceOwnerGetParent(ResourceOwner owner); |
| 76 | extern void ResourceOwnerNewParent(ResourceOwner owner, |
| 77 | ResourceOwner newparent); |
| 78 | extern void RegisterResourceReleaseCallback(ResourceReleaseCallback callback, |
| 79 | void *arg); |
| 80 | extern void UnregisterResourceReleaseCallback(ResourceReleaseCallback callback, |
| 81 | void *arg); |
| 82 | extern void CreateAuxProcessResourceOwner(void); |
| 83 | extern void ReleaseAuxProcessResources(bool isCommit); |
| 84 | |
| 85 | #endif /* RESOWNER_H */ |
| 86 | |