make linking of thread-start with explicit scheduling conditional
[musl] / src / thread / pthread_attr_setinheritsched.c
1 #include "pthread_impl.h"
2 #include "syscall.h"
3
4 __attribute__((__visibility__("hidden")))
5 void *__start_sched(void *p)
6 {
7         struct start_sched_args *ssa = p;
8         void *start_arg = ssa->start_arg;
9         void *(*start_fn)(void *) = ssa->start_fn;
10         pthread_t self = __pthread_self();
11
12         int ret = -__syscall(SYS_sched_setscheduler, self->tid,
13                 ssa->attr->_a_policy, &ssa->attr->_a_prio);
14         if (!ret) __restore_sigs(&ssa->mask);
15         a_store(&ssa->futex, ret);
16         __wake(&ssa->futex, 1, 1);
17         if (ret) {
18                 self->detach_state = DT_DYNAMIC;
19                 return 0;
20         }
21         return start_fn(start_arg);
22 }
23
24 int pthread_attr_setinheritsched(pthread_attr_t *a, int inherit)
25 {
26         if (inherit > 1U) return EINVAL;
27         a->_a_sched = inherit;
28         return 0;
29 }