| 445 | } |
| 446 | |
| 447 | void TimerThread::stop_and_join() { |
| 448 | _stop.store(true, butil::memory_order_relaxed); |
| 449 | if (_started) { |
| 450 | { |
| 451 | BAIDU_SCOPED_LOCK(_mutex); |
| 452 | // trigger pull_again and wakeup TimerThread |
| 453 | _nearest_run_time = 0; |
| 454 | ++_nsignals; |
| 455 | } |
| 456 | if (pthread_self() != _thread) { |
| 457 | // stop_and_join was not called from a running task. |
| 458 | // wake up the timer thread in case it is sleeping. |
| 459 | futex_wake_private(&_nsignals, 1); |
| 460 | pthread_join(_thread, NULL); |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | static pthread_once_t g_timer_thread_once = PTHREAD_ONCE_INIT; |
| 466 | static TimerThread* g_timer_thread = NULL; |