1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-02 22:52:07 +00:00

Kernel: Protect internal structures in InodeWatcher with spinlocks

This was the last change that was needed to be able boot with the flag
of LOCK_IN_CRITICAL_DEBUG. That flag is not always enabled because there
are still other issues in which we hold a spinlock and still try to lock
a mutex.

Instead of using one global mutex we can protect internal structures of
the InodeWatcher class with SpinlockProtected wrappers. This in turn
allows the InodeWatcher code to be called from other parts in the kernel
while holding a prior spinlock properly.
This commit is contained in:
Liav A 2023-04-21 14:48:11 +03:00 committed by Andreas Kling
parent cf3835b29b
commit ee4e9b807a
2 changed files with 85 additions and 76 deletions

View file

@ -15,6 +15,8 @@
#include <Kernel/API/InodeWatcherEvent.h>
#include <Kernel/FileSystem/File.h>
#include <Kernel/Forward.h>
#include <Kernel/Locking/MutexProtected.h>
#include <Kernel/Locking/SpinlockProtected.h>
namespace Kernel {
@ -63,20 +65,22 @@ public:
private:
explicit InodeWatcher() { }
mutable Mutex m_lock;
struct Event {
int wd { 0 };
InodeWatcherEvent::Type type { InodeWatcherEvent::Type::Invalid };
OwnPtr<KString> path;
};
CircularQueue<Event, 32> m_queue;
SpinlockProtected<CircularQueue<Event, 32>, LockRank::None> m_queue;
Checked<int> m_wd_counter { 1 };
// NOTE: These two hashmaps provide two different ways of reaching the same
// watch description, so they will overlap.
HashMap<int, NonnullOwnPtr<WatchDescription>> m_wd_to_watches;
HashMap<InodeIdentifier, WatchDescription*> m_inode_to_watches;
struct WatchMaps {
HashMap<int, NonnullOwnPtr<WatchDescription>> wd_to_watches;
HashMap<InodeIdentifier, WatchDescription*> inode_to_watches;
};
mutable SpinlockProtected<WatchMaps, LockRank::None> m_watch_maps;
};
}