summaryrefslogtreecommitdiff
path: root/Kernel/Thread.h
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-08-23 02:09:08 +0200
committerAndreas Kling <kling@serenityos.org>2021-08-23 02:13:04 +0200
commit7006cb82bde1dbcd9465186fd31aa884e679f92c (patch)
tree9504d4c1ae3d4d936e6f5c68af0168c8164c347d /Kernel/Thread.h
parent39474830a94fd812dca51ebe622751e364dc1044 (diff)
downloadserenity-7006cb82bde1dbcd9465186fd31aa884e679f92c.zip
Kernel: Rename Blocker::not_blocking(bool) to something more descriptive
Namely, will_unblock_immediately_without_blocking(Reason). This virtual function is called on a blocker *before any block occurs*, if it turns out that we don't need to block the thread after all. This can happens for one of two reasons: - UnblockImmediatelyReason::UnblockConditionAlreadyMet We don't need to block the thread because the condition for unblocking it is already met. - UnblockImmediatelyReason::TimeoutInThePast We don't need to block the thread because a timeout was specified and that timeout is already in the past. This patch does not introduce any behavior changes, it's only meant to clarify this part of the blocking logic.
Diffstat (limited to 'Kernel/Thread.h')
-rw-r--r--Kernel/Thread.h27
1 files changed, 17 insertions, 10 deletions
diff --git a/Kernel/Thread.h b/Kernel/Thread.h
index d223c6212e..c15c14ecd4 100644
--- a/Kernel/Thread.h
+++ b/Kernel/Thread.h
@@ -300,7 +300,14 @@ public:
virtual Type blocker_type() const = 0;
virtual const BlockTimeout& override_timeout(const BlockTimeout& timeout) { return timeout; }
virtual bool can_be_interrupted() const { return true; }
- virtual void not_blocking(bool) = 0;
+
+ enum class UnblockImmediatelyReason {
+ UnblockConditionAlreadyMet,
+ TimeoutInThePast,
+ };
+
+ virtual void will_unblock_immediately_without_blocking(UnblockImmediatelyReason) = 0;
+
virtual void was_unblocked(bool did_timeout)
{
if (did_timeout) {
@@ -515,7 +522,7 @@ public:
virtual StringView state_string() const override { return "Joining"sv; }
virtual bool can_be_interrupted() const override { return false; }
virtual bool should_block() override { return !m_join_error && m_should_block; }
- virtual void not_blocking(bool) override;
+ virtual void will_unblock_immediately_without_blocking(UnblockImmediatelyReason) override;
bool unblock(void*, bool);
@@ -534,7 +541,7 @@ public:
virtual Type blocker_type() const override { return Type::Queue; }
virtual StringView state_string() const override { return m_block_reason.is_null() ? m_block_reason : "Queue"sv; }
- virtual void not_blocking(bool) override { }
+ virtual void will_unblock_immediately_without_blocking(UnblockImmediatelyReason) override { }
virtual bool should_block() override
{
@@ -556,7 +563,7 @@ public:
virtual Type blocker_type() const override { return Type::Futex; }
virtual StringView state_string() const override { return "Futex"sv; }
- virtual void not_blocking(bool) override { }
+ virtual void will_unblock_immediately_without_blocking(UnblockImmediatelyReason) override { }
virtual bool should_block() override
{
@@ -620,7 +627,7 @@ public:
const FileDescription& blocked_description() const;
virtual bool unblock(bool, void*) override;
- virtual void not_blocking(bool) override;
+ virtual void will_unblock_immediately_without_blocking(UnblockImmediatelyReason) override;
protected:
explicit FileDescriptionBlocker(FileDescription&, BlockFlags, BlockFlags&);
@@ -670,7 +677,7 @@ public:
virtual StringView state_string() const override { return "Sleeping"sv; }
virtual Type blocker_type() const override { return Type::Sleep; }
virtual const BlockTimeout& override_timeout(const BlockTimeout&) override;
- virtual void not_blocking(bool) override;
+ virtual void will_unblock_immediately_without_blocking(UnblockImmediatelyReason) override;
virtual void was_unblocked(bool) override;
virtual Thread::BlockResult block_result() override;
@@ -694,7 +701,7 @@ public:
virtual ~SelectBlocker();
virtual bool unblock(bool, void*) override;
- virtual void not_blocking(bool) override;
+ virtual void will_unblock_immediately_without_blocking(UnblockImmediatelyReason) override;
virtual void was_unblocked(bool) override;
virtual StringView state_string() const override { return "Selecting"sv; }
@@ -718,7 +725,7 @@ public:
virtual StringView state_string() const override { return "Waiting"sv; }
virtual Type blocker_type() const override { return Type::Wait; }
virtual bool should_block() override { return m_should_block; }
- virtual void not_blocking(bool) override;
+ virtual void will_unblock_immediately_without_blocking(UnblockImmediatelyReason) override;
virtual void was_unblocked(bool) override;
bool unblock(Process& process, UnblockFlags flags, u8 signal, bool from_add_blocker);
@@ -881,7 +888,7 @@ public:
m_blocker = &blocker;
if (!blocker.should_block()) {
// Don't block if the wake condition is already met
- blocker.not_blocking(false);
+ blocker.will_unblock_immediately_without_blocking(Blocker::UnblockImmediatelyReason::UnblockConditionAlreadyMet);
m_blocker = nullptr;
m_in_block = false;
return BlockResult::NotBlocked;
@@ -903,7 +910,7 @@ public:
});
if (!timer_was_added) {
// Timeout is already in the past
- blocker.not_blocking(true);
+ blocker.will_unblock_immediately_without_blocking(Blocker::UnblockImmediatelyReason::TimeoutInThePast);
m_blocker = nullptr;
m_in_block = false;
return BlockResult::InterruptedByTimeout;