Apache Portable Runtime
Loading...
Searching...
No Matches
apr_reslist.h
Go to the documentation of this file.
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#ifndef APR_RESLIST_H
18#define APR_RESLIST_H
19
20/**
21 * @file apr_reslist.h
22 * @brief APR-UTIL Resource List Routines
23 */
24
25#include "apr.h"
26#include "apu.h"
27#include "apr_pools.h"
28#include "apr_errno.h"
29#include "apr_time.h"
30
31/**
32 * @defgroup APR_Util_RL Resource List Routines
33 * @ingroup APR
34 * @{
35 */
36
37#ifdef __cplusplus
38extern "C" {
39#endif /* __cplusplus */
40
41/** Opaque resource list object */
43
44/* Generic constructor called by resource list when it needs to create a
45 * resource.
46 * @param resource opaque resource
47 * @param params flags
48 * @param pool Pool
49 */
50typedef apr_status_t (*apr_reslist_constructor)(void **resource, void *params,
51 apr_pool_t *pool);
52
53/* Generic destructor called by resource list when it needs to destroy a
54 * resource.
55 * @param resource opaque resource
56 * @param params flags
57 * @param pool Pool
58 */
59typedef apr_status_t (*apr_reslist_destructor)(void *resource, void *params,
60 apr_pool_t *pool);
61
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 */
65
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 during reslist maintenance to
73 * meet this maximum restriction as they expire (reach their ttl).
74 * @param hmax Absolute maximum limit on the number of total resources.
75 * @param ttl If non-zero, sets the maximum amount of time in microseconds an
76 * unused resource is valid. Any resource which has exceeded this
77 * time will be destroyed, either when encountered by
78 * apr_reslist_acquire() or during reslist maintenance.
79 * @param con Constructor routine that is called to create a new resource.
80 * @param de Destructor routine that is called to destroy an expired resource.
81 * @param params Passed to constructor and deconstructor
82 * @param pool The pool from which to create this resource list. Also the
83 * same pool that is passed to the constructor and destructor
84 * routines.
85 * @remark If APR has been compiled without thread support, hmax will be
86 * automatically set to 1 and values of min and smax will be forced to
87 * 1 for any non-zero value.
88 */
90 int min, int smax, int hmax,
92 apr_reslist_constructor con,
93 apr_reslist_destructor de,
94 void *params,
95 apr_pool_t *pool);
96
97/**
98 * Destroy the given resource list and all resources controlled by
99 * this list.
100 * FIXME: Should this block until all resources become available,
101 * or maybe just destroy all the free ones, or maybe destroy
102 * them even though they might be in use by something else?
103 * Currently it will abort if there are resources that haven't
104 * been released, so there is an assumption that all resources
105 * have been released to the list before calling this function.
106 * @param reslist The reslist to destroy
107 */
109
110/* Acquire order modes */
111#define APR_RESLIST_ACQUIRE_LIFO 0x0
112#define APR_RESLIST_ACQUIRE_FIFO 0x1
113#define APR_RESLIST_ACQUIRE_MASK 0x1
114
115/**
116 * Retrieve a resource from the list, either the oldest (FIFO) or
117 * latest (LIFO), creating a new one if necessary.
118 * If we have met our maximum number of resources, we will block
119 * until one becomes available.
120 * @param reslist The resource list.
121 * @param resource An address where the pointer to the resource
122 * will be stored.
123 * @param flags Bitmask of APR_RESLIST_ACQUIRE_* flags.
124 */
126 void **resource, int flags);
127
128/**
129 * Retrieve the latest resource from the list, creating a new one if necessary.
130 * If we have met our maximum number of resources, we will block
131 * until one becomes available.
132 * @param reslist The resource list.
133 * @param resource An address where the pointer to the resource
134 * will be stored.
135 */
137 void **resource);
138
139/**
140 * Return a resource back to the list of available resources.
141 * @param reslist The resource list.
142 * @param resource The resource to return to the list.
143 */
145 void *resource);
146
147/**
148 * Set the timeout the acquire will wait for a free resource
149 * when the maximum number of resources is exceeded.
150 * @param reslist The resource list.
151 * @param timeout Timeout to wait. The zero waits forever.
152 */
154 apr_interval_time_t timeout);
155
156/**
157 * Return the number of outstanding resources.
158 * @param reslist The resource list.
159 */
161
162/**
163 * Invalidate a resource in the pool - e.g. a database connection
164 * that returns a "lost connection" error and can't be restored.
165 * Use this instead of apr_reslist_release if the resource is bad.
166 * @param reslist The resource list.
167 * @param resource The resource to invalidate.
168 */
170 void *resource);
171
172/**
173 * Perform routine maintenance on the resource list. This call
174 * may instantiate new resources or expire old resources.
175 * @param reslist The resource list.
176 */
178
179/**
180 * Set reslist cleanup order.
181 * @param reslist The resource list.
182 * @param mode Cleanup order mode
183 * <PRE>
184 * APR_RESLIST_CLEANUP_DEFAULT default pool cleanup order
185 * APR_RESLIST_CLEANUP_FIRST use pool pre cleanup
186 * </PRE>
187 * @remark If APR_RESLIST_CLEANUP_FIRST is used the destructors will
188 * be called before child pools of the pool used to create the reslist
189 * are destroyed. This allows to explicitly destroy the child pools
190 * inside reslist destructors.
191 */
193 apr_uint32_t mode);
194
195#ifdef __cplusplus
196}
197#endif
198
199/** @} */
200
201#endif /* ! APR_RESLIST_H */
APR Platform Definitions.
APR Error Codes.
APR memory allocation.
APR Time Library.
apr_status_t apr_reslist_destroy(apr_reslist_t *reslist)
apr_status_t apr_reslist_invalidate(apr_reslist_t *reslist, void *resource)
apr_status_t apr_reslist_create(apr_reslist_t **reslist, int min, int smax, int hmax, apr_interval_time_t ttl, apr_reslist_constructor con, apr_reslist_destructor de, void *params, apr_pool_t *pool)
struct apr_reslist_t apr_reslist_t
Definition apr_reslist.h:42
void apr_reslist_cleanup_order_set(apr_reslist_t *reslist, apr_uint32_t mode)
apr_status_t apr_reslist_maintain(apr_reslist_t *reslist)
apr_uint32_t apr_reslist_acquired_count(apr_reslist_t *reslist)
apr_status_t apr_reslist_acquire(apr_reslist_t *reslist, void **resource)
apr_status_t apr_reslist_acquire_ex(apr_reslist_t *reslist, void **resource, int flags)
apr_status_t apr_reslist_release(apr_reslist_t *reslist, void *resource)
void apr_reslist_timeout_set(apr_reslist_t *reslist, apr_interval_time_t timeout)
int apr_status_t
Definition apr_errno.h:44
#define APR_DECLARE(type)
Definition apr.h:523
struct apr_pool_t apr_pool_t
Definition apr_pools.h:60
apr_int64_t apr_interval_time_t
Definition apr_time.h:55