From a22634bb593b29c97f90e6fc8bf36ff5c263d85f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 24 Aug 2021 13:27:49 +0200 Subject: [PATCH] Kernel: Use TemporaryChange to update Thread::m_in_block Let's use an RAII helper to avoid having to update this on every path out of block(). Note that this extends the time under `m_in_block == true` by a little but that should be harmless. --- Kernel/Thread.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Kernel/Thread.h b/Kernel/Thread.h index a4026c7176..3d33fc6f06 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -847,12 +848,12 @@ public: // We need to hold m_block_lock so that nobody can unblock a blocker as soon // as it is constructed and registered elsewhere VERIFY(!m_in_block); - m_in_block = true; + TemporaryChange in_block_change(m_in_block, true); + BlockerType blocker(forward(args)...); if (!blocker.setup_blocker()) { blocker.will_unblock_immediately_without_blocking(Blocker::UnblockImmediatelyReason::UnblockConditionAlreadyMet); - m_in_block = false; return BlockResult::NotBlocked; } @@ -893,7 +894,6 @@ public: // Timeout is already in the past blocker.will_unblock_immediately_without_blocking(Blocker::UnblockImmediatelyReason::TimeoutInThePast); m_blocker = nullptr; - m_in_block = false; return BlockResult::InterruptedByTimeout; } } @@ -938,7 +938,6 @@ public: m_blocker = nullptr; } dbgln_if(THREAD_DEBUG, "<-- Thread {} unblocked from {} ({})", *this, &blocker, blocker.state_string()); - m_in_block = false; break; }