kernel: Make StorageCache have a reference to its parent BlockDevice
All checks were successful
Build and test / build (push) Successful in 2m10s

This will make it easier to implement sync later on.
This commit is contained in:
apio 2024-08-09 18:52:56 +02:00
parent bfb45c7d4a
commit abbfd5825f
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 8 additions and 3 deletions

View File

@ -33,7 +33,7 @@ void StorageCache::clear()
m_mutex.unlock();
}
StorageCache::StorageCache()
StorageCache::StorageCache(BlockDevice* device) : m_device(device)
{
g_storage_caches.append(this);
}

View File

@ -4,12 +4,15 @@
#include <luna/HashMap.h>
#include <luna/LinkedList.h>
class BlockDevice;
class StorageCache : public LinkedListNode<StorageCache>
{
public:
struct CacheEntry
{
Buffer buffer {};
bool dirty;
};
void lock()
@ -28,10 +31,11 @@ class StorageCache : public LinkedListNode<StorageCache>
static void clear_caches();
StorageCache();
StorageCache(BlockDevice* device);
~StorageCache();
private:
HashMap<u64, CacheEntry> m_cache_entries;
BlockDevice* m_device;
Mutex m_mutex;
};

View File

@ -2,7 +2,8 @@
#include "arch/MMU.h"
#include <luna/Common.h>
BlockDevice::BlockDevice(u64 block_size, u64 num_blocks) : m_cache(), m_block_size(block_size), m_num_blocks(num_blocks)
BlockDevice::BlockDevice(u64 block_size, u64 num_blocks)
: m_cache(this), m_block_size(block_size), m_num_blocks(num_blocks)
{
}