00001 /* Copyright 2000-2005 The Apache Software Foundation or its licensors, as 00002 * applicable. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * 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_ALLOCATOR_H 00018 #define APR_ALLOCATOR_H 00019 00025 #include "apr.h" 00026 #include "apr_errno.h" 00027 #define APR_WANT_MEMFUNC 00028 #include "apr_want.h" 00029 00030 #ifdef __cplusplus 00031 extern "C" { 00032 #endif 00033 00041 typedef struct apr_allocator_t apr_allocator_t; 00043 typedef struct apr_memnode_t apr_memnode_t; 00044 00054 struct apr_memnode_t { 00055 apr_memnode_t *next; 00056 apr_memnode_t **ref; 00057 apr_uint32_t index; 00058 apr_uint32_t free_index; 00059 char *first_avail; 00060 char *endp; 00061 }; 00062 00064 #define APR_MEMNODE_T_SIZE APR_ALIGN_DEFAULT(sizeof(apr_memnode_t)) 00065 00067 #define APR_ALLOCATOR_MAX_FREE_UNLIMITED 0 00068 00074 APR_DECLARE(apr_status_t) apr_allocator_create(apr_allocator_t **allocator); 00075 00082 APR_DECLARE(void) apr_allocator_destroy(apr_allocator_t *allocator); 00083 00090 APR_DECLARE(apr_memnode_t *) apr_allocator_alloc(apr_allocator_t *allocator, 00091 apr_size_t size); 00092 00100 APR_DECLARE(void) apr_allocator_free(apr_allocator_t *allocator, 00101 apr_memnode_t *memnode); 00102 00103 #include "apr_pools.h" 00104 00111 /* 00112 * XXX: see if we can come up with something a bit better. Currently 00113 * you can make a pool an owner, but if the pool doesn't use the allocator 00114 * the allocator will never be destroyed. 00115 */ 00116 APR_DECLARE(void) apr_allocator_owner_set(apr_allocator_t *allocator, 00117 apr_pool_t *pool); 00118 00123 APR_DECLARE(apr_pool_t *) apr_allocator_owner_get(apr_allocator_t *allocator); 00124 00131 APR_DECLARE(void) apr_allocator_max_free_set(apr_allocator_t *allocator, 00132 apr_size_t size); 00133 00134 #include "apr_thread_mutex.h" 00135 00136 #if APR_HAS_THREADS 00137 00142 APR_DECLARE(void) apr_allocator_mutex_set(apr_allocator_t *allocator, 00143 apr_thread_mutex_t *mutex); 00144 00149 APR_DECLARE(apr_thread_mutex_t *) apr_allocator_mutex_get( 00150 apr_allocator_t *allocator); 00151 00152 #endif /* APR_HAS_THREADS */ 00153 00156 #ifdef __cplusplus 00157 } 00158 #endif 00159 00160 #endif /* !APR_ALLOCATOR_H */