1 /*
2  * Copyright (c) 2018 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_INCLUDE_POSIX_TYPES_H_
8 #define ZEPHYR_INCLUDE_POSIX_TYPES_H_
9 
10 #if !(defined(CONFIG_ARCH_POSIX) && defined(CONFIG_EXTERNAL_LIBC))
11 #include <sys/types.h>
12 #endif
13 
14 #if !defined(_CLOCK_T_DECLARED) && !defined(__clock_t_defined)
15 typedef unsigned long clock_t;
16 #define _CLOCK_T_DECLARED
17 #define __clock_t_defined
18 #endif
19 
20 #if !defined(_CLOCKID_T_DECLARED) && !defined(__clockid_t_defined)
21 typedef unsigned long clockid_t;
22 #define _CLOCKID_T_DECLARED
23 #define __clockid_t_defined
24 #endif
25 
26 #ifdef CONFIG_NEWLIB_LIBC
27 #include <sys/_pthreadtypes.h>
28 #endif
29 
30 #include <zephyr/kernel.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #if !defined(_DEV_T_DECLARED) && !defined(__dev_t_defined)
37 typedef int dev_t;
38 #define _DEV_T_DECLARED
39 #define __dev_t_defined
40 #endif
41 
42 #if !defined(_INO_T_DECLARED) && !defined(__ino_t_defined)
43 typedef int ino_t;
44 #define _INO_T_DECLARED
45 #define __ino_t_defined
46 #endif
47 
48 #if !defined(_NLINK_T_DECLARED) && !defined(__nlink_t_defined)
49 typedef unsigned short nlink_t;
50 #define _NLINK_T_DECLARED
51 #define __nlink_t_defined
52 #endif
53 
54 #if !defined(_UID_T_DECLARED) && !defined(__uid_t_defined)
55 typedef unsigned short uid_t;
56 #define _UID_T_DECLARED
57 #define __uid_t_defined
58 #endif
59 
60 #if !defined(_GID_T_DECLARED) && !defined(__gid_t_defined)
61 typedef unsigned short gid_t;
62 #define _GID_T_DECLARED
63 #define __gid_t_defined
64 #endif
65 
66 #if !defined(_BLKSIZE_T_DECLARED) && !defined(__blksize_t_defined)
67 typedef unsigned long blksize_t;
68 #define _BLKSIZE_T_DECLARED
69 #define __blksize_t_defined
70 #endif
71 
72 #if !defined(_BLKCNT_T_DECLARED) && !defined(__blkcnt_t_defined)
73 typedef unsigned long blkcnt_t;
74 #define _BLKCNT_T_DECLARED
75 #define __blkcnt_t_defined
76 #endif
77 
78 #if !defined(CONFIG_ARCMWDT_LIBC)
79 typedef int pid_t;
80 #endif
81 
82 #ifndef __useconds_t_defined
83 typedef unsigned long useconds_t;
84 #endif
85 
86 /* time related attributes */
87 #if !defined(__timer_t_defined) && !defined(_TIMER_T_DECLARED)
88 typedef unsigned long timer_t;
89 #endif
90 
91 /* Thread attributes */
92 struct pthread_attr {
93 	void *stack;
94 	uint32_t details[2];
95 };
96 
97 #if !defined(CONFIG_NEWLIB_LIBC)
98 typedef struct pthread_attr pthread_attr_t;
99 BUILD_ASSERT(sizeof(pthread_attr_t) >= sizeof(struct pthread_attr));
100 #endif
101 
102 typedef uint32_t pthread_t;
103 typedef uint32_t pthread_spinlock_t;
104 
105 /* Semaphore */
106 typedef struct k_sem sem_t;
107 
108 /* Mutex */
109 typedef uint32_t pthread_mutex_t;
110 
111 struct pthread_mutexattr {
112 	unsigned char type: 2;
113 	bool initialized: 1;
114 };
115 #if !defined(CONFIG_NEWLIB_LIBC)
116 typedef struct pthread_mutexattr pthread_mutexattr_t;
117 BUILD_ASSERT(sizeof(pthread_mutexattr_t) >= sizeof(struct pthread_mutexattr));
118 #endif
119 
120 /* Condition variables */
121 typedef uint32_t pthread_cond_t;
122 
123 struct pthread_condattr {
124 	clockid_t clock;
125 };
126 
127 #if !defined(CONFIG_NEWLIB_LIBC)
128 typedef struct pthread_condattr pthread_condattr_t;
129 BUILD_ASSERT(sizeof(pthread_condattr_t) >= sizeof(struct pthread_condattr));
130 #endif
131 
132 /* Barrier */
133 typedef uint32_t pthread_barrier_t;
134 
135 typedef struct pthread_barrierattr {
136 	int pshared;
137 } pthread_barrierattr_t;
138 
139 typedef uint32_t pthread_rwlockattr_t;
140 
141 typedef uint32_t pthread_rwlock_t;
142 
143 struct pthread_once {
144 	bool flag;
145 };
146 
147 #if !defined(CONFIG_NEWLIB_LIBC)
148 typedef uint32_t pthread_key_t;
149 typedef struct pthread_once pthread_once_t;
150 /* Newlib typedefs pthread_once_t as a struct with two ints */
151 BUILD_ASSERT(sizeof(pthread_once_t) >= sizeof(struct pthread_once));
152 #endif
153 
154 #ifdef __cplusplus
155 }
156 #endif
157 
158 #endif	/* ZEPHYR_INCLUDE_POSIX_TYPES_H_ */
159