| 289 | } |
| 290 | |
| 291 | void ThreadPoolToken::Transition(State new_state) { |
| 292 | #ifndef NDEBUG |
| 293 | CHECK_NE(state_, new_state); |
| 294 | |
| 295 | switch (state_) { |
| 296 | case State::IDLE: |
| 297 | CHECK(new_state == State::RUNNING || |
| 298 | new_state == State::QUIESCED); |
| 299 | if (new_state == State::RUNNING) { |
| 300 | CHECK(!entries_.empty()); |
| 301 | } else { |
| 302 | CHECK(entries_.empty()); |
| 303 | CHECK_EQ(active_threads_, 0); |
| 304 | } |
| 305 | break; |
| 306 | case State::RUNNING: |
| 307 | CHECK(new_state == State::IDLE || |
| 308 | new_state == State::QUIESCING || |
| 309 | new_state == State::QUIESCED); |
| 310 | CHECK(entries_.empty()); |
| 311 | if (new_state == State::QUIESCING) { |
| 312 | CHECK_GT(active_threads_, 0); |
| 313 | } |
| 314 | break; |
| 315 | case State::QUIESCING: |
| 316 | CHECK(new_state == State::QUIESCED); |
| 317 | CHECK_EQ(active_threads_, 0); |
| 318 | break; |
| 319 | case State::QUIESCED: |
| 320 | CHECK(false); // QUIESCED is a terminal state |
| 321 | break; |
| 322 | default: |
| 323 | LOG(FATAL) << "Unknown token state: " << state_; |
| 324 | } |
| 325 | #endif |
| 326 | |
| 327 | // Take actions based on the state we're entering. |
| 328 | switch (new_state) { |
| 329 | case State::IDLE: |
| 330 | case State::QUIESCED: |
| 331 | not_running_cond_.Broadcast(); |
| 332 | break; |
| 333 | default: |
| 334 | break; |
| 335 | } |
| 336 | |
| 337 | state_ = new_state; |
| 338 | } |
| 339 | |
| 340 | const char* ThreadPoolToken::StateToString(State s) { |
| 341 | switch (s) { |
no test coverage detected