summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-12-07 21:29:41 -0700
committerAndreas Kling <kling@serenityos.org>2020-12-12 21:28:12 +0100
commitda5cc34ebbdfcc5b37815d369fe0c0931df54c90 (patch)
tree21b1bf721a5dce58a0ea652cee8d05d74884f002 /Kernel/FileSystem
parent0918d8b1f8bae11a2ef97c79564a7e7c9a394eb5 (diff)
downloadserenity-da5cc34ebbdfcc5b37815d369fe0c0931df54c90.zip
Kernel: Fix some issues related to fixes and block conditions
Fix some problems with join blocks where the joining thread block condition was added twice, which lead to a crash when trying to unblock that condition a second time. Deferred block condition evaluation by File objects were also not properly keeping the File object alive, which lead to some random crashes and corruption problems. Other problems were caused by the fact that the Queued state didn't handle signals/interruptions consistently. To solve these issues we remove this state entirely, along with Thread::wait_on and change the WaitQueue into a BlockCondition instead. Also, deliver signals even if there isn't going to be a context switch to another thread. Fixes #4336 and #4330
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r--Kernel/FileSystem/FIFO.cpp4
-rw-r--r--Kernel/FileSystem/File.h17
2 files changed, 14 insertions, 7 deletions
diff --git a/Kernel/FileSystem/FIFO.cpp b/Kernel/FileSystem/FIFO.cpp
index 7878f4aa81..fe0d8d6cd3 100644
--- a/Kernel/FileSystem/FIFO.cpp
+++ b/Kernel/FileSystem/FIFO.cpp
@@ -71,7 +71,7 @@ NonnullRefPtr<FileDescription> FIFO::open_direction_blocking(FIFO::Direction dir
if (m_writers == 0) {
locker.unlock();
- Thread::current()->wait_on(m_write_open_queue, "FIFO");
+ m_write_open_queue.wait_on(nullptr, "FIFO");
locker.lock();
}
}
@@ -81,7 +81,7 @@ NonnullRefPtr<FileDescription> FIFO::open_direction_blocking(FIFO::Direction dir
if (m_readers == 0) {
locker.unlock();
- Thread::current()->wait_on(m_read_open_queue, "FIFO");
+ m_read_open_queue.wait_on(nullptr, "FIFO");
locker.lock();
}
}
diff --git a/Kernel/FileSystem/File.h b/Kernel/FileSystem/File.h
index ed56f1cc33..a56c148f59 100644
--- a/Kernel/FileSystem/File.h
+++ b/Kernel/FileSystem/File.h
@@ -142,17 +142,24 @@ protected:
{
if (Processor::current().in_irq()) {
// If called from an IRQ handler we need to delay evaluation
- // and unblocking of waiting threads
- Processor::deferred_call_queue([this]() {
- ASSERT(!Processor::current().in_irq());
- evaluate_block_conditions();
+ // and unblocking of waiting threads. Note that this File
+ // instance may be deleted until the deferred call is executed!
+ Processor::deferred_call_queue([self = make_weak_ptr()]() {
+ if (auto file = self.strong_ref())
+ file->do_evaluate_block_conditions();
});
} else {
- block_condition().unblock();
+ do_evaluate_block_conditions();
}
}
private:
+ ALWAYS_INLINE void do_evaluate_block_conditions()
+ {
+ ASSERT(!Processor::current().in_irq());
+ block_condition().unblock();
+ }
+
FileBlockCondition m_block_condition;
};