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.
22 * @brief APR-UTIL Resource List Routines
27 #include "apr_pools.h"
28 #include "apr_errno.h"
32 * @defgroup APR_Util_RL Resource List Routines
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
46 * @param resource opaque resource
50 typedef apr_status_t (*apr_reslist_constructor
)(void **resource
, void *params
,
53 /* Generic destructor called by resource list when it needs to destroy a
55 * @param resource opaque resource
59 typedef apr_status_t (*apr_reslist_destructor
)(void *resource
, void *params
,
63 * Create a new resource list with the following parameters:
64 * @param reslist An address where the pointer to the new resource
65 * list will be stored.
66 * @param min Allowed minimum number of available resources. Zero
67 * creates new resources only when needed.
68 * @param smax Resources will be destroyed to meet this maximum
69 * restriction as they expire.
70 * @param hmax Absolute maximum limit on the number of total resources.
71 * @param ttl If non-zero, sets the maximum amount of time a resource
72 * may be available while exceeding the soft limit.
73 * @param con Constructor routine that is called to create a new resource.
74 * @param de Destructor routine that is called to destroy an expired resource.
75 * @param params Passed to constructor and deconstructor
76 * @param pool The pool from which to create this resoure list. Also the
77 * same pool that is passed to the constructor and destructor
79 * @remark If APR has been compiled without thread support, hmax will be
80 * automatically set to 1 and values of min and smax will be forced to
81 * 1 for any non-zero value.
83 APU_DECLARE(apr_status_t
) apr_reslist_create(apr_reslist_t
**reslist
,
84 int min
, int smax
, int hmax
,
85 apr_interval_time_t ttl
,
86 apr_reslist_constructor con
,
87 apr_reslist_destructor de
,
92 * Destroy the given resource list and all resources controlled by
94 * FIXME: Should this block until all resources become available,
95 * or maybe just destroy all the free ones, or maybe destroy
96 * them even though they might be in use by something else?
97 * Currently it will abort if there are resources that haven't
98 * been released, so there is an assumption that all resources
99 * have been released to the list before calling this function.
100 * @param reslist The reslist to destroy
102 APU_DECLARE(apr_status_t
) apr_reslist_destroy(apr_reslist_t
*reslist
);
105 * Retrieve a resource from the list, creating a new one if necessary.
106 * If we have met our maximum number of resources, we will block
107 * until one becomes available.
109 APU_DECLARE(apr_status_t
) apr_reslist_acquire(apr_reslist_t
*reslist
,
113 * Return a resource back to the list of available resources.
115 APU_DECLARE(apr_status_t
) apr_reslist_release(apr_reslist_t
*reslist
,
119 * Set the timeout the acquire will wait for a free resource
120 * when the maximum number of resources is exceeded.
121 * @param reslist The resource list.
122 * @param timeout Timeout to wait. The zero waits forewer.
124 APU_DECLARE(void) apr_reslist_timeout_set(apr_reslist_t
*reslist
,
125 apr_interval_time_t timeout
);
128 * Return the number of outstanding resources.
129 * @param reslist The resource list.
131 APU_DECLARE(apr_uint32_t
) apr_reslist_acquired_count(apr_reslist_t
*reslist
);
134 * Invalidate a resource in the pool - e.g. a database connection
135 * that returns a "lost connection" error and can't be restored.
136 * Use this instead of apr_reslist_release if the resource is bad.
138 APU_DECLARE(apr_status_t
) apr_reslist_invalidate(apr_reslist_t
*reslist
,
148 #endif /* ! APR_RESLIST_H */