Eneboo - Documentación para desarrolladores
src/hoard/src/globalheap.h
Ir a la documentación de este archivo.
00001 #ifndef _GLOBALHEAP_H_
00002 #define _GLOBALHEAP_H_
00003 
00004 #include "hoardsuperblock.h"
00005 #include "processheap.h"
00006 
00007 namespace Hoard {
00008 
00009 template <size_t SuperblockSize,
00010           int EmptinessClasses,
00011           class LockType>
00012 class GlobalHeap {
00013   
00014   class bogusThresholdFunctionClass {
00015   public:
00016     static inline bool function (int, int, size_t) {
00017       // We *never* cross the threshold for a process heap.
00018       return false;
00019     }
00020   };
00021   
00022 public:
00023 
00024   GlobalHeap (void) 
00025     : _theHeap (getHeap())
00026     {
00027     }
00028   
00029   typedef ProcessHeap<SuperblockSize, EmptinessClasses, LockType, bogusThresholdFunctionClass> SuperHeap;
00030   typedef HoardSuperblock<LockType, SuperblockSize, GlobalHeap> SuperblockType;
00031 
00032   void put (void * s, size_t sz) {
00033     assert (s);
00034     assert (((SuperblockType *) s)->isValidSuperblock());
00035     _theHeap->put ((typename SuperHeap::SuperblockType *) s,
00036                   sz);
00037   }
00038 
00039   SuperblockType * get (size_t sz, void * dest) {
00040     SuperblockType * s = 
00041       reinterpret_cast<SuperblockType *>
00042       (_theHeap->get (sz, reinterpret_cast<SuperHeap *>(dest)));
00043     if (s) {
00044       assert (s->isValidSuperblock());
00045     }
00046     return s;
00047   }
00048 
00049 private:
00050 
00051   SuperHeap * _theHeap;
00052 
00053   inline static SuperHeap * getHeap (void) {
00054     static double theHeapBuf[sizeof(SuperHeap) / sizeof(double) + 1];
00055     static SuperHeap * theHeap = new (&theHeapBuf[0]) SuperHeap;
00056     return theHeap;
00057   }
00058 
00059   // Prevent copying.
00060   GlobalHeap (const GlobalHeap&);
00061   GlobalHeap& operator=(const GlobalHeap&);
00062 
00063 };
00064 
00065 }
00066 
00067 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'