From 0425aadc78680e53000fd0108b540d6eca048516 Mon Sep 17 00:00:00 2001 From: gmcdonald Date: Sat, 13 Feb 2010 01:32:03 +0000 Subject: Moving axis svn, part of TLP move INFRA-2441 git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@909681 13f79535-47bb-0310-9956-ffa450edef68 --- util/src/allocator.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 util/src/allocator.c (limited to 'util/src/allocator.c') diff --git a/util/src/allocator.c b/util/src/allocator.c new file mode 100644 index 0000000..1b31048 --- /dev/null +++ b/util/src/allocator.c @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +void *AXIS2_CALL axutil_allocator_malloc_impl( + axutil_allocator_t * allocator, + size_t size); + +void *AXIS2_CALL axutil_allocator_realloc_impl( + axutil_allocator_t * allocator, + void *ptr, + size_t size); + +void AXIS2_CALL axutil_allocator_free_impl( + axutil_allocator_t * allocator, + void *ptr); + +AXIS2_EXTERN axutil_allocator_t *AXIS2_CALL +axutil_allocator_init( + axutil_allocator_t * allocator) +{ + if(allocator) + return allocator; + + else + { + allocator = (axutil_allocator_t *)malloc(sizeof(axutil_allocator_t)); + memset(allocator, 0, sizeof(axutil_allocator_t)); + if(allocator) + { + allocator->malloc_fn = axutil_allocator_malloc_impl; + allocator->realloc = axutil_allocator_realloc_impl; + allocator->free_fn = axutil_allocator_free_impl; + allocator->global_pool_ref = 0; + + return allocator; + } + } + return NULL; +} + +AXIS2_EXTERN axutil_allocator_t *AXIS2_CALL +axutil_allocator_clone( + axutil_allocator_t * allocator) +{ + if(!allocator) + return NULL; + + else + { + axutil_allocator_t* clone = NULL; + clone = (axutil_allocator_t *)malloc(sizeof(axutil_allocator_t)); + memset(clone, 0, sizeof(axutil_allocator_t)); + if(clone) + { + clone->malloc_fn = allocator->malloc_fn; + clone->realloc = allocator->realloc; + clone->free_fn = allocator->free_fn; + clone->current_pool = allocator->current_pool; + clone->global_pool = allocator->global_pool; + clone->local_pool = allocator->local_pool; + clone->global_pool_ref = 0; + + return clone; + } + } + return NULL; +} +AXIS2_EXTERN void AXIS2_CALL +axutil_allocator_free( + axutil_allocator_t * allocator) +{ + if(allocator) + { + allocator->free_fn(allocator, allocator); + } + return; +} + +void *AXIS2_CALL +axutil_allocator_malloc_impl( + axutil_allocator_t * allocator, + size_t size) +{ + return malloc(size); +} + +void *AXIS2_CALL +axutil_allocator_realloc_impl( + axutil_allocator_t * allocator, + void *ptr, + size_t size) +{ + return realloc(ptr, size); +} + +void AXIS2_CALL +axutil_allocator_free_impl( + axutil_allocator_t * allocator, + void *ptr) +{ + free(ptr); +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_allocator_switch_to_global_pool( + axutil_allocator_t * allocator) +{ + if(!allocator) + return; + allocator->global_pool_ref++; + allocator->current_pool = allocator->global_pool; + return; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_allocator_switch_to_local_pool( + axutil_allocator_t * allocator) +{ + if(!allocator) + return; + if(allocator->global_pool_ref > 0) + { + allocator->global_pool_ref--; + } + + if(allocator->global_pool_ref == 0) + { + allocator->current_pool = allocator->local_pool; + } + return; +} + -- cgit v1.1-32-gdbae