| 10 | } |
| 11 | |
| 12 | void XCommand::SetState(XCommandState new_state) |
| 13 | { |
| 14 | XASSERT(new_state >= kCommandStateCreated && new_state <= kCommandStateCompleted, |
| 15 | "invalid state: %d", new_state); |
| 16 | mtx_.lock(); |
| 17 | XCommandState old_state = state_; |
| 18 | XASSERT(new_state >= old_state, "state should not go back"); |
| 19 | state_ = new_state; |
| 20 | mtx_.unlock(); |
| 21 | |
| 22 | if (new_state == old_state) return; // only notify when state changes |
| 23 | state_cv_.notify_all(); |
| 24 | for (int i = old_state + 1; i <= new_state; i++) { |
| 25 | for (auto listener : state_listeners_) listener(XCommandState(i)); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | void XCommand::WaitUntil(XCommandState state) |
| 30 | { |
no test coverage detected