• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #define _GNU_SOURCE
2 #include "pthread_impl.h"
3 #include <sys/mman.h>
4 
dummy1(pthread_t t)5 static void dummy1(pthread_t t)
6 {
7 }
8 weak_alias(dummy1, __tl_sync);
9 
__pthread_timedjoin_np(pthread_t t,void ** res,const struct timespec * at)10 static int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec *at)
11 {
12 	int state, cs, r = 0;
13 	unsigned int tid;
14 	pthread_t self = __pthread_self();
15 	__pthread_testcancel();
16 	__pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
17 	if (cs == PTHREAD_CANCEL_ENABLE) __pthread_setcancelstate(cs, 0);
18 	if (t == self) {
19 		r = EINVAL;
20 		goto out;
21 	}
22 
23 	switch (t->detach_state) {
24 		case DT_JOINABLE: {
25 			r = __syscall(SYS_pthread_join, t->tid);
26 			break;
27 		}
28 		case DT_EXITING:
29 			break;
30 		case DT_DETACHED:
31 		default:
32 			r = EINVAL;
33 			break;
34 	}
35 
36 out:
37 	__pthread_setcancelstate(cs, 0);
38 	if (r == ESRCH || r == EINVAL) return r;
39 	__tl_sync(t);
40 	if (res) *res = t->result;
41 	tid = t->tid;
42 	t->tid = 0;
43 	return __syscall(SYS_pthread_deatch, tid);
44 }
45 
__pthread_join(pthread_t t,void ** res)46 int __pthread_join(pthread_t t, void **res)
47 {
48 	return __pthread_timedjoin_np(t, res, 0);
49 }
50 
__pthread_tryjoin_np(pthread_t t,void ** res)51 static int __pthread_tryjoin_np(pthread_t t, void **res)
52 {
53 	return t->detach_state==DT_JOINABLE ? EBUSY : __pthread_join(t, res);
54 }
55 
56 weak_alias(__pthread_tryjoin_np, pthread_tryjoin_np);
57 weak_alias(__pthread_timedjoin_np, pthread_timedjoin_np);
58 weak_alias(__pthread_join, pthread_join);
59