00001 /* Licensed to the Apache Software Foundation (ASF) under one or more 00002 * contributor license agreements. See the NOTICE file distributed with 00003 * this work for additional information regarding copyright ownership. 00004 * The ASF licenses this file to You under the Apache License, Version 2.0 00005 * (the "License"); you may not use this file except in compliance with 00006 * the License. You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef APR_RESLIST_H 00018 #define APR_RESLIST_H 00019 00020 /** 00021 * @file apr_reslist.h 00022 * @brief APR-UTIL Resource List Routines 00023 */ 00024 00025 #include "apr.h" 00026 #include "apu.h" 00027 #include "apr_pools.h" 00028 #include "apr_errno.h" 00029 #include "apr_time.h" 00030 00031 /** 00032 * @defgroup APR_Util_RL Resource List Routines 00033 * @ingroup APR_Util 00034 * @{ 00035 */ 00036 00037 #ifdef __cplusplus 00038 extern "C" { 00039 #endif /* __cplusplus */ 00040 00041 /** Opaque resource list object */ 00042 typedef struct apr_reslist_t apr_reslist_t; 00043 00044 /* Generic constructor called by resource list when it needs to create a 00045 * resource. 00046 * @param resource opaque resource 00047 * @param param flags 00048 * @param pool Pool 00049 */ 00050 typedef apr_status_t (*apr_reslist_constructor)(void **resource, void *params, 00051 apr_pool_t *pool); 00052 00053 /* Generic destructor called by resource list when it needs to destroy a 00054 * resource. 00055 * @param resource opaque resource 00056 * @param param flags 00057 * @param pool Pool 00058 */ 00059 typedef apr_status_t (*apr_reslist_destructor)(void *resource, void *params, 00060 apr_pool_t *pool); 00061 00062 /* Cleanup order modes */ 00063 #define APR_RESLIST_CLEANUP_DEFAULT 0 /**< default pool cleanup */ 00064 #define APR_RESLIST_CLEANUP_FIRST 1 /**< use pool pre cleanup */ 00065 00066 /** 00067 * Create a new resource list with the following parameters: 00068 * @param reslist An address where the pointer to the new resource 00069 * list will be stored. 00070 * @param min Allowed minimum number of available resources. Zero 00071 * creates new resources only when needed. 00072 * @param smax Resources will be destroyed to meet this maximum 00073 * restriction as they expire. 00074 * @param hmax Absolute maximum limit on the number of total resources. 00075 * @param ttl If non-zero, sets the maximum amount of time in microseconds a 00076 * resource may be available while exceeding the soft limit. 00077 * @param con Constructor routine that is called to create a new resource. 00078 * @param de Destructor routine that is called to destroy an expired resource. 00079 * @param params Passed to constructor and deconstructor 00080 * @param pool The pool from which to create this resource list. Also the 00081 * same pool that is passed to the constructor and destructor 00082 * routines. 00083 * @remark If APR has been compiled without thread support, hmax will be 00084 * automatically set to 1 and values of min and smax will be forced to 00085 * 1 for any non-zero value. 00086 */ 00087 APR_DECLARE(apr_status_t) apr_reslist_create(apr_reslist_t **reslist, 00088 int min, int smax, int hmax, 00089 apr_interval_time_t ttl, 00090 apr_reslist_constructor con, 00091 apr_reslist_destructor de, 00092 void *params, 00093 apr_pool_t *pool); 00094 00095 /** 00096 * Destroy the given resource list and all resources controlled by 00097 * this list. 00098 * FIXME: Should this block until all resources become available, 00099 * or maybe just destroy all the free ones, or maybe destroy 00100 * them even though they might be in use by something else? 00101 * Currently it will abort if there are resources that haven't 00102 * been released, so there is an assumption that all resources 00103 * have been released to the list before calling this function. 00104 * @param reslist The reslist to destroy 00105 */ 00106 APR_DECLARE(apr_status_t) apr_reslist_destroy(apr_reslist_t *reslist); 00107 00108 /** 00109 * Retrieve a resource from the list, creating a new one if necessary. 00110 * If we have met our maximum number of resources, we will block 00111 * until one becomes available. 00112 */ 00113 APR_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist, 00114 void **resource); 00115 00116 /** 00117 * Return a resource back to the list of available resources. 00118 */ 00119 APR_DECLARE(apr_status_t) apr_reslist_release(apr_reslist_t *reslist, 00120 void *resource); 00121 00122 /** 00123 * Set the timeout the acquire will wait for a free resource 00124 * when the maximum number of resources is exceeded. 00125 * @param reslist The resource list. 00126 * @param timeout Timeout to wait. The zero waits forever. 00127 */ 00128 APR_DECLARE(void) apr_reslist_timeout_set(apr_reslist_t *reslist, 00129 apr_interval_time_t timeout); 00130 00131 /** 00132 * Return the number of outstanding resources. 00133 * @param reslist The resource list. 00134 */ 00135 APR_DECLARE(apr_uint32_t) apr_reslist_acquired_count(apr_reslist_t *reslist); 00136 00137 /** 00138 * Invalidate a resource in the pool - e.g. a database connection 00139 * that returns a "lost connection" error and can't be restored. 00140 * Use this instead of apr_reslist_release if the resource is bad. 00141 */ 00142 APR_DECLARE(apr_status_t) apr_reslist_invalidate(apr_reslist_t *reslist, 00143 void *resource); 00144 00145 /** 00146 * Perform routine maintenance on the resource list. This call 00147 * may instantiate new resources or expire old resources. 00148 * @param reslist The resource list. 00149 */ 00150 APR_DECLARE(apr_status_t) apr_reslist_maintain(apr_reslist_t *reslist); 00151 00152 /** 00153 * Set reslist cleanup order. 00154 * @param reslist The resource list. 00155 * @param mode Cleanup order mode 00156 * <PRE> 00157 * APR_RESLIST_CLEANUP_DEFAULT default pool cleanup order 00158 * APR_RESLIST_CLEANUP_FIRST use pool pre cleanup 00159 * </PRE> 00160 * @remark If APR_RESLIST_CLEANUP_FIRST is used the destructors will 00161 * be called before child pools of the pool used to create the reslist 00162 * are destroyed. This allows to explicitly destroy the child pools 00163 * inside reslist destructors. 00164 */ 00165 APR_DECLARE(void) apr_reslist_cleanup_order_set(apr_reslist_t *reslist, 00166 apr_uint32_t mode); 00167 00168 #ifdef __cplusplus 00169 } 00170 #endif 00171 00172 /** @} */ 00173 00174 #endif /* ! APR_RESLIST_H */
1.5.8