apr_allocator.inc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. {
  17. * @file apr_allocator.h
  18. * @brief APR Internal Memory Allocation
  19. }
  20. {#include "apr.h"
  21. #include "apr_errno.h"
  22. #define APR_WANT_MEMFUNC < For no good reason?
  23. #include "apr_want.h"}
  24. {
  25. * @defgroup apr_allocator Internal Memory Allocation
  26. * @ingroup APR
  27. }
  28. type
  29. { the allocator structure }
  30. apr_allocator_t = record end;
  31. Papr_allocator_t = ^apr_allocator_t;
  32. PPapr_allocator_t = ^Papr_allocator_t;
  33. { the structure which holds information about the allocation }
  34. Papr_memnode_t = ^apr_memnode_t;
  35. PPapr_memnode_t = ^Papr_memnode_t;
  36. { basic memory node structure
  37. * @note The next, ref and first_avail fields are available for use by the
  38. * caller of apr_allocator_alloc(), the remaining fields are read-only.
  39. * The next field has to be used with caution and sensibly set when the
  40. * memnode is passed back to apr_allocator_free(). See apr_allocator_free()
  41. * for details.
  42. * The ref and first_avail fields will be properly restored by
  43. * apr_allocator_free().
  44. }
  45. apr_memnode_t = record
  46. next: Papr_memnode_t; {< next memnode }
  47. ref: PPapr_memnode_t; {< reference to self }
  48. index: apr_uint32_t; {< size }
  49. free_index: apr_uint32_t; {< how much free }
  50. first_avail: PChar; {< pointer to first free memory }
  51. endp: PChar; {< pointer to end of free memory }
  52. end;
  53. { The base size of a memory node - aligned. }
  54. //#define APR_MEMNODE_T_SIZE APR_ALIGN_DEFAULT(sizeof(apr_memnode_t))
  55. { Symbolic constants }
  56. const
  57. APR_ALLOCATOR_MAX_FREE_UNLIMITED = 0;
  58. {
  59. * Create a new allocator
  60. * @param allocator The allocator we have just created.
  61. *
  62. }
  63. function apr_allocator_create(allocator: PPapr_allocator_t): apr_status_t;
  64. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  65. external LibAPR name LibNamePrefix + 'apr_allocator_create' + LibSuff4;
  66. {
  67. * Destroy an allocator
  68. * @param allocator The allocator to be destroyed
  69. * @remark Any memnodes not given back to the allocator prior to destroying
  70. * will _not_ be free()d.
  71. }
  72. procedure apr_allocator_destroy(allocator: Papr_allocator_t);
  73. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  74. external LibAPR name LibNamePrefix + 'apr_allocator_destroy' + LibSuff4;
  75. {
  76. * Allocate a block of mem from the allocator
  77. * @param allocator The allocator to allocate from
  78. * @param size The size of the mem to allocate (excluding the
  79. * memnode structure)
  80. }
  81. function apr_allocator_alloc(allocator: Papr_allocator_t;
  82. size: apr_size_t): Papr_memnode_t;
  83. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  84. external LibAPR name LibNamePrefix + 'apr_allocator_alloc' + LibSuff8;
  85. {
  86. * Free a list of blocks of mem, giving them back to the allocator.
  87. * The list is typically terminated by a memnode with its next field
  88. * set to NULL.
  89. * @param allocator The allocator to give the mem back to
  90. * @param memnode The memory node to return
  91. }
  92. procedure apr_allocator_free(allocator: Papr_allocator_t; memnode: Papr_memnode_t);
  93. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  94. external LibAPR name LibNamePrefix + 'apr_allocator_free' + LibSuff8;
  95. //#include "apr_pools.h"
  96. {
  97. * Set the owner of the allocator
  98. * @param allocator The allocator to set the owner for
  99. * @param pool The pool that is to own the allocator
  100. * @remark Typically pool is the highest level pool using the allocator
  101. }
  102. {
  103. * XXX: see if we can come up with something a bit better. Currently
  104. * you can make a pool an owner, but if the pool doesn't use the allocator
  105. * the allocator will never be destroyed.
  106. }
  107. procedure apr_allocator_owner_set(allocator: Papr_allocator_t; pool: Papr_pool_t);
  108. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  109. external LibAPR name LibNamePrefix + 'apr_allocator_owner_set' + LibSuff8;
  110. {
  111. * Get the current owner of the allocator
  112. * @param allocator The allocator to get the owner from
  113. }
  114. function apr_allocator_owner_get(allocator: Papr_allocator_t): Papr_pool_t;
  115. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  116. external LibAPR name LibNamePrefix + 'apr_allocator_owner_get' + LibSuff4;
  117. {
  118. * Set the current threshold at which the allocator should start
  119. * giving blocks back to the system.
  120. * @param allocator The allocator the set the threshold on
  121. * @param size The threshold. 0 == unlimited.
  122. }
  123. procedure apr_allocator_max_free_set(allocator: Papr_allocator_t; size: apr_size_t);
  124. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  125. external LibAPR name LibNamePrefix + 'apr_allocator_max_free_set' + LibSuff8;
  126. {#include "apr_thread_mutex.h"}
  127. {$ifdef APR_HAS_THREADS}
  128. {
  129. * Set a mutex for the allocator to use
  130. * @param allocator The allocator to set the mutex for
  131. * @param mutex The mutex
  132. }
  133. APR_DECLARE(void) apr_allocator_mutex_set(apr_allocator_t *allocator,
  134. apr_thread_mutex_t *mutex);
  135. {
  136. * Get the mutex currently set for the allocator
  137. * @param allocator The allocator
  138. }
  139. APR_DECLARE(apr_thread_mutex_t *) apr_allocator_mutex_get(
  140. apr_allocator_t *allocator);
  141. {$endif} { APR_HAS_THREADS }