123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #include <errno.h>
- #include <stdlib.h>
- #include <atomic.h>
- #include "pthreadP.h"
- int
- pthread_tryjoin_np (
- pthread_t threadid,
- void **thread_return)
- {
- struct pthread *self;
- struct pthread *pd = (struct pthread *) threadid;
-
- if (DEBUGGING_P && __find_in_stack_list (pd) == NULL)
-
- return ESRCH;
-
- if (IS_DETACHED (pd))
-
- return EINVAL;
- self = THREAD_SELF;
- if (pd == self || self->joinid == pd)
-
- return EDEADLK;
-
- if (pd->tid != 0)
- return EBUSY;
-
- if (atomic_compare_and_exchange_bool_acq (&pd->joinid, self, NULL))
-
- return EINVAL;
-
- if (thread_return != NULL)
- *thread_return = pd->result;
-
- __free_tcb (pd);
- return 0;
- }
|