1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-21 15:12:11 +00:00

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.
This commit is contained in:
Andreas Kling 2021-08-24 13:27:49 +02:00
parent 0c1d41cc8a
commit a22634bb59

View file

@ -13,6 +13,7 @@
#include <AK/Optional.h> #include <AK/Optional.h>
#include <AK/OwnPtr.h> #include <AK/OwnPtr.h>
#include <AK/String.h> #include <AK/String.h>
#include <AK/TemporaryChange.h>
#include <AK/Time.h> #include <AK/Time.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <AK/WeakPtr.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 // We need to hold m_block_lock so that nobody can unblock a blocker as soon
// as it is constructed and registered elsewhere // as it is constructed and registered elsewhere
VERIFY(!m_in_block); VERIFY(!m_in_block);
m_in_block = true; TemporaryChange in_block_change(m_in_block, true);
BlockerType blocker(forward<Args>(args)...); BlockerType blocker(forward<Args>(args)...);
if (!blocker.setup_blocker()) { if (!blocker.setup_blocker()) {
blocker.will_unblock_immediately_without_blocking(Blocker::UnblockImmediatelyReason::UnblockConditionAlreadyMet); blocker.will_unblock_immediately_without_blocking(Blocker::UnblockImmediatelyReason::UnblockConditionAlreadyMet);
m_in_block = false;
return BlockResult::NotBlocked; return BlockResult::NotBlocked;
} }
@ -893,7 +894,6 @@ public:
// Timeout is already in the past // Timeout is already in the past
blocker.will_unblock_immediately_without_blocking(Blocker::UnblockImmediatelyReason::TimeoutInThePast); blocker.will_unblock_immediately_without_blocking(Blocker::UnblockImmediatelyReason::TimeoutInThePast);
m_blocker = nullptr; m_blocker = nullptr;
m_in_block = false;
return BlockResult::InterruptedByTimeout; return BlockResult::InterruptedByTimeout;
} }
} }
@ -938,7 +938,6 @@ public:
m_blocker = nullptr; m_blocker = nullptr;
} }
dbgln_if(THREAD_DEBUG, "<-- Thread {} unblocked from {} ({})", *this, &blocker, blocker.state_string()); dbgln_if(THREAD_DEBUG, "<-- Thread {} unblocked from {} ({})", *this, &blocker, blocker.state_string());
m_in_block = false;
break; break;
} }