apio
abbfd5825f
All checks were successful
Build and test / build (push) Successful in 2m10s
This will make it easier to implement sync later on.
42 lines
680 B
C++
42 lines
680 B
C++
#pragma once
|
|
#include "lib/Mutex.h"
|
|
#include <luna/Buffer.h>
|
|
#include <luna/HashMap.h>
|
|
#include <luna/LinkedList.h>
|
|
|
|
class BlockDevice;
|
|
|
|
class StorageCache : public LinkedListNode<StorageCache>
|
|
{
|
|
public:
|
|
struct CacheEntry
|
|
{
|
|
Buffer buffer {};
|
|
bool dirty;
|
|
};
|
|
|
|
void lock()
|
|
{
|
|
return m_mutex.lock();
|
|
}
|
|
|
|
void unlock()
|
|
{
|
|
return m_mutex.unlock();
|
|
}
|
|
|
|
Result<CacheEntry*> fetch_entry(u64 block);
|
|
|
|
void clear();
|
|
|
|
static void clear_caches();
|
|
|
|
StorageCache(BlockDevice* device);
|
|
~StorageCache();
|
|
|
|
private:
|
|
HashMap<u64, CacheEntry> m_cache_entries;
|
|
BlockDevice* m_device;
|
|
Mutex m_mutex;
|
|
};
|