diff options
author | Andreas Kling <kling@serenityos.org> | 2021-08-24 13:27:49 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-24 16:37:28 +0200 |
commit | a22634bb593b29c97f90e6fc8bf36ff5c263d85f (patch) | |
tree | 634c5ae0da03b152595394676b8ea5b81bce8e43 /Kernel/Thread.h | |
parent | 0c1d41cc8a10595e4449f9cc92681ee9e90e57c2 (diff) | |
download | serenity-a22634bb593b29c97f90e6fc8bf36ff5c263d85f.zip |
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.
Diffstat (limited to 'Kernel/Thread.h')
-rw-r--r-- | Kernel/Thread.h | 7 |
1 files 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 <AK/Optional.h> #include <AK/OwnPtr.h> #include <AK/String.h> +#include <AK/TemporaryChange.h> #include <AK/Time.h> #include <AK/Vector.h> #include <AK/WeakPtr.h> @@ -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>(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; } |