2
0

apr_reslist.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * 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. #ifndef APR_RESLIST_H
  17. #define APR_RESLIST_H
  18. /**
  19. * @file apr_reslist.h
  20. * @brief APR-UTIL Resource List Routines
  21. */
  22. #include "apr.h"
  23. #include "apu.h"
  24. #include "apr_pools.h"
  25. #include "apr_errno.h"
  26. #include "apr_time.h"
  27. #if APR_HAS_THREADS
  28. /**
  29. * @defgroup APR_Util_RL Resource List Routines
  30. * @ingroup APR_Util
  31. * @{
  32. */
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif /* __cplusplus */
  36. /** Opaque resource list object */
  37. typedef struct apr_reslist_t apr_reslist_t;
  38. /* Generic constructor called by resource list when it needs to create a
  39. * resource.
  40. * @param resource opaque resource
  41. * @param param flags
  42. * @param pool Pool
  43. */
  44. typedef apr_status_t (*apr_reslist_constructor)(void **resource, void *params,
  45. apr_pool_t *pool);
  46. /* Generic destructor called by resource list when it needs to destroy a
  47. * resource.
  48. * @param resource opaque resource
  49. * @param param flags
  50. * @param pool Pool
  51. */
  52. typedef apr_status_t (*apr_reslist_destructor)(void *resource, void *params,
  53. apr_pool_t *pool);
  54. /**
  55. * Create a new resource list with the following parameters:
  56. * @param reslist An address where the pointer to the new resource
  57. * list will be stored.
  58. * @param pool The pool to use for local storage and management
  59. * @param min Allowed minimum number of available resources. Zero
  60. * creates new resources only when needed.
  61. * @param smax Resources will be destroyed to meet this maximum
  62. * restriction as they expire.
  63. * @param hmax Absolute maximum limit on the number of total resources.
  64. * @param ttl If non-zero, sets the maximum amount of time a resource
  65. * may be available while exceeding the soft limit.
  66. * @param con Constructor routine that is called to create a new resource.
  67. * @param de Destructor routine that is called to destroy an expired resource.
  68. * @param params Passed to constructor and deconstructor
  69. * @param pool The pool from which to create this resoure list. Also the
  70. * same pool that is passed to the constructor and destructor
  71. * routines.
  72. */
  73. APU_DECLARE(apr_status_t) apr_reslist_create(apr_reslist_t **reslist,
  74. int min, int smax, int hmax,
  75. apr_interval_time_t ttl,
  76. apr_reslist_constructor con,
  77. apr_reslist_destructor de,
  78. void *params,
  79. apr_pool_t *pool);
  80. /**
  81. * Destroy the given resource list and all resources controlled by
  82. * this list.
  83. * FIXME: Should this block until all resources become available,
  84. * or maybe just destroy all the free ones, or maybe destroy
  85. * them even though they might be in use by something else?
  86. * Currently it will abort if there are resources that haven't
  87. * been released, so there is an assumption that all resources
  88. * have been released to the list before calling this function.
  89. * @param reslist The reslist to destroy
  90. */
  91. APU_DECLARE(apr_status_t) apr_reslist_destroy(apr_reslist_t *reslist);
  92. /**
  93. * Retrieve a resource from the list, creating a new one if necessary.
  94. * If we have met our maximum number of resources, we will block
  95. * until one becomes available.
  96. */
  97. APU_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist,
  98. void **resource);
  99. /**
  100. * Return a resource back to the list of available resources.
  101. */
  102. APU_DECLARE(apr_status_t) apr_reslist_release(apr_reslist_t *reslist,
  103. void *resource);
  104. /**
  105. * Set the timeout the acquire will wait for a free resource
  106. * when the maximum number of resources is exceeded.
  107. * @param reslist The resource list.
  108. * @param timeout Timeout to wait. The zero waits forewer.
  109. */
  110. APU_DECLARE(void) apr_reslist_timeout_set(apr_reslist_t *reslist,
  111. apr_interval_time_t timeout);
  112. /**
  113. * Invalidate a resource in the pool - e.g. a database connection
  114. * that returns a "lost connection" error and can't be restored.
  115. * Use this instead of apr_reslist_release if the resource is bad.
  116. */
  117. APU_DECLARE(apr_status_t) apr_reslist_invalidate(apr_reslist_t *reslist,
  118. void *resource);
  119. #ifdef __cplusplus
  120. }
  121. #endif
  122. /** @} */
  123. #endif /* APR_HAS_THREADS */
  124. #endif /* ! APR_RESLIST_H */