123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #include <errno.h>
- #include <stdlib.h>
- #include "atomic.h"
- #include "pthreadP.h"
- static void
- cleanup (void *arg)
- {
- *(void **) arg = NULL;
- }
- int
- pthread_join (threadid, thread_return)
- pthread_t threadid;
- void **thread_return;
- {
- struct pthread *self;
- struct pthread *pd = (struct pthread *) threadid;
-
- if (INVALID_NOT_TERMINATED_TD_P (pd))
-
- return ESRCH;
-
- if (IS_DETACHED (pd))
-
- return EINVAL;
- self = THREAD_SELF;
- if (pd == self
- || (self->joinid == pd
- && (pd->cancelhandling
- & (CANCELING_BITMASK | CANCELED_BITMASK | EXITING_BITMASK
- | TERMINATED_BITMASK)) == 0))
-
- return EDEADLK;
-
- if (__builtin_expect (atomic_compare_and_exchange_bool_acq (&pd->joinid,
- self,
- NULL), 0))
-
- return EINVAL;
-
- pthread_cleanup_push (cleanup, &pd->joinid);
-
- int oldtype = CANCEL_ASYNC ();
-
- lll_wait_tid (pd->tid);
-
- CANCEL_RESET (oldtype);
-
- pthread_cleanup_pop (0);
-
- pd->tid = -1;
-
- if (thread_return != NULL)
- *thread_return = pd->result;
-
- __free_tcb (pd);
- return 0;
- }
|