]> git.proxmox.com Git - wasi-libc.git/blame - libc-top-half/musl/src/thread/pthread_attr_get.c
threads: enable access to `pthread_attr_get` functions (#357)
[wasi-libc.git] / libc-top-half / musl / src / thread / pthread_attr_get.c
CommitLineData
320054e8
DG
1#include "pthread_impl.h"
2
3int pthread_attr_getdetachstate(const pthread_attr_t *a, int *state)
4{
5 *state = a->_a_detach;
6 return 0;
7}
8int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size)
9{
10 *size = a->_a_guardsize;
11 return 0;
12}
13
14int pthread_attr_getinheritsched(const pthread_attr_t *restrict a, int *restrict inherit)
15{
16 *inherit = a->_a_sched;
17 return 0;
18}
19
627654f0 20#ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */
320054e8
DG
21int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param)
22{
23 param->sched_priority = a->_a_prio;
24 return 0;
25}
26
27int pthread_attr_getschedpolicy(const pthread_attr_t *restrict a, int *restrict policy)
28{
29 *policy = a->_a_policy;
30 return 0;
31}
627654f0 32#endif
320054e8
DG
33
34int pthread_attr_getscope(const pthread_attr_t *restrict a, int *restrict scope)
35{
36 *scope = PTHREAD_SCOPE_SYSTEM;
37 return 0;
38}
39
40int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size)
41{
42 if (!a->_a_stackaddr)
43 return EINVAL;
44 *size = a->_a_stacksize;
45 *addr = (void *)(a->_a_stackaddr - *size);
46 return 0;
47}
48
49int pthread_attr_getstacksize(const pthread_attr_t *restrict a, size_t *restrict size)
50{
51 *size = a->_a_stacksize;
52 return 0;
53}
54
55int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict a, int *restrict pshared)
56{
57 *pshared = !!a->__attr;
58 return 0;
59}
60
627654f0 61#ifdef __wasilibc_unmodified_upstream /* Forward declaration of WASI's `__clockid` type. */
320054e8
DG
62int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk)
63{
64 *clk = a->__attr & 0x7fffffff;
65 return 0;
66}
627654f0 67#endif
320054e8
DG
68
69int pthread_condattr_getpshared(const pthread_condattr_t *restrict a, int *restrict pshared)
70{
71 *pshared = a->__attr>>31;
72 return 0;
73}
74
75int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict a, int *restrict protocol)
76{
322bd4ff 77 *protocol = a->__attr / 8U % 2;
320054e8
DG
78 return 0;
79}
80int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict a, int *restrict pshared)
81{
82 *pshared = a->__attr / 128U % 2;
83 return 0;
84}
85
86int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict a, int *restrict robust)
87{
88 *robust = a->__attr / 4U % 2;
89 return 0;
90}
91
92int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict a, int *restrict type)
93{
94 *type = a->__attr & 3;
95 return 0;
96}
97
98int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict a, int *restrict pshared)
99{
100 *pshared = a->__attr[0];
101 return 0;
102}