00001
00002
00003
00004
00005
00006 template <class T> ACE_INLINE T *
00007 ACE_Cached_Mem_Pool_Node<T>::addr (void)
00008 {
00009
00010
00011
00012 return ACE_static_cast (T *, ACE_static_cast (void *, this));
00013 }
00014
00015 template <class T> ACE_INLINE ACE_Cached_Mem_Pool_Node<T> *
00016 ACE_Cached_Mem_Pool_Node<T>::get_next (void)
00017 {
00018 return this->next_;
00019 }
00020
00021 template <class T> ACE_INLINE void
00022 ACE_Cached_Mem_Pool_Node<T>::set_next (ACE_Cached_Mem_Pool_Node<T> *ptr)
00023 {
00024 this->next_ = ptr;
00025 }
00026
00027 template <class T, class ACE_LOCK> ACE_INLINE void *
00028 ACE_Cached_Allocator<T, ACE_LOCK>::malloc (size_t nbytes)
00029 {
00030
00031 if (nbytes > sizeof (T))
00032 return 0;
00033
00034
00035
00036 return this->free_list_.remove ()->addr ();
00037 }
00038
00039 template <class T, class ACE_LOCK> ACE_INLINE void *
00040 ACE_Cached_Allocator<T, ACE_LOCK>::calloc (size_t nbytes,
00041 char initial_value)
00042 {
00043
00044 if (nbytes > sizeof (T))
00045 return 0;
00046
00047
00048
00049 void *ptr = this->free_list_.remove ()->addr ();
00050 ACE_OS::memset (ptr, initial_value, sizeof (T));
00051 return ptr;
00052 }
00053
00054 template <class T, class ACE_LOCK> ACE_INLINE void *
00055 ACE_Cached_Allocator<T, ACE_LOCK>::calloc (size_t,
00056 size_t,
00057 char)
00058 {
00059 ACE_NOTSUP_RETURN (0);
00060 }
00061
00062 template <class T, class ACE_LOCK> ACE_INLINE void
00063 ACE_Cached_Allocator<T, ACE_LOCK>::free (void * ptr)
00064 {
00065 if (ptr != 0)
00066 this->free_list_.add ((ACE_Cached_Mem_Pool_Node<T> *) ptr) ;
00067 }
00068
00069 template <class ACE_LOCK> ACE_INLINE void *
00070 ACE_Dynamic_Cached_Allocator<ACE_LOCK>::malloc (size_t nbytes)
00071 {
00072
00073 if (nbytes > chunk_size_)
00074 return 0;
00075
00076
00077
00078 return this->free_list_.remove ()->addr ();
00079 }
00080
00081 template <class ACE_LOCK> ACE_INLINE void *
00082 ACE_Dynamic_Cached_Allocator<ACE_LOCK>::calloc (size_t nbytes,
00083 char initial_value)
00084 {
00085
00086 if (nbytes > chunk_size_)
00087 return 0;
00088
00089
00090
00091 void *ptr = this->free_list_.remove ()->addr ();
00092 ACE_OS::memset (ptr, initial_value, chunk_size_);
00093 return ptr;
00094 }
00095
00096 template <class ACE_LOCK> ACE_INLINE void *
00097 ACE_Dynamic_Cached_Allocator<ACE_LOCK>::calloc (size_t, size_t, char)
00098 {
00099 ACE_NOTSUP_RETURN (0);
00100 }
00101
00102 template <class ACE_LOCK> ACE_INLINE void
00103 ACE_Dynamic_Cached_Allocator<ACE_LOCK>::free (void * ptr)
00104 {
00105 this->free_list_.add ((ACE_Cached_Mem_Pool_Node<char> *) ptr);
00106 }
00107
00108 template <class MALLOC> ACE_INLINE void *
00109 ACE_Allocator_Adapter<MALLOC>::malloc (size_t nbytes)
00110 {
00111 ACE_TRACE ("ACE_Allocator_Adapter<MALLOC>::malloc");
00112 return this->allocator_.malloc (nbytes);
00113 }
00114
00115 template <class MALLOC> ACE_INLINE void *
00116 ACE_Allocator_Adapter<MALLOC>::calloc (size_t nbytes,
00117 char initial_value)
00118 {
00119 ACE_TRACE ("ACE_Allocator_Adapter<MALLOC>::calloc");
00120 return this->allocator_.calloc (nbytes, initial_value);
00121 }
00122
00123 template <class MALLOC> ACE_INLINE void *
00124 ACE_Allocator_Adapter<MALLOC>::calloc (size_t n_elem,
00125 size_t elem_size,
00126 char initial_value)
00127 {
00128 ACE_TRACE ("ACE_Allocator_Adapter<MALLOC>::calloc");
00129 return this->allocator_.calloc (n_elem, elem_size, initial_value);
00130 }
00131
00132 template <class MALLOC> ACE_INLINE MALLOC &
00133 ACE_Allocator_Adapter<MALLOC>::alloc (void)
00134 {
00135 ACE_TRACE ("ACE_Allocator_Adapter<MALLOC>::allocator");
00136 return this->allocator_;
00137 }
00138
00139 template <class MALLOC> ACE_INLINE void
00140 ACE_Allocator_Adapter<MALLOC>::free (void *ptr)
00141 {
00142 ACE_TRACE ("ACE_Allocator_Adapter<MALLOC>::free");
00143 this->allocator_.free (ptr);
00144 }
00145
00146 template <class MALLOC> ACE_INLINE int
00147 ACE_Allocator_Adapter<MALLOC>::remove (void)
00148 {
00149 ACE_TRACE ("ACE_Allocator_Adapter<MALLOC>::remove");
00150 return this->allocator_.remove ();
00151 }
00152
00153 template <class MALLOC> ACE_INLINE int
00154 ACE_Allocator_Adapter<MALLOC>::trybind (const char *name,
00155 void *&pointer)
00156 {
00157 ACE_TRACE ("ACE_Allocator_Adapter<MALLOC>::trybind");
00158 return this->allocator_.trybind (name, pointer);
00159 }
00160
00161 template <class MALLOC> ACE_INLINE int
00162 ACE_Allocator_Adapter<MALLOC>::bind (const char *name,
00163 void *pointer,
00164 int duplicates)
00165 {
00166 ACE_TRACE ("ACE_Allocator_Adapter<MALLOC>::bind");
00167 return this->allocator_.bind (name, pointer, duplicates);
00168 }
00169
00170 template <class MALLOC> ACE_INLINE int
00171 ACE_Allocator_Adapter<MALLOC>::find (const char *name,
00172 void *&pointer)
00173 {
00174 ACE_TRACE ("ACE_Allocator_Adapter<MALLOC>::find");
00175 return this->allocator_.find (name, pointer);
00176 }
00177
00178 template <class MALLOC> ACE_INLINE int
00179 ACE_Allocator_Adapter<MALLOC>::find (const char *name)
00180 {
00181 ACE_TRACE ("ACE_Allocator_Adapter<MALLOC>::find");
00182 return this->allocator_.find (name);
00183 }
00184
00185 template <class MALLOC> ACE_INLINE int
00186 ACE_Allocator_Adapter<MALLOC>::unbind (const char *name, void *&pointer)
00187 {
00188 ACE_TRACE ("ACE_Allocator_Adapter<MALLOC>::unbind");
00189 return this->allocator_.unbind (name, pointer);
00190 }
00191
00192 template <class MALLOC> ACE_INLINE int
00193 ACE_Allocator_Adapter<MALLOC>::unbind (const char *name)
00194 {
00195 ACE_TRACE ("ACE_Allocator_Adapter<MALLOC>::unbind");
00196 return this->allocator_.unbind (name);
00197 }
00198
00199 template <class MALLOC> ACE_INLINE int
00200 ACE_Allocator_Adapter<MALLOC>::sync (ssize_t len, int flags)
00201 {
00202 ACE_TRACE ("ACE_Allocator_Adapter<MALLOC>::sync");
00203 return this->allocator_.sync (len, flags);
00204 }
00205
00206 template <class MALLOC> ACE_INLINE int
00207 ACE_Allocator_Adapter<MALLOC>::sync (void *addr, size_t len, int flags)
00208 {
00209 ACE_TRACE ("ACE_Allocator_Adapter<MALLOC>::sync");
00210 return this->allocator_.sync (addr, len, flags);
00211 }
00212
00213 template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> ACE_INLINE int
00214 ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ref_counter (void)
00215 {
00216 ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
00217 if (this->cb_ptr_ != 0)
00218 return this->cb_ptr_->ref_counter_;
00219
00220 return -1;
00221 }
00222
00223 template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> ACE_INLINE int
00224 ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::bad (void)
00225 {
00226 return this->bad_flag_;
00227 }
00228
00229 template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> ACE_INLINE int
00230 ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::release (int close)
00231 {
00232 ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
00233 if (this->cb_ptr_ != 0)
00234 {
00235 int retv = --this->cb_ptr_->ref_counter_;
00236
00237 #if 0
00238 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("(%P) ACE_Malloc_T::release ->%d\n"),
00239 this->cb_ptr_->ref_counter_ - 1));
00240 #endif
00241 if (close)
00242 this->memory_pool_.release (0);
00243
00244 if (retv == 0)
00245 this->remove ();
00246 return retv;
00247 }
00248 return -1;
00249 }
00250
00251 template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> ACE_INLINE ACE_MEM_POOL &
00252 ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::memory_pool (void)
00253 {
00254 ACE_TRACE ("ACE_Malloc_T<MEMORY_POOL, ACE_LOCK, ACE_CB>::memory_pool");
00255 return this->memory_pool_;
00256 }
00257
00258 template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> ACE_INLINE int
00259 ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::sync (ssize_t len,
00260 int flags)
00261 {
00262 ACE_TRACE ("ACE_Malloc_T<MEMORY_POOL, ACE_LOCK, ACE_CB>::sync");
00263 return this->memory_pool_.sync (len, flags);
00264 }
00265
00266 template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> ACE_INLINE int
00267 ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::sync (void *addr,
00268 size_t len,
00269 int flags)
00270 {
00271 ACE_TRACE ("ACE_Malloc_T<MEMORY_POOL, ACE_LOCK, ACE_CB>::sync");
00272 return this->memory_pool_.sync (addr, len, flags);
00273 }
00274
00275 template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> ACE_INLINE int
00276 ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::protect (ssize_t len,
00277 int flags)
00278 {
00279 ACE_TRACE ("ACE_Malloc_T<MEMORY_POOL, ACE_LOCK, ACE_CB>::protect");
00280 return this->memory_pool_.protect (len, flags);
00281 }
00282
00283 template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> ACE_INLINE int
00284 ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::protect (void *addr,
00285 size_t len,
00286 int flags)
00287 {
00288 ACE_TRACE ("ACE_Malloc_T<MEMORY_POOL, ACE_LOCK, ACE_CB>::protect");
00289 return this->memory_pool_.protect (addr, len, flags);
00290 }
00291
00292 template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> ACE_INLINE ACE_LOCK &
00293 ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::mutex (void)
00294 {
00295 return *this->lock_;
00296 }
00297
00298 template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> ACE_INLINE void *
00299 ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::base_addr (void)
00300 {
00301 return this->cb_ptr_;
00302 }
00303
00304 template <ACE_MEM_POOL_1, class ACE_LOCK> ACE_INLINE
00305 ACE_Malloc<ACE_MEM_POOL_2, ACE_LOCK>::ACE_Malloc (const ACE_TCHAR *pool_name)
00306 : ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_Control_Block> (pool_name)
00307 {
00308 }
00309
00310 template <ACE_MEM_POOL_1, class ACE_LOCK> ACE_INLINE
00311 ACE_Malloc<ACE_MEM_POOL_2, ACE_LOCK>::ACE_Malloc (const ACE_TCHAR *pool_name,
00312 const ACE_TCHAR *lock_name,
00313 const ACE_MEM_POOL_OPTIONS *options)
00314 : ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_Control_Block> (pool_name, lock_name, options)
00315 {
00316 }
00317
00318 #if !defined (ACE_HAS_TEMPLATE_TYPEDEFS)
00319 template <ACE_MEM_POOL_1, class ACE_LOCK> ACE_INLINE
00320 ACE_Malloc<ACE_MEM_POOL_2, ACE_LOCK>::ACE_Malloc (const ACE_TCHAR *pool_name,
00321 const ACE_TCHAR *lock_name,
00322 const void *options)
00323 : ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_Control_Block> (pool_name, lock_name, options)
00324 {
00325 }
00326 #endif
00327
00328 template <ACE_MEM_POOL_1, class ACE_LOCK> ACE_INLINE
00329 ACE_Malloc_LIFO_Iterator<ACE_MEM_POOL_2, ACE_LOCK>::ACE_Malloc_LIFO_Iterator (ACE_Malloc<ACE_MEM_POOL_2, ACE_LOCK> &malloc,
00330 const char *name)
00331 : ACE_Malloc_LIFO_Iterator_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_Control_Block> (malloc, name)
00332 {
00333 }
00334
00335 template <ACE_MEM_POOL_1, class ACE_LOCK> ACE_INLINE
00336 ACE_Malloc_FIFO_Iterator<ACE_MEM_POOL_2, ACE_LOCK>::ACE_Malloc_FIFO_Iterator (ACE_Malloc<ACE_MEM_POOL_2, ACE_LOCK> &malloc,
00337 const char *name)
00338 : ACE_Malloc_FIFO_Iterator_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_Control_Block> (malloc, name)
00339 {
00340 }
00341
00342
00343
00344 #if 0
00345 template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> ACE_INLINE void
00346 ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::init_malloc_header_ptr (void* ptr)
00347 {
00348 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
00349 new (ptr) ACE_MALLOC_HEADER_PTR (this->cb_ptr_, 0);
00350 #else
00351 ACE_UNUSED_ARG (ptr);
00352 #endif
00353 }
00354 #endif