2010-03-19 18:12:22 +00:00
|
|
|
#ifndef __CONCRETE_BLOCK_CACHE_H__
|
|
|
|
#define __CONCRETE_BLOCK_CACHE_H__
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2010-03-21 22:33:16 +00:00
|
|
|
#include <Cache/BlockCache.h>
|
2010-03-19 18:12:22 +00:00
|
|
|
|
|
|
|
namespace Device {
|
|
|
|
|
|
|
|
class ConcreteBlockCache : public BlockCache {
|
|
|
|
public:
|
2011-02-22 02:59:33 +00:00
|
|
|
|
|
|
|
static BlockCachePointer Create(BlockDevicePointer device, unsigned size = 16);
|
|
|
|
|
2010-03-19 18:12:22 +00:00
|
|
|
virtual ~ConcreteBlockCache();
|
|
|
|
|
|
|
|
virtual void sync();
|
2010-05-18 19:59:00 +00:00
|
|
|
virtual void write(unsigned block, const void *vp);
|
2010-03-19 18:12:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
virtual void *acquire(unsigned block);
|
|
|
|
virtual void release(unsigned block, int flags);
|
|
|
|
virtual void markDirty(unsigned block);
|
|
|
|
|
2010-05-20 22:30:00 +00:00
|
|
|
|
2010-03-19 18:12:22 +00:00
|
|
|
private:
|
2011-02-22 02:59:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
ConcreteBlockCache(BlockDevicePointer device, unsigned size);
|
|
|
|
|
2010-03-19 18:12:22 +00:00
|
|
|
struct Entry {
|
|
|
|
unsigned block;
|
|
|
|
unsigned count;
|
|
|
|
bool dirty;
|
|
|
|
|
|
|
|
struct Entry *next;
|
|
|
|
struct Entry *prev;
|
|
|
|
struct Entry *nextHash;
|
|
|
|
|
|
|
|
uint8_t buffer[512];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-02-15 04:00:54 +00:00
|
|
|
typedef std::vector<Entry *>::iterator EntryIter;
|
|
|
|
|
2010-03-19 18:12:22 +00:00
|
|
|
enum { HashTableSize = 23 };
|
|
|
|
|
|
|
|
std::vector<Entry *>_buffers;
|
|
|
|
|
|
|
|
Entry *_hashTable[HashTableSize];
|
|
|
|
|
|
|
|
Entry *_first;
|
|
|
|
Entry *_last;
|
|
|
|
|
|
|
|
|
|
|
|
unsigned hashFunction(unsigned block);
|
|
|
|
|
|
|
|
Entry *findEntry(unsigned block);
|
|
|
|
void removeEntry(unsigned block);
|
|
|
|
void addEntry(Entry *);
|
|
|
|
|
|
|
|
Entry *newEntry(unsigned block);
|
|
|
|
|
|
|
|
void pushEntry(Entry *);
|
|
|
|
|
|
|
|
void setLast(Entry *);
|
2010-03-21 22:33:16 +00:00
|
|
|
void setFirst(Entry *);
|
|
|
|
|
2010-03-22 01:12:51 +00:00
|
|
|
void incrementCount(Entry *);
|
|
|
|
void decrementCount(Entry *);
|
2010-03-19 18:12:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2010-03-22 01:12:51 +00:00
|
|
|
|
|
|
|
#endif
|