| 625 | void* __restrict arg); |
| 626 | |
| 627 | int TaskGroup::join(bthread_t tid, void** return_value) { |
| 628 | if (__builtin_expect(!tid, 0)) { // tid of bthread is never 0. |
| 629 | return EINVAL; |
| 630 | } |
| 631 | TaskMeta* m = address_meta(tid); |
| 632 | if (BAIDU_UNLIKELY(NULL == m)) { |
| 633 | // The bthread is not created yet, this join is definitely wrong. |
| 634 | return EINVAL; |
| 635 | } |
| 636 | TaskGroup* g = tls_task_group; |
| 637 | if (g != NULL && g->current_tid() == tid) { |
| 638 | // joining self causes indefinite waiting. |
| 639 | return EINVAL; |
| 640 | } |
| 641 | const uint32_t expected_version = get_version(tid); |
| 642 | while (*m->version_butex == expected_version) { |
| 643 | if (butex_wait(m->version_butex, expected_version, NULL) < 0 && |
| 644 | errno != EWOULDBLOCK && errno != EINTR) { |
| 645 | return errno; |
| 646 | } |
| 647 | } |
| 648 | // Ensure all memory writes made by the joined bthread are visible to |
| 649 | // the joining thread after join returns. This matches the semantic |
| 650 | // guarantee provided by pthread_join() across supported architectures. |
| 651 | butil::atomic_thread_fence(butil::memory_order_acquire); |
| 652 | if (return_value) { |
| 653 | *return_value = NULL; |
| 654 | } |
| 655 | return 0; |
| 656 | } |
| 657 | |
| 658 | bool TaskGroup::exists(bthread_t tid) { |
| 659 | if (tid != 0) { // tid of bthread is never 0. |
nothing calls this directly
no test coverage detected