GME  13
apr_allocator.h
Go to the documentation of this file.
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_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                           __attribute__((nonnull(1)));
00076 
00083 APR_DECLARE(void) apr_allocator_destroy(apr_allocator_t *allocator)
00084                   __attribute__((nonnull(1)));
00085 
00092 APR_DECLARE(apr_memnode_t *) apr_allocator_alloc(apr_allocator_t *allocator,
00093                                                  apr_size_t size)
00094                              __attribute__((nonnull(1)));
00095 
00103 APR_DECLARE(void) apr_allocator_free(apr_allocator_t *allocator,
00104                                      apr_memnode_t *memnode)
00105                   __attribute__((nonnull(1,2)));
00106 
00107 #include "apr_pools.h"
00108 
00115 /*
00116  * XXX: see if we can come up with something a bit better.  Currently
00117  * you can make a pool an owner, but if the pool doesn't use the allocator
00118  * the allocator will never be destroyed.
00119  */
00120 APR_DECLARE(void) apr_allocator_owner_set(apr_allocator_t *allocator,
00121                                           apr_pool_t *pool)
00122                   __attribute__((nonnull(1)));
00123 
00128 APR_DECLARE(apr_pool_t *) apr_allocator_owner_get(apr_allocator_t *allocator)
00129                           __attribute__((nonnull(1)));
00130 
00137 APR_DECLARE(void) apr_allocator_max_free_set(apr_allocator_t *allocator,
00138                                              apr_size_t size)
00139                   __attribute__((nonnull(1)));
00140 
00141 #include "apr_thread_mutex.h"
00142 
00143 #if APR_HAS_THREADS
00144 
00149 APR_DECLARE(void) apr_allocator_mutex_set(apr_allocator_t *allocator,
00150                                           apr_thread_mutex_t *mutex)
00151                   __attribute__((nonnull(1)));
00152 
00157 APR_DECLARE(apr_thread_mutex_t *) apr_allocator_mutex_get(
00158                                           apr_allocator_t *allocator)
00159                                   __attribute__((nonnull(1)));
00160 
00161 #endif /* APR_HAS_THREADS */
00162 
00165 #ifdef __cplusplus
00166 }
00167 #endif
00168 
00169 #endif /* !APR_ALLOCATOR_H */