Debian Codegraph @

libc-top-half/musl/src/thread/pthread_attr_get.c

raw
1 #include "pthread_impl.h"
2
3 #ifndef __wasilibc_unmodified_upstream
4 #include <common/clock.h>
5 #endif
6
7 int pthread_attr_getdetachstate(const pthread_attr_t *a, int *state)
8 {
9 *state = a->_a_detach;
10 return 0;
11 }
12 int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size)
13 {
14 *size = a->_a_guardsize;
15 return 0;
16 }
17
18 #ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */
19 int pthread_attr_getinheritsched(const pthread_attr_t *restrict a, int *restrict inherit)
20 {
21 *inherit = a->_a_sched;
22 return 0;
23 }
24
25 int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param)
26 {
27 param->sched_priority = a->_a_prio;
28 return 0;
29 }
30
31 int pthread_attr_getschedpolicy(const pthread_attr_t *restrict a, int *restrict policy)
32 {
33 *policy = a->_a_policy;
34 return 0;
35 }
36
37 int pthread_attr_getscope(const pthread_attr_t *restrict a, int *restrict scope)
38 {
39 *scope = PTHREAD_SCOPE_SYSTEM;
40 return 0;
41 }
42 #else
43 int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param)
44 {
45 param->sched_priority = 0;
46 return 0;
47 }
48 #endif
49
50 int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size)
51 {
52 if (!a->_a_stackaddr)
53 return EINVAL;
54 *size = a->_a_stacksize;
55 *addr = (void *)(a->_a_stackaddr - *size);
56 return 0;
57 }
58
59 int pthread_attr_getstacksize(const pthread_attr_t *restrict a, size_t *restrict size)
60 {
61 *size = a->_a_stacksize;
62 return 0;
63 }
64
65 int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict a, int *restrict pshared)
66 {
67 *pshared = !!a->__attr;
68 return 0;
69 }
70
71 #ifdef __wasilibc_unmodified_upstream /* Forward declaration of WASI's `__clockid` type. */
72 int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk)
73 {
74 *clk = a->__attr & 0x7fffffff;
75 return 0;
76 }
77 #else
78 int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk)
79 {
80 if (a->__attr & 0x7fffffff == CLOCKID_REALTIME)
81 *clk = CLOCK_REALTIME;
82 if (a->__attr & 0x7fffffff == CLOCKID_MONOTONIC)
83 *clk = CLOCK_MONOTONIC;
84 return 0;
85 }
86 #endif
87
88 int pthread_condattr_getpshared(const pthread_condattr_t *restrict a, int *restrict pshared)
89 {
90 *pshared = a->__attr>>31;
91 return 0;
92 }
93
94 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict a, int *restrict protocol)
95 {
96 *protocol = a->__attr / 8U % 2;
97 return 0;
98 }
99 int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict a, int *restrict pshared)
100 {
101 *pshared = a->__attr / 128U % 2;
102 return 0;
103 }
104
105 int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict a, int *restrict robust)
106 {
107 *robust = a->__attr / 4U % 2;
108 return 0;
109 }
110
111 int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict a, int *restrict type)
112 {
113 *type = a->__attr & 3;
114 return 0;
115 }
116
117 int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict a, int *restrict pshared)
118 {
119 *pshared = a->__attr[0];
120 return 0;
121 }