From b1d5d3cc341a13c15bcde58bf8bee95096b59425 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sun, 31 Oct 2021 16:52:43 -0600 Subject: [PATCH] Kernel: Avoid redundant bool comparisons in Kernel::Thread Two instances of comparing a bool with == true or == false, and one instance where we can just return an expression instead of checking it to return true on succeess and false on failure. --- Kernel/Thread.cpp | 8 +++----- Kernel/Thread.h | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index d9bbc9fcfd..d24f98b6e6 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -792,9 +792,7 @@ bool Thread::should_ignore_signal(u8 signal) const auto const& action = m_signal_action_data[signal]; if (action.handler_or_sigaction.is_null()) return default_signal_action(signal) == DefaultSignalAction::Ignore; - if ((sighandler_t)action.handler_or_sigaction.get() == SIG_IGN) - return true; - return false; + return ((sighandler_t)action.handler_or_sigaction.get() == SIG_IGN); } bool Thread::has_signal_handler(u8 signal) const @@ -1068,7 +1066,7 @@ void Thread::set_state(State new_state, u8 stop_signal) } else if (previous_state == Stopped) { m_stop_state = State::Invalid; auto& process = this->process(); - if (process.set_stopped(false) == true) { + if (process.set_stopped(false)) { process.for_each_thread([&](auto& thread) { if (&thread == this) return; @@ -1092,7 +1090,7 @@ void Thread::set_state(State new_state, u8 stop_signal) // We don't want to restore to Running state, only Runnable! m_stop_state = previous_state != Running ? previous_state : Runnable; auto& process = this->process(); - if (process.set_stopped(true) == false) { + if (!process.set_stopped(true)) { process.for_each_thread([&](auto& thread) { if (&thread == this) return; diff --git a/Kernel/Thread.h b/Kernel/Thread.h index 6a2294c5a3..d2b858134d 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -883,7 +883,7 @@ public: // NOTE: this may execute on the same or any other processor! SpinlockLocker scheduler_lock(g_scheduler_lock); SpinlockLocker block_lock(m_block_lock); - if (m_blocker && timeout_unblocked.exchange(true) == false) + if (m_blocker && !timeout_unblocked.exchange(true)) unblock(); }); if (!timer_was_added) {