| 303 | } |
| 304 | |
| 305 | int butex_wake(void* arg, bool nosignal) { |
| 306 | Butex* b = container_of(static_cast<butil::atomic<int>*>(arg), Butex, value); |
| 307 | ButexWaiter* front = NULL; |
| 308 | { |
| 309 | BAIDU_SCOPED_LOCK(b->waiter_lock); |
| 310 | if (b->waiters.empty()) { |
| 311 | return 0; |
| 312 | } |
| 313 | front = b->waiters.head()->value(); |
| 314 | front->RemoveFromList(); |
| 315 | front->container.store(NULL, butil::memory_order_relaxed); |
| 316 | } |
| 317 | if (front->tid == 0) { |
| 318 | wakeup_pthread(static_cast<ButexPthreadWaiter*>(front)); |
| 319 | return 1; |
| 320 | } |
| 321 | ButexBthreadWaiter* bbw = static_cast<ButexBthreadWaiter*>(front); |
| 322 | unsleep_if_necessary(bbw, get_global_timer_thread()); |
| 323 | TaskGroup* g = get_task_group(bbw->control, bbw->tag); |
| 324 | if (g == tls_task_group) { |
| 325 | run_in_local_task_group(g, bbw->task_meta, nosignal); |
| 326 | } else { |
| 327 | g->ready_to_run_remote(bbw->task_meta, check_nosignal(nosignal, g->tag())); |
| 328 | } |
| 329 | return 1; |
| 330 | } |
| 331 | |
| 332 | int butex_wake_n(void* arg, size_t n, bool nosignal) { |
| 333 | Butex* b = container_of(static_cast<butil::atomic<int>*>(arg), Butex, value); |