1 #include "pthread_impl.h"
2 #include <unsupported_api.h>
3
pthread_attr_getdetachstate(const pthread_attr_t * a,int * state)4 int pthread_attr_getdetachstate(const pthread_attr_t *a, int *state)
5 {
6 *state = a->_a_detach;
7 return 0;
8 }
pthread_attr_getguardsize(const pthread_attr_t * restrict a,size_t * restrict size)9 int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size)
10 {
11 *size = a->_a_guardsize;
12 return 0;
13 }
14
pthread_attr_getinheritsched(const pthread_attr_t * restrict a,int * restrict inherit)15 int pthread_attr_getinheritsched(const pthread_attr_t *restrict a, int *restrict inherit)
16 {
17 *inherit = a->_a_sched;
18 return 0;
19 }
20
pthread_attr_getschedparam(const pthread_attr_t * restrict a,struct sched_param * restrict param)21 int 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
pthread_attr_getschedpolicy(const pthread_attr_t * restrict a,int * restrict policy)27 int pthread_attr_getschedpolicy(const pthread_attr_t *restrict a, int *restrict policy)
28 {
29 *policy = a->_a_policy;
30 return 0;
31 }
32
pthread_attr_getscope(const pthread_attr_t * restrict a,int * restrict scope)33 int pthread_attr_getscope(const pthread_attr_t *restrict a, int *restrict scope)
34 {
35 #ifdef __LITEOS_A__
36 *scope = PTHREAD_SCOPE_PROCESS;
37 #else
38 *scope = PTHREAD_SCOPE_SYSTEM;
39 #endif
40 return 0;
41 }
42
pthread_attr_getstack(const pthread_attr_t * restrict a,void ** restrict addr,size_t * restrict size)43 int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size)
44 {
45 if (!a->_a_stackaddr)
46 return EINVAL;
47 *size = a->_a_stacksize;
48 *addr = (void *)(a->_a_stackaddr - *size);
49 return 0;
50 }
51
pthread_attr_getstacksize(const pthread_attr_t * restrict a,size_t * restrict size)52 int pthread_attr_getstacksize(const pthread_attr_t *restrict a, size_t *restrict size)
53 {
54 *size = a->_a_stacksize;
55 return 0;
56 }
57
pthread_barrierattr_getpshared(const pthread_barrierattr_t * restrict a,int * restrict pshared)58 int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict a, int *restrict pshared)
59 {
60 *pshared = !!a->__attr;
61 return 0;
62 }
63
pthread_condattr_getclock(const pthread_condattr_t * restrict a,clockid_t * restrict clk)64 int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk)
65 {
66 *clk = a->__attr & 0x7fffffff;
67 return 0;
68 }
69
pthread_condattr_getpshared(const pthread_condattr_t * restrict a,int * restrict pshared)70 int pthread_condattr_getpshared(const pthread_condattr_t *restrict a, int *restrict pshared)
71 {
72 *pshared = a->__attr>>31;
73 return 0;
74 }
75
pthread_mutexattr_getprotocol(const pthread_mutexattr_t * restrict a,int * restrict protocol)76 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict a, int *restrict protocol)
77 {
78 UNSUPPORTED_API_VOID(LITEOS_A);
79 *protocol = a->__attr / 8U % 2;
80 return 0;
81 }
pthread_mutexattr_getpshared(const pthread_mutexattr_t * restrict a,int * restrict pshared)82 int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict a, int *restrict pshared)
83 {
84 *pshared = a->__attr / 128U % 2;
85 return 0;
86 }
87
pthread_mutexattr_getrobust(const pthread_mutexattr_t * restrict a,int * restrict robust)88 int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict a, int *restrict robust)
89 {
90 *robust = a->__attr / 4U % 2;
91 return 0;
92 }
93
pthread_mutexattr_gettype(const pthread_mutexattr_t * restrict a,int * restrict type)94 int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict a, int *restrict type)
95 {
96 *type = a->__attr & 3;
97 return 0;
98 }
99
pthread_rwlockattr_getpshared(const pthread_rwlockattr_t * restrict a,int * restrict pshared)100 int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict a, int *restrict pshared)
101 {
102 *pshared = a->__attr[0];
103 return 0;
104 }
105