00001
00006 #ifndef _GARBAGECOLLECTOR_H
00007 #define _GARBAGECOLLECTOR_H
00008
00009 #include <list>
00010 #include <set>
00011 #include <utility>
00012 #include <deque>
00013 #include <pthread.h>
00014
00015 #include "Space.h"
00016 #include "Cache.h"
00017
00027 class GarbageCollector {
00028
00029 private:
00030
00031 typedef std::list<Space*> SpaceList;
00032 typedef std::set<Space*> SpaceSet;
00033
00034 Cache *cache;
00035 unsigned sleepInterval;
00036 SpaceList spaceList;
00037 SpaceSet spacesToRemove;
00038 SpaceList spacesToAdd;
00039
00040 pthread_mutex_t removeMutex;
00041 pthread_mutex_t addMutex;
00042
00043 pthread_t threadID;
00044
00045
00046 unsigned reqHistoryLimiter;
00047 std::map<Space *, std::deque<unsigned> *> reqHistoryMap;
00048 std::deque<unsigned> reqHistoryTotal;
00049 unsigned long long quotaToDistribute;
00050 unsigned long long nextQuotaToDistribute;
00051 std::map<Space *, unsigned long long> requiredMinimum;
00052 unsigned long long maxHardQuota;
00053
00054 public:
00055
00062 GarbageCollector(Cache *cache, unsigned sleepInterval);
00063
00067 virtual ~GarbageCollector();
00068
00074 void addObservedSpace(Space *space);
00075
00081 void removeObservedSpace(Space * space);
00082
00088 void setInterval(unsigned interval);
00089
00093 void operator()();
00094
00095 private:
00096
00097 void collect(Space * space, bool goBelowQuota);
00098
00107 unsigned long long determineNewQuota(Space * space);
00108
00109 };
00110
00114 void * GCThread(void * arg);
00115
00116
00117
00118 #endif