Use of pre_cleanups is not the default for reslists.
[apr-util.git] / include / apr_reslist.h
blobad27d80cdfbac14c8914f755c77c1dbaddd225a3
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef APR_RESLIST_H
18 #define APR_RESLIST_H
20 /**
21 * @file apr_reslist.h
22 * @brief APR-UTIL Resource List Routines
25 #include "apr.h"
26 #include "apu.h"
27 #include "apr_pools.h"
28 #include "apr_errno.h"
29 #include "apr_time.h"
31 /**
32 * @defgroup APR_Util_RL Resource List Routines
33 * @ingroup APR_Util
34 * @{
37 #ifdef __cplusplus
38 extern "C" {
39 #endif /* __cplusplus */
41 /** Opaque resource list object */
42 typedef struct apr_reslist_t apr_reslist_t;
44 /* Generic constructor called by resource list when it needs to create a
45 * resource.
46 * @param resource opaque resource
47 * @param param flags
48 * @param pool Pool
50 typedef apr_status_t (*apr_reslist_constructor)(void **resource, void *params,
51 apr_pool_t *pool);
53 /* Generic destructor called by resource list when it needs to destroy a
54 * resource.
55 * @param resource opaque resource
56 * @param param flags
57 * @param pool Pool
59 typedef apr_status_t (*apr_reslist_destructor)(void *resource, void *params,
60 apr_pool_t *pool);
62 /* Cleanup order modes */
63 #define APR_RESLIST_CLEANUP_DEFAULT 0 /**< default pool cleanup */
64 #define APR_RESLIST_CLEANUP_FIRST 1 /**< use pool pre cleanup */
66 /**
67 * Create a new resource list with the following parameters:
68 * @param reslist An address where the pointer to the new resource
69 * list will be stored.
70 * @param min Allowed minimum number of available resources. Zero
71 * creates new resources only when needed.
72 * @param smax Resources will be destroyed to meet this maximum
73 * restriction as they expire.
74 * @param hmax Absolute maximum limit on the number of total resources.
75 * @param ttl If non-zero, sets the maximum amount of time a resource
76 * may be available while exceeding the soft limit.
77 * @param con Constructor routine that is called to create a new resource.
78 * @param de Destructor routine that is called to destroy an expired resource.
79 * @param params Passed to constructor and deconstructor
80 * @param pool The pool from which to create this resoure list. Also the
81 * same pool that is passed to the constructor and destructor
82 * routines.
83 * @remark If APR has been compiled without thread support, hmax will be
84 * automatically set to 1 and values of min and smax will be forced to
85 * 1 for any non-zero value.
87 APU_DECLARE(apr_status_t) apr_reslist_create(apr_reslist_t **reslist,
88 int min, int smax, int hmax,
89 apr_interval_time_t ttl,
90 apr_reslist_constructor con,
91 apr_reslist_destructor de,
92 void *params,
93 apr_pool_t *pool);
95 /**
96 * Destroy the given resource list and all resources controlled by
97 * this list.
98 * FIXME: Should this block until all resources become available,
99 * or maybe just destroy all the free ones, or maybe destroy
100 * them even though they might be in use by something else?
101 * Currently it will abort if there are resources that haven't
102 * been released, so there is an assumption that all resources
103 * have been released to the list before calling this function.
104 * @param reslist The reslist to destroy
106 APU_DECLARE(apr_status_t) apr_reslist_destroy(apr_reslist_t *reslist);
109 * Retrieve a resource from the list, creating a new one if necessary.
110 * If we have met our maximum number of resources, we will block
111 * until one becomes available.
113 APU_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist,
114 void **resource);
117 * Return a resource back to the list of available resources.
119 APU_DECLARE(apr_status_t) apr_reslist_release(apr_reslist_t *reslist,
120 void *resource);
123 * Set the timeout the acquire will wait for a free resource
124 * when the maximum number of resources is exceeded.
125 * @param reslist The resource list.
126 * @param timeout Timeout to wait. The zero waits forewer.
128 APU_DECLARE(void) apr_reslist_timeout_set(apr_reslist_t *reslist,
129 apr_interval_time_t timeout);
132 * Return the number of outstanding resources.
133 * @param reslist The resource list.
135 APU_DECLARE(apr_uint32_t) apr_reslist_acquired_count(apr_reslist_t *reslist);
138 * Invalidate a resource in the pool - e.g. a database connection
139 * that returns a "lost connection" error and can't be restored.
140 * Use this instead of apr_reslist_release if the resource is bad.
142 APU_DECLARE(apr_status_t) apr_reslist_invalidate(apr_reslist_t *reslist,
143 void *resource);
146 * Perform routine maintenance on the resource list. This call
147 * may instantiate new resources or expire old resources.
148 * @param reslist The resource list.
150 APU_DECLARE(apr_status_t) apr_reslist_maintain(apr_reslist_t *reslist);
153 * Set reslist cleanup order.
154 * @param reslist The resource list.
155 * @param mode Cleanup order mode
156 * <PRE>
157 * APR_RESLIST_CLEANUP_DEFAULT default pool cleanup order
158 * APR_RESLIST_CLEANUP_FIRST use pool pre cleanup
159 * </PRE>
160 * @remark If APR_RESLIST_CLEANUP_FIRST is used the destructors will
161 * be called before child pools of the pool used to create the reslist
162 * are destroyed. This allows to explicitly destroy the child pools
163 * inside reslist destructors.
165 APU_DECLARE(void) apr_reslist_cleanup_order_set(apr_reslist_t *reslist,
166 apr_uint32_t mode);
168 #ifdef __cplusplus
170 #endif
172 /** @} */
174 #endif /* ! APR_RESLIST_H */