123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #include <errno.h>
- #include <stdlib.h>
- #include <atomic.h>
- #include "pthreadP.h"
- static void
- cleanup (void *arg)
- {
- *(void **) arg = NULL;
- }
- int
- pthread_timedjoin_np (
- pthread_t threadid,
- void **thread_return,
- const struct timespec *abstime)
- {
- struct pthread *self;
- struct pthread *pd = (struct pthread *) threadid;
- int result;
-
- if (INVALID_NOT_TERMINATED_TD_P (pd))
-
- return ESRCH;
-
- if (IS_DETACHED (pd))
-
- return EINVAL;
- self = THREAD_SELF;
- if (pd == self || self->joinid == pd)
-
- 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 ();
-
- result = lll_timedwait_tid (pd->tid, abstime);
-
- CANCEL_RESET (oldtype);
-
- pthread_cleanup_pop (0);
-
- if (result == 0)
- {
-
- if (thread_return != NULL)
- *thread_return = pd->result;
-
- __free_tcb (pd);
- }
- else
- pd->joinid = NULL;
- return result;
- }
|