Thread entry point.
| 107 | private: |
| 108 | // Thread entry point. |
| 109 | void ThreadFuncImpl() { |
| 110 | ChangeState(State::Ready); |
| 111 | |
| 112 | // Thread main loop |
| 113 | while (true) { |
| 114 | // In the 'Ready' state, we have nothing to do but to wait until |
| 115 | // we switch to another state. |
| 116 | const auto& condition = [this]() { |
| 117 | return state_.load(std::memory_order_acquire) != State::Ready; |
| 118 | }; |
| 119 | WaitUntil(condition, &state_cond_, &state_mutex_); |
| 120 | |
| 121 | // Act on new state. |
| 122 | switch (state_.load(std::memory_order_acquire)) { |
| 123 | case State::HasWork: |
| 124 | // Got work to do! So do it, and then revert to 'Ready' state. |
| 125 | ChangeState(State::Ready); |
| 126 | break; |
| 127 | case State::ExitAsSoonAsPossible: |
| 128 | return; |
| 129 | default: |
| 130 | abort(); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | // The underlying thread. |
| 136 | std::unique_ptr<std::thread> thread_; |
no test coverage detected