256f06850e73cf6936af2523cb15f56444612190
[musl] / src / thread / pthread_setattr_default_np.c
1 #define _GNU_SOURCE
2 #include "pthread_impl.h"
3 #include <string.h>
4
5 int pthread_setattr_default_np(const pthread_attr_t *attrp)
6 {
7         /* Reject anything in the attr object other than stack/guard size. */
8         pthread_attr_t tmp = *attrp, zero = { 0 };
9         tmp._a_stacksize = 0;
10         tmp._a_guardsize = 0;
11         if (memcmp(&tmp, &zero, sizeof tmp))
12                 return EINVAL;
13
14         __inhibit_ptc();
15         if (attrp->_a_stacksize >= __default_stacksize)
16                 __default_stacksize = attrp->_a_stacksize;
17         if (attrp->_a_guardsize >= __default_guardsize)
18                 __default_guardsize = attrp->_a_guardsize;
19         __release_ptc();
20
21         return 0;
22 }
23
24 int pthread_getattr_default_np(pthread_attr_t *attrp)
25 {
26         __acquire_ptc();
27         *attrp = (pthread_attr_t) {
28                 ._a_stacksize = __default_stacksize,
29                 ._a_guardsize = __default_guardsize,
30         };
31         __release_ptc();
32         return 0;
33 }