• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

I_ProxyAllocator.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /****************************************************************************
00025 
00026   ProxyAllocator.h
00027 
00028 
00029 
00030 *****************************************************************************/
00031 #ifndef _I_ProxyAllocator_h_
00032 #define _I_ProxyAllocator_h_
00033 
00034 #include "libts.h"
00035 
00036 class EThread;
00037 
00038 extern int thread_freelist_size;
00039 
00040 struct ProxyAllocator
00041 {
00042   int allocated;
00043   void *freelist;
00044 
00045   ProxyAllocator():allocated(0), freelist(0) { }
00046 };
00047 
00048 template<class C> inline C * thread_alloc(ClassAllocator<C> &a, ProxyAllocator & l)
00049 {
00050 #if TS_USE_FREELIST && !TS_USE_RECLAIMABLE_FREELIST
00051   if (l.freelist) {
00052     C *v = (C *) l.freelist;
00053     l.freelist = *(C **) l.freelist;
00054     l.allocated--;
00055     *(void **) v = *(void **) &a.proto.typeObject;
00056     return v;
00057   }
00058 #else
00059   (void)l;
00060 #endif
00061   return a.alloc();
00062 }
00063 
00064 template<class C> inline C * thread_alloc_init(ClassAllocator<C> &a, ProxyAllocator & l)
00065 {
00066 #if TS_USE_FREELIST && !TS_USE_RECLAIMABLE_FREELIST
00067   if (l.freelist) {
00068     C *v = (C *) l.freelist;
00069     l.freelist = *(C **) l.freelist;
00070     l.allocated--;
00071     memcpy((void *) v, (void *) &a.proto.typeObject, sizeof(C));
00072     return v;
00073   }
00074 #else
00075   (void)l;
00076 #endif
00077   return a.alloc();
00078 }
00079 
00080 template<class C> inline void
00081 thread_free(ClassAllocator<C> &a, C *p)
00082 {
00083   a.free(p);
00084 }
00085 
00086 static inline void
00087 thread_free(Allocator &a, void *p)
00088 {
00089   a.free_void(p);
00090 }
00091 
00092 template<class C> inline void
00093 thread_freeup(ClassAllocator<C> &a, ProxyAllocator & l)
00094 {
00095   while (l.freelist) {
00096     C *v = (C *) l.freelist;
00097     l.freelist = *(C **) l.freelist;
00098     l.allocated--;
00099     a.free(v);                  // we could use a bulk free here
00100   }
00101   ink_assert(!l.allocated);
00102 }
00103 
00104 void* thread_alloc(Allocator &a, ProxyAllocator &l);
00105 void thread_freeup(Allocator &a, ProxyAllocator &l);
00106 
00107 #define THREAD_ALLOC(_a, _t) thread_alloc(::_a, _t->_a)
00108 #define THREAD_ALLOC_INIT(_a, _t) thread_alloc_init(::_a, _t->_a)
00109 #if TS_USE_FREELIST && !TS_USE_RECLAIMABLE_FREELIST
00110 #define THREAD_FREE(_p, _a, _t) do {            \
00111   *(char **)_p = (char*)_t->_a.freelist;        \
00112   _t->_a.freelist = _p;                         \
00113   _t->_a.allocated++;                           \
00114   if (_t->_a.allocated > thread_freelist_size)  \
00115     thread_freeup(::_a, _t->_a);                \
00116 } while (0)
00117 #else /* !TS_USE_FREELIST || TS_USE_RECLAIMABLE_FREELIST */
00118 #define THREAD_FREE(_p, _a, _t) do {  \
00119   (void)_t;                           \
00120   thread_free(::_a, _p);              \
00121 } while (0)
00122 #endif
00123 
00124 #endif /* _ProxyAllocator_h_ */

Generated by  doxygen 1.7.1