// -*- C++ -*- // // $Id$ #include "ace/OS_NS_string.h" template ACE_INLINE T * ACE_Cached_Mem_Pool_Node::addr (void) { // This should be done using a single reinterpret_cast, but Sun/CC // (4.2) gets awfully confused when T is a char[20] (and maybe other // types). return static_cast (static_cast (this)); } template ACE_INLINE ACE_Cached_Mem_Pool_Node * ACE_Cached_Mem_Pool_Node::get_next (void) { return this->next_; } template ACE_INLINE void ACE_Cached_Mem_Pool_Node::set_next (ACE_Cached_Mem_Pool_Node *ptr) { this->next_ = ptr; } template ACE_INLINE void * ACE_Cached_Allocator::malloc (size_t nbytes) { // Check if size requested fits within pre-determined size. if (nbytes > sizeof (T)) return 0; // addr() call is really not absolutely necessary because of the way // ACE_Cached_Mem_Pool_Node's internal structure arranged. return this->free_list_.remove ()->addr (); } template ACE_INLINE void * ACE_Cached_Allocator::calloc (size_t nbytes, char initial_value) { // Check if size requested fits within pre-determined size. if (nbytes > sizeof (T)) return 0; // addr() call is really not absolutely necessary because of the way // ACE_Cached_Mem_Pool_Node's internal structure arranged. void *ptr = this->free_list_.remove ()->addr (); ACE_OS::memset (ptr, initial_value, sizeof (T)); return ptr; } template ACE_INLINE void * ACE_Cached_Allocator::calloc (size_t, size_t, char) { ACE_NOTSUP_RETURN (0); } template ACE_INLINE void ACE_Cached_Allocator::free (void * ptr) { if (ptr != 0) this->free_list_.add ((ACE_Cached_Mem_Pool_Node *) ptr) ; } template ACE_INLINE void * ACE_Dynamic_Cached_Allocator::malloc (size_t nbytes) { // Check if size requested fits within pre-determined size. if (nbytes > chunk_size_) return 0; // addr() call is really not absolutely necessary because of the way // ACE_Cached_Mem_Pool_Node's internal structure arranged. return this->free_list_.remove ()->addr (); } template ACE_INLINE void * ACE_Dynamic_Cached_Allocator::calloc (size_t nbytes, char initial_value) { // Check if size requested fits within pre-determined size. if (nbytes > chunk_size_) return 0; // addr() call is really not absolutely necessary because of the way // ACE_Cached_Mem_Pool_Node's internal structure arranged. void *ptr = this->free_list_.remove ()->addr (); ACE_OS::memset (ptr, initial_value, chunk_size_); return ptr; } template ACE_INLINE void * ACE_Dynamic_Cached_Allocator::calloc (size_t, size_t, char) { ACE_NOTSUP_RETURN (0); } template ACE_INLINE void ACE_Dynamic_Cached_Allocator::free (void * ptr) { if (ptr != 0) this->free_list_.add ((ACE_Cached_Mem_Pool_Node *) ptr); } template ACE_INLINE void * ACE_Allocator_Adapter::malloc (size_t nbytes) { ACE_TRACE ("ACE_Allocator_Adapter::malloc"); return this->allocator_.malloc (nbytes); } template ACE_INLINE void * ACE_Allocator_Adapter::calloc (size_t nbytes, char initial_value) { ACE_TRACE ("ACE_Allocator_Adapter::calloc"); return this->allocator_.calloc (nbytes, initial_value); } template ACE_INLINE void * ACE_Allocator_Adapter::calloc (size_t n_elem, size_t elem_size, char initial_value) { ACE_TRACE ("ACE_Allocator_Adapter::calloc"); return this->allocator_.calloc (n_elem, elem_size, initial_value); } template ACE_INLINE MALLOC & ACE_Allocator_Adapter::alloc (void) { ACE_TRACE ("ACE_Allocator_Adapter::allocator"); return this->allocator_; } template ACE_INLINE void ACE_Allocator_Adapter::free (void *ptr) { ACE_TRACE ("ACE_Allocator_Adapter::free"); this->allocator_.free (ptr); } template ACE_INLINE int ACE_Allocator_Adapter::remove (void) { ACE_TRACE ("ACE_Allocator_Adapter::remove"); return this->allocator_.remove (); } template ACE_INLINE int ACE_Allocator_Adapter::trybind (const char *name, void *&pointer) { ACE_TRACE ("ACE_Allocator_Adapter::trybind"); return this->allocator_.trybind (name, pointer); } template ACE_INLINE int ACE_Allocator_Adapter::bind (const char *name, void *pointer, int duplicates) { ACE_TRACE ("ACE_Allocator_Adapter::bind"); return this->allocator_.bind (name, pointer, duplicates); } template ACE_INLINE int ACE_Allocator_Adapter::find (const char *name, void *&pointer) { ACE_TRACE ("ACE_Allocator_Adapter::find"); return this->allocator_.find (name, pointer); } template ACE_INLINE int ACE_Allocator_Adapter::find (const char *name) { ACE_TRACE ("ACE_Allocator_Adapter::find"); return this->allocator_.find (name); } template ACE_INLINE int ACE_Allocator_Adapter::unbind (const char *name, void *&pointer) { ACE_TRACE ("ACE_Allocator_Adapter::unbind"); return this->allocator_.unbind (name, pointer); } template ACE_INLINE int ACE_Allocator_Adapter::unbind (const char *name) { ACE_TRACE ("ACE_Allocator_Adapter::unbind"); return this->allocator_.unbind (name); } template ACE_INLINE int ACE_Allocator_Adapter::sync (ssize_t len, int flags) { ACE_TRACE ("ACE_Allocator_Adapter::sync"); return this->allocator_.sync (len, flags); } template ACE_INLINE int ACE_Allocator_Adapter::sync (void *addr, size_t len, int flags) { ACE_TRACE ("ACE_Allocator_Adapter::sync"); return this->allocator_.sync (addr, len, flags); } template ACE_INLINE int ACE_Malloc_T::ref_counter (void) { ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1); if (this->cb_ptr_ != 0) return this->cb_ptr_->ref_counter_; return -1; } template ACE_INLINE int ACE_Malloc_T::bad (void) { return this->bad_flag_; } template ACE_INLINE int ACE_Malloc_T::release (int close) { ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1); if (this->cb_ptr_ != 0) { int retv = --this->cb_ptr_->ref_counter_; #if 0 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("(%P) ACE_Malloc_T::release ->%d\n"), this->cb_ptr_->ref_counter_ - 1)); #endif /* 0 */ if (close) this->memory_pool_.release (0); if (retv == 0) this->remove (); return retv; } return -1; } template ACE_INLINE ACE_MEM_POOL & ACE_Malloc_T::memory_pool (void) { ACE_TRACE ("ACE_Malloc_T::memory_pool"); return this->memory_pool_; } template ACE_INLINE int ACE_Malloc_T::sync (ssize_t len, int flags) { ACE_TRACE ("ACE_Malloc_T::sync"); return this->memory_pool_.sync (len, flags); } template ACE_INLINE int ACE_Malloc_T::sync (void *addr, size_t len, int flags) { ACE_TRACE ("ACE_Malloc_T::sync"); return this->memory_pool_.sync (addr, len, flags); } template ACE_INLINE int ACE_Malloc_T::protect (ssize_t len, int flags) { ACE_TRACE ("ACE_Malloc_T::protect"); return this->memory_pool_.protect (len, flags); } template ACE_INLINE int ACE_Malloc_T::protect (void *addr, size_t len, int flags) { ACE_TRACE ("ACE_Malloc_T::protect"); return this->memory_pool_.protect (addr, len, flags); } template ACE_INLINE ACE_LOCK & ACE_Malloc_T::mutex (void) { return *this->lock_; } template ACE_INLINE void * ACE_Malloc_T::base_addr (void) { return this->cb_ptr_; } template ACE_INLINE ACE_Malloc::ACE_Malloc (const ACE_TCHAR *pool_name) : ACE_Malloc_T (pool_name) { } template ACE_INLINE ACE_Malloc::ACE_Malloc (const ACE_TCHAR *pool_name, const ACE_TCHAR *lock_name, const ACE_MEM_POOL_OPTIONS *options) : ACE_Malloc_T (pool_name, lock_name, options) { } #if !defined (ACE_HAS_TEMPLATE_TYPEDEFS) template ACE_INLINE ACE_Malloc::ACE_Malloc (const ACE_TCHAR *pool_name, const ACE_TCHAR *lock_name, const void *options) : ACE_Malloc_T (pool_name, lock_name, options) { } #endif /* !ACE_HAS_TEMPLATE_TYPEDEFS */ template ACE_INLINE ACE_Malloc_LIFO_Iterator::ACE_Malloc_LIFO_Iterator (ACE_Malloc &malloc, const char *name) : ACE_Malloc_LIFO_Iterator_T (malloc, name) { } template ACE_INLINE ACE_Malloc_FIFO_Iterator::ACE_Malloc_FIFO_Iterator (ACE_Malloc &malloc, const char *name) : ACE_Malloc_FIFO_Iterator_T (malloc, name) { } #if 0 template ACE_INLINE void ACE_Malloc_T::init_malloc_header_ptr (void* ptr) { #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1) new (ptr) ACE_MALLOC_HEADER_PTR (this->cb_ptr_, 0); #else ACE_UNUSED_ARG (ptr); #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */ } #endif