diff options
author | Benoit Jacob <benoitjacob@google.com> | 2022-04-07 17:53:22 +0300 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-04-07 17:53:55 +0300 |
commit | 915898ed1a46401f1dfb3b23563cad7f89b83fa0 (patch) | |
tree | 865e820d1d996cbb40f1be3f4c0362af5765b2a1 | |
parent | 7ef39c5745a61f43071e699c6a96da41701ae59f (diff) |
Simplification of ThreadPool code - merge asserts into main logic
PiperOrigin-RevId: 440105621
-rw-r--r-- | ruy/thread_pool.cc | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/ruy/thread_pool.cc b/ruy/thread_pool.cc index 5f22a13..298820e 100644 --- a/ruy/thread_pool.cc +++ b/ruy/thread_pool.cc @@ -65,23 +65,9 @@ class Thread { state_mutex_.lock(); State old_state = state_.load(std::memory_order_relaxed); RUY_DCHECK_NE(old_state, new_state); - switch (old_state) { - case State::Startup: - RUY_DCHECK_EQ(new_state, State::Ready); - break; - case State::Ready: - RUY_DCHECK(new_state == State::HasWork || - new_state == State::ExitAsSoonAsPossible); - break; - case State::HasWork: - RUY_DCHECK(new_state == State::Ready || - new_state == State::ExitAsSoonAsPossible); - break; - default: - abort(); - } switch (new_state) { case State::Ready: + RUY_DCHECK(old_state == State::Startup || old_state == State::HasWork); if (task_) { // Doing work is part of reverting to 'ready' state. task_->Run(); @@ -89,11 +75,15 @@ class Thread { } break; case State::HasWork: + RUY_DCHECK(old_state == State::Ready); RUY_DCHECK(!task_); task_ = task; break; - default: + case State::ExitAsSoonAsPossible: + RUY_DCHECK(old_state == State::Ready || old_state == State::HasWork); break; + default: + abort(); } state_.store(new_state, std::memory_order_relaxed); state_cond_.notify_all(); |