| 170 | } |
| 171 | |
| 172 | TimerThread::Task* TimerThread::Bucket::consume_tasks() { |
| 173 | Task* head = NULL; |
| 174 | if (_task_head) { // NOTE: schedule() and consume_tasks() are sequenced |
| 175 | // by TimerThread._nearest_run_time and fenced by TimerThread._mutex. |
| 176 | // We can avoid touching the mutex and related cacheline when the |
| 177 | // bucket is actually empty. |
| 178 | BAIDU_SCOPED_LOCK(_mutex); |
| 179 | if (_task_head) { |
| 180 | head = _task_head; |
| 181 | _task_head = NULL; |
| 182 | _nearest_run_time = std::numeric_limits<int64_t>::max(); |
| 183 | } |
| 184 | } |
| 185 | return head; |
| 186 | } |
| 187 | |
| 188 | TimerThread::Bucket::ScheduleResult |
| 189 | TimerThread::Bucket::schedule(void (*fn)(void*), void* arg, |