apr_reslist.h revision 262253
1279377Simp/* Licensed to the Apache Software Foundation (ASF) under one or more 2279377Simp * contributor license agreements. See the NOTICE file distributed with 3279377Simp * this work for additional information regarding copyright ownership. 4279377Simp * The ASF licenses this file to You under the Apache License, Version 2.0 5279377Simp * (the "License"); you may not use this file except in compliance with 6279377Simp * the License. You may obtain a copy of the License at 7279377Simp * 8279377Simp * http://www.apache.org/licenses/LICENSE-2.0 9279377Simp * 10279377Simp * Unless required by applicable law or agreed to in writing, software 11279377Simp * distributed under the License is distributed on an "AS IS" BASIS, 12279377Simp * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13279377Simp * See the License for the specific language governing permissions and 14279377Simp * limitations under the License. 15279377Simp */ 16279377Simp 17279377Simp#ifndef APR_RESLIST_H 18279377Simp#define APR_RESLIST_H 19279377Simp 20279377Simp/** 21279377Simp * @file apr_reslist.h 22279377Simp * @brief APR-UTIL Resource List Routines 23279377Simp */ 24279377Simp 25279377Simp#include "apr.h" 26279377Simp#include "apu.h" 27279377Simp#include "apr_pools.h" 28279377Simp#include "apr_errno.h" 29279377Simp#include "apr_time.h" 30279377Simp 31279377Simp/** 32279377Simp * @defgroup APR_Util_RL Resource List Routines 33279377Simp * @ingroup APR_Util 34279377Simp * @{ 35279377Simp */ 36279377Simp 37279377Simp#ifdef __cplusplus 38279377Simpextern "C" { 39279377Simp#endif /* __cplusplus */ 40279377Simp 41279377Simp/** Opaque resource list object */ 42279377Simptypedef struct apr_reslist_t apr_reslist_t; 43279377Simp 44279377Simp/* Generic constructor called by resource list when it needs to create a 45279377Simp * resource. 46279377Simp * @param resource opaque resource 47279377Simp * @param params flags 48279377Simp * @param pool Pool 49279377Simp */ 50279377Simptypedef apr_status_t (*apr_reslist_constructor)(void **resource, void *params, 51279377Simp apr_pool_t *pool); 52279377Simp 53279377Simp/* Generic destructor called by resource list when it needs to destroy a 54279377Simp * resource. 55279377Simp * @param resource opaque resource 56279377Simp * @param params flags 57279377Simp * @param pool Pool 58279377Simp */ 59279377Simptypedef apr_status_t (*apr_reslist_destructor)(void *resource, void *params, 60279377Simp apr_pool_t *pool); 61279377Simp 62279377Simp/* Cleanup order modes */ 63279377Simp#define APR_RESLIST_CLEANUP_DEFAULT 0 /**< default pool cleanup */ 64279377Simp#define APR_RESLIST_CLEANUP_FIRST 1 /**< use pool pre cleanup */ 65279377Simp 66279377Simp/** 67279377Simp * Create a new resource list with the following parameters: 68279377Simp * @param reslist An address where the pointer to the new resource 69279377Simp * list will be stored. 70279377Simp * @param min Allowed minimum number of available resources. Zero 71279377Simp * creates new resources only when needed. 72279377Simp * @param smax Resources will be destroyed during reslist maintenance to 73279377Simp * meet this maximum restriction as they expire (reach their ttl). 74279377Simp * @param hmax Absolute maximum limit on the number of total resources. 75279377Simp * @param ttl If non-zero, sets the maximum amount of time in microseconds an 76279377Simp * unused resource is valid. Any resource which has exceeded this 77279377Simp * time will be destroyed, either when encountered by 78279377Simp * apr_reslist_acquire() or during reslist maintenance. 79279377Simp * @param con Constructor routine that is called to create a new resource. 80279377Simp * @param de Destructor routine that is called to destroy an expired resource. 81279377Simp * @param params Passed to constructor and deconstructor 82279377Simp * @param pool The pool from which to create this resource list. Also the 83279377Simp * same pool that is passed to the constructor and destructor 84279377Simp * routines. 85279377Simp * @remark If APR has been compiled without thread support, hmax will be 86279377Simp * automatically set to 1 and values of min and smax will be forced to 87279377Simp * 1 for any non-zero value. 88279377Simp */ 89279377SimpAPU_DECLARE(apr_status_t) apr_reslist_create(apr_reslist_t **reslist, 90279377Simp int min, int smax, int hmax, 91279377Simp apr_interval_time_t ttl, 92279377Simp apr_reslist_constructor con, 93279377Simp apr_reslist_destructor de, 94279377Simp void *params, 95279377Simp apr_pool_t *pool); 96279377Simp 97279377Simp/** 98279377Simp * Destroy the given resource list and all resources controlled by 99279377Simp * this list. 100279377Simp * FIXME: Should this block until all resources become available, 101279377Simp * or maybe just destroy all the free ones, or maybe destroy 102279377Simp * them even though they might be in use by something else? 103279377Simp * Currently it will abort if there are resources that haven't 104279377Simp * been released, so there is an assumption that all resources 105279377Simp * have been released to the list before calling this function. 106279377Simp * @param reslist The reslist to destroy 107279377Simp */ 108279377SimpAPU_DECLARE(apr_status_t) apr_reslist_destroy(apr_reslist_t *reslist); 109279377Simp 110279377Simp/** 111279377Simp * Retrieve a resource from the list, creating a new one if necessary. 112279377Simp * If we have met our maximum number of resources, we will block 113279377Simp * until one becomes available. 114279377Simp * @param reslist The resource list. 115279377Simp * @param resource An address where the pointer to the resource 116279377Simp * will be stored. 117279377Simp */ 118279377SimpAPU_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist, 119279377Simp void **resource); 120279377Simp 121279377Simp/** 122279377Simp * Return a resource back to the list of available resources. 123279377Simp * @param reslist The resource list. 124279377Simp * @param resource The resource to return to the list. 125279377Simp */ 126279377SimpAPU_DECLARE(apr_status_t) apr_reslist_release(apr_reslist_t *reslist, 127279377Simp void *resource); 128279377Simp 129279377Simp/** 130279377Simp * Set the timeout the acquire will wait for a free resource 131279377Simp * when the maximum number of resources is exceeded. 132279377Simp * @param reslist The resource list. 133279377Simp * @param timeout Timeout to wait. The zero waits forever. 134279377Simp */ 135279377SimpAPU_DECLARE(void) apr_reslist_timeout_set(apr_reslist_t *reslist, 136279377Simp apr_interval_time_t timeout); 137279377Simp 138279377Simp/** 139279377Simp * Return the number of outstanding resources. 140279377Simp * @param reslist The resource list. 141279377Simp */ 142279377SimpAPU_DECLARE(apr_uint32_t) apr_reslist_acquired_count(apr_reslist_t *reslist); 143279377Simp 144279377Simp/** 145279377Simp * Invalidate a resource in the pool - e.g. a database connection 146279377Simp * that returns a "lost connection" error and can't be restored. 147279377Simp * Use this instead of apr_reslist_release if the resource is bad. 148279377Simp * @param reslist The resource list. 149279377Simp * @param resource The resource to invalidate. 150279377Simp */ 151279377SimpAPU_DECLARE(apr_status_t) apr_reslist_invalidate(apr_reslist_t *reslist, 152279377Simp void *resource); 153279377Simp 154279377Simp/** 155279377Simp * Perform routine maintenance on the resource list. This call 156279377Simp * may instantiate new resources or expire old resources. 157279377Simp * @param reslist The resource list. 158279377Simp */ 159279377SimpAPU_DECLARE(apr_status_t) apr_reslist_maintain(apr_reslist_t *reslist); 160279377Simp 161279377Simp/** 162279377Simp * Set reslist cleanup order. 163279377Simp * @param reslist The resource list. 164279377Simp * @param mode Cleanup order mode 165279377Simp * <PRE> 166279377Simp * APR_RESLIST_CLEANUP_DEFAULT default pool cleanup order 167279377Simp * APR_RESLIST_CLEANUP_FIRST use pool pre cleanup 168279377Simp * </PRE> 169279377Simp * @remark If APR_RESLIST_CLEANUP_FIRST is used the destructors will 170279377Simp * be called before child pools of the pool used to create the reslist 171279377Simp * are destroyed. This allows to explicitly destroy the child pools 172279377Simp * inside reslist destructors. 173279377Simp */ 174279377SimpAPU_DECLARE(void) apr_reslist_cleanup_order_set(apr_reslist_t *reslist, 175279377Simp apr_uint32_t mode); 176279377Simp 177279377Simp#ifdef __cplusplus 178279377Simp} 179279377Simp#endif 180279377Simp 181279377Simp/** @} */ 182279377Simp 183279377Simp#endif /* ! APR_RESLIST_H */ 184279377Simp