diff options
author | Andreas Kling <kling@serenityos.org> | 2022-02-03 15:47:21 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-03 16:11:26 +0100 |
commit | 0bebf013e348f52f218535ebd3d82c9599ea5818 (patch) | |
tree | 702ac147dfeb4f3f47169e7cdb613fcc3f63eb02 | |
parent | 64254b5df8c24141fa75038078b3bcdab49b1751 (diff) | |
download | serenity-0bebf013e348f52f218535ebd3d82c9599ea5818.zip |
Kernel: Protect InodeWatcher internals with spinlock instead of mutex
-rw-r--r-- | Kernel/FileSystem/InodeWatcher.cpp | 14 | ||||
-rw-r--r-- | Kernel/FileSystem/InodeWatcher.h | 2 |
2 files changed, 8 insertions, 8 deletions
diff --git a/Kernel/FileSystem/InodeWatcher.cpp b/Kernel/FileSystem/InodeWatcher.cpp index e3563f599b..1d1ccebd08 100644 --- a/Kernel/FileSystem/InodeWatcher.cpp +++ b/Kernel/FileSystem/InodeWatcher.cpp @@ -24,13 +24,13 @@ InodeWatcher::~InodeWatcher() bool InodeWatcher::can_read(const OpenFileDescription&, u64) const { - MutexLocker locker(m_lock); + SpinlockLocker locker(m_lock); return !m_queue.is_empty(); } ErrorOr<size_t> InodeWatcher::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t buffer_size) { - MutexLocker locker(m_lock); + SpinlockLocker locker(m_lock); if (m_queue.is_empty()) // can_read will catch the blocking case. return EAGAIN; @@ -69,7 +69,7 @@ ErrorOr<size_t> InodeWatcher::read(OpenFileDescription&, u64, UserOrKernelBuffer ErrorOr<void> InodeWatcher::close() { - MutexLocker locker(m_lock); + SpinlockLocker locker(m_lock); for (auto& entry : m_wd_to_watches) { auto& inode = const_cast<Inode&>(entry.value->inode); @@ -88,7 +88,7 @@ ErrorOr<NonnullOwnPtr<KString>> InodeWatcher::pseudo_path(const OpenFileDescript void InodeWatcher::notify_inode_event(Badge<Inode>, InodeIdentifier inode_id, InodeWatcherEvent::Type event_type, StringView name) { - MutexLocker locker(m_lock); + SpinlockLocker locker(m_lock); auto it = m_inode_to_watches.find(inode_id); if (it == m_inode_to_watches.end()) @@ -107,7 +107,7 @@ void InodeWatcher::notify_inode_event(Badge<Inode>, InodeIdentifier inode_id, In ErrorOr<int> InodeWatcher::register_inode(Inode& inode, unsigned event_mask) { - MutexLocker locker(m_lock); + SpinlockLocker locker(m_lock); if (m_inode_to_watches.find(inode.identifier()) != m_inode_to_watches.end()) return EEXIST; @@ -142,7 +142,7 @@ ErrorOr<int> InodeWatcher::register_inode(Inode& inode, unsigned event_mask) ErrorOr<void> InodeWatcher::unregister_by_wd(int wd) { - MutexLocker locker(m_lock); + SpinlockLocker locker(m_lock); auto it = m_wd_to_watches.find(wd); if (it == m_wd_to_watches.end()) @@ -159,7 +159,7 @@ ErrorOr<void> InodeWatcher::unregister_by_wd(int wd) void InodeWatcher::unregister_by_inode(Badge<Inode>, InodeIdentifier identifier) { - MutexLocker locker(m_lock); + SpinlockLocker locker(m_lock); auto it = m_inode_to_watches.find(identifier); if (it == m_inode_to_watches.end()) diff --git a/Kernel/FileSystem/InodeWatcher.h b/Kernel/FileSystem/InodeWatcher.h index 39d80652ab..a3d5ece833 100644 --- a/Kernel/FileSystem/InodeWatcher.h +++ b/Kernel/FileSystem/InodeWatcher.h @@ -64,7 +64,7 @@ public: private: explicit InodeWatcher() { } - mutable Mutex m_lock; + mutable Spinlock m_lock; struct Event { int wd { 0 }; |