1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:17:34 +00:00

Kernel: Clarify Thread::block() a little bit with a better local name

This commit is contained in:
Andreas Kling 2021-03-30 10:59:38 +02:00
parent 279599cbed
commit 664571c88f

View file

@ -789,7 +789,7 @@ public:
} }
} }
template<typename T, class... Args> template<typename BlockerType, class... Args>
[[nodiscard]] BlockResult block(const BlockTimeout& timeout, Args&&... args) [[nodiscard]] BlockResult block(const BlockTimeout& timeout, Args&&... args)
{ {
VERIFY(!Processor::current().in_irq()); VERIFY(!Processor::current().in_irq());
@ -801,7 +801,7 @@ 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
m_in_block = true; m_in_block = true;
T t(forward<Args>(args)...); BlockerType blocker(forward<Args>(args)...);
ScopedSpinLock scheduler_lock(g_scheduler_lock); ScopedSpinLock scheduler_lock(g_scheduler_lock);
// Relaxed semantics are fine for timeout_unblocked because we // Relaxed semantics are fine for timeout_unblocked because we
@ -820,16 +820,16 @@ public:
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
m_blocker = &t; m_blocker = &blocker;
if (!t.should_block()) { if (!blocker.should_block()) {
// Don't block if the wake condition is already met // Don't block if the wake condition is already met
t.not_blocking(false); blocker.not_blocking(false);
m_blocker = nullptr; m_blocker = nullptr;
m_in_block = false; m_in_block = false;
return BlockResult::NotBlocked; return BlockResult::NotBlocked;
} }
auto& block_timeout = t.override_timeout(timeout); auto& block_timeout = blocker.override_timeout(timeout);
if (!block_timeout.is_infinite()) { if (!block_timeout.is_infinite()) {
// Process::kill_all_threads may be called at any time, which will mark all // Process::kill_all_threads may be called at any time, which will mark all
// threads to die. In that case // threads to die. In that case
@ -845,14 +845,14 @@ public:
}); });
if (!timer) { if (!timer) {
// Timeout is already in the past // Timeout is already in the past
t.not_blocking(true); blocker.not_blocking(true);
m_blocker = nullptr; m_blocker = nullptr;
m_in_block = false; m_in_block = false;
return BlockResult::InterruptedByTimeout; return BlockResult::InterruptedByTimeout;
} }
} }
t.begin_blocking({}); blocker.begin_blocking({});
set_state(Thread::Blocked); set_state(Thread::Blocked);
} }
@ -860,7 +860,7 @@ public:
scheduler_lock.unlock(); scheduler_lock.unlock();
block_lock.unlock(); block_lock.unlock();
dbgln_if(THREAD_DEBUG, "Thread {} blocking on {} ({}) -->", *this, &t, t.state_string()); dbgln_if(THREAD_DEBUG, "Thread {} blocking on {} ({}) -->", *this, &blocker, blocker.state_string());
bool did_timeout = false; bool did_timeout = false;
u32 lock_count_to_restore = 0; u32 lock_count_to_restore = 0;
auto previous_locked = unlock_process_if_locked(lock_count_to_restore); auto previous_locked = unlock_process_if_locked(lock_count_to_restore);
@ -888,15 +888,15 @@ public:
did_timeout |= timeout_unblocked.exchange(true); did_timeout |= timeout_unblocked.exchange(true);
if (m_blocker) { if (m_blocker) {
// Remove ourselves... // Remove ourselves...
VERIFY(m_blocker == &t); VERIFY(m_blocker == &blocker);
m_blocker = nullptr; m_blocker = nullptr;
} }
dbgln_if(THREAD_DEBUG, "<-- Thread {} unblocked from {} ({})", *this, &t, t.state_string()); dbgln_if(THREAD_DEBUG, "<-- Thread {} unblocked from {} ({})", *this, &blocker, blocker.state_string());
m_in_block = false; m_in_block = false;
break; break;
} }
if (t.was_interrupted_by_signal()) { if (blocker.was_interrupted_by_signal()) {
ScopedSpinLock scheduler_lock(g_scheduler_lock); ScopedSpinLock scheduler_lock(g_scheduler_lock);
ScopedSpinLock lock(m_lock); ScopedSpinLock lock(m_lock);
dispatch_one_pending_signal(); dispatch_one_pending_signal();
@ -904,7 +904,7 @@ public:
// Notify the blocker that we are no longer blocking. It may need // Notify the blocker that we are no longer blocking. It may need
// to clean up now while we're still holding m_lock // to clean up now while we're still holding m_lock
auto result = t.end_blocking({}, did_timeout); // calls was_unblocked internally auto result = blocker.end_blocking({}, did_timeout); // calls was_unblocked internally
if (timer && !did_timeout) { if (timer && !did_timeout) {
// Cancel the timer while not holding any locks. This allows // Cancel the timer while not holding any locks. This allows