mirror of
https://github.com/ksherlock/profuse.git
synced 2024-10-31 17:04:27 +00:00
6b6ad10ba0
git-svn-id: https://profuse.googlecode.com/svn/branches/v2@324 aa027e90-d47c-11dd-86d7-074df07e0730
71 lines
1.3 KiB
C++
71 lines
1.3 KiB
C++
#ifndef __CONCRETE_BLOCK_CACHE_H__
|
|
#define __CONCRETE_BLOCK_CACHE_H__
|
|
|
|
#include <vector>
|
|
|
|
#include <Cache/BlockCache.h>
|
|
|
|
namespace Device {
|
|
|
|
class ConcreteBlockCache : public BlockCache {
|
|
public:
|
|
ConcreteBlockCache(BlockDevice *device, unsigned size = 16);
|
|
virtual ~ConcreteBlockCache();
|
|
|
|
virtual void sync();
|
|
virtual void write(unsigned block, const void *vp);
|
|
|
|
|
|
virtual void *acquire(unsigned block);
|
|
virtual void release(unsigned block, int flags);
|
|
virtual void markDirty(unsigned block);
|
|
|
|
|
|
|
|
private:
|
|
struct Entry {
|
|
unsigned block;
|
|
unsigned count;
|
|
bool dirty;
|
|
|
|
struct Entry *next;
|
|
struct Entry *prev;
|
|
struct Entry *nextHash;
|
|
|
|
uint8_t buffer[512];
|
|
|
|
};
|
|
|
|
typedef std::vector<Entry *>::iterator EntryIter;
|
|
|
|
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 *);
|
|
void setFirst(Entry *);
|
|
|
|
void incrementCount(Entry *);
|
|
void decrementCount(Entry *);
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|