Eneboo - Documentación para desarrolladores
src/hoard/src/alignedsuperblockheap.h
Ir a la documentación de este archivo.
00001 // -*- C++ -*-
00002 
00003 #ifndef _ALIGNEDSUPERBLOCKHEAP_H_
00004 #define _ALIGNEDSUPERBLOCKHEAP_H_
00005 
00006 #include "mmapheap.h"
00007 #include "sassert.h"
00008 
00009 #include "conformantheap.h"
00010 #include "lockedheap.h"
00011 #include "fixedrequestheap.h"
00012 #include "dllist.h"
00013 
00014 // Always requests aligned superblocks.
00015 #include "alignedmmap.h"
00016 
00017 namespace Hoard {
00018 
00019 template <size_t SuperblockSize,
00020           class TheLockType>
00021 class SuperblockStore {
00022 public:
00023 
00024   enum { Alignment = AlignedMmap<SuperblockSize, TheLockType>::Alignment };
00025 
00026   void * malloc (size_t sz) {
00027     sz = sz; // to avoid warning.
00028     assert (sz == SuperblockSize);
00029     if (_freeSuperblocks.isEmpty()) {
00030       // Get more memory.
00031       void * ptr = _superblockSource.malloc (ChunksToGrab * SuperblockSize);
00032       if (!ptr) {
00033         return NULL;
00034       }
00035       char * p = (char *) ptr;
00036       for (int i = 0; i < ChunksToGrab; i++) {
00037         _freeSuperblocks.insert ((DLList::Entry *) p);
00038         p += SuperblockSize;
00039       }
00040     }
00041     return _freeSuperblocks.get();
00042   }
00043 
00044   void free (void * ptr) {
00045     _freeSuperblocks.insert ((DLList::Entry *) ptr);
00046   }
00047 
00048 private:
00049 
00050 #if defined(__SVR4)
00051   enum { ChunksToGrab = 1 };
00052 
00053   // We only get 64K chunks from mmap on Solaris, so we need to grab
00054   // more chunks (and align them to 64K!) for smaller superblock sizes.
00055   // Right now, we do not handle this case and just assert here that
00056   // we are getting chunks of 64K.
00057 
00058   HL::sassert<(SuperblockSize == 65536)> PreventMmapFragmentation;
00059 #else
00060   enum { ChunksToGrab = 1 };
00061 #endif
00062 
00063   AlignedMmap<SuperblockSize, TheLockType> _superblockSource;
00064   DLList _freeSuperblocks;
00065 
00066 };
00067 
00068 }
00069 
00070 
00071 namespace Hoard {
00072 
00073 template <class TheLockType,
00074           size_t SuperblockSize>
00075 class AlignedSuperblockHeapHelper :
00076   public ConformantHeap<HL::LockedHeap<TheLockType,
00077                                        FixedRequestHeap<SuperblockSize, 
00078                                                         SuperblockStore<SuperblockSize, TheLockType> > > > {};
00079 
00080 
00081 #if 0
00082 
00083 template <class TheLockType,
00084           size_t SuperblockSize>
00085 class AlignedSuperblockHeap : public AlignedMmap<SuperblockSize,TheLockType> {};
00086 
00087 
00088 #else
00089 
00090 template <class TheLockType,
00091           size_t SuperblockSize>
00092 class AlignedSuperblockHeap :
00093   public AlignedSuperblockHeapHelper<TheLockType, SuperblockSize> {
00094 
00095   HL::sassert<(AlignedSuperblockHeapHelper<TheLockType, SuperblockSize>::Alignment % SuperblockSize == 0)> EnsureProperAlignment;
00096 
00097 };
00098 #endif
00099 
00100 }
00101 
00102 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'