1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 19:45:08 +00:00

Fix broken SpinLock.

The SpinLock was all backwards and didn't actually work. Fixing it exposed
how wrong most of the locking here is.

I need to come up with a better granularity here.
This commit is contained in:
Andreas Kling 2018-10-29 21:54:11 +01:00
parent bea106fdb2
commit e6284a8774
24 changed files with 195 additions and 77 deletions

View file

@ -7,6 +7,7 @@ typedef int InterruptDisabler;
#endif
//#define DBFS_DEBUG
#define BLOCK_CACHE
DiskBackedFileSystem::DiskBackedFileSystem(RetainPtr<DiskDevice>&& device)
: m_device(move(device))
@ -42,6 +43,8 @@ ByteBuffer DiskBackedFileSystem::readBlock(unsigned index) const
#ifdef DBFS_DEBUG
kprintf("DiskBackedFileSystem::readBlock %u\n", index);
#endif
#ifdef BLOCK_CACHE
{
InterruptDisabler disabler;
auto it = m_blockCache.find(index);
@ -49,19 +52,24 @@ ByteBuffer DiskBackedFileSystem::readBlock(unsigned index) const
return (*it).value;
}
}
#endif
auto buffer = ByteBuffer::createUninitialized(blockSize());
//kprintf("created block buffer with size %u\n", blockSize());
DiskOffset baseOffset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(blockSize());
auto* bufferPointer = buffer.pointer();
device().read(baseOffset, blockSize(), bufferPointer);
bool success = device().read(baseOffset, blockSize(), bufferPointer);
ASSERT(success);
ASSERT(buffer.size() == blockSize());
#ifdef BLOCK_CACHE
{
InterruptDisabler disabler;
if (m_blockCache.size() >= 32)
m_blockCache.removeOneRandomly();
m_blockCache.set(index, buffer);
}
#endif
return buffer;
}