| 200 | } |
| 201 | |
| 202 | void TimerManager::stop() { |
| 203 | bool doStop = false; |
| 204 | { |
| 205 | Synchronized s(monitor_); |
| 206 | if (state_ == TimerManager::UNINITIALIZED) { |
| 207 | state_ = TimerManager::STOPPED; |
| 208 | } else if (state_ != STOPPING && state_ != STOPPED) { |
| 209 | doStop = true; |
| 210 | state_ = STOPPING; |
| 211 | monitor_.notifyAll(); |
| 212 | } |
| 213 | while (state_ != STOPPED) { |
| 214 | monitor_.wait(); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | if (doStop) { |
| 219 | // Clean up any outstanding tasks |
| 220 | taskMap_.clear(); |
| 221 | |
| 222 | // Remove dispatcher's reference to us. |
| 223 | dispatcher_->manager_ = nullptr; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | shared_ptr<const ThreadFactory> TimerManager::threadFactory() const { |
| 228 | Synchronized s(monitor_); |