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 #ifndef CONFIG_ARCH_POSIX
11 #include <sys/types.h>
12 #endif
13 
14 #ifdef CONFIG_NEWLIB_LIBC
15 #include <sys/_pthreadtypes.h>
16 #endif
17 
18 #include <zephyr/kernel.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #ifndef __useconds_t_defined
25 typedef unsigned long useconds_t;
26 #endif
27 
28 /* time related attributes */
29 #if !defined(CONFIG_NEWLIB_LIBC) && !defined(CONFIG_ARCMWDT_LIBC)
30 #ifndef __clockid_t_defined
31 typedef uint32_t clockid_t;
32 #endif
33 #endif /* !CONFIG_NEWLIB_LIBC && !CONFIG_ARCMWDT_LIBC */
34 #ifndef __timer_t_defined
35 typedef unsigned long timer_t;
36 #endif
37 
38 #ifdef CONFIG_PTHREAD_IPC
39 /* Thread attributes */
40 struct pthread_attr {
41 	int priority;
42 	void *stack;
43 	uint32_t stacksize;
44 	uint32_t flags;
45 	uint32_t delayedstart;
46 	uint32_t schedpolicy;
47 	int32_t detachstate;
48 	uint32_t initialized;
49 };
50 #if defined(CONFIG_MINIMAL_LIBC) || defined(CONFIG_PICOLIBC) || defined(CONFIG_ARMCLANG_STD_LIBC) \
51 	|| defined(CONFIG_ARCMWDT_LIBC)
52 typedef struct pthread_attr pthread_attr_t;
53 #endif
54 
55 BUILD_ASSERT(sizeof(pthread_attr_t) >= sizeof(struct pthread_attr));
56 
57 typedef uint32_t pthread_t;
58 
59 /* Semaphore */
60 typedef struct k_sem sem_t;
61 
62 /* Mutex */
63 typedef uint32_t pthread_mutex_t;
64 
65 struct pthread_mutexattr {
66 	int type;
67 };
68 #if defined(CONFIG_MINIMAL_LIBC) || defined(CONFIG_PICOLIBC) || defined(CONFIG_ARMCLANG_STD_LIBC) \
69 	|| defined(CONFIG_ARCMWDT_LIBC)
70 typedef struct pthread_mutexattr pthread_mutexattr_t;
71 #endif
72 BUILD_ASSERT(sizeof(pthread_mutexattr_t) >= sizeof(struct pthread_mutexattr));
73 
74 /* Condition variables */
75 typedef uint32_t pthread_cond_t;
76 
77 struct pthread_condattr {
78 };
79 
80 #if defined(CONFIG_MINIMAL_LIBC) || defined(CONFIG_PICOLIBC) || defined(CONFIG_ARMCLANG_STD_LIBC) \
81 	|| defined(CONFIG_ARCMWDT_LIBC)
82 typedef struct pthread_condattr pthread_condattr_t;
83 #endif
84 BUILD_ASSERT(sizeof(pthread_condattr_t) >= sizeof(struct pthread_condattr));
85 
86 /* Barrier */
87 typedef uint32_t pthread_barrier_t;
88 
89 typedef struct pthread_barrierattr {
90 } pthread_barrierattr_t;
91 
92 typedef uint32_t pthread_rwlockattr_t;
93 
94 typedef struct pthread_rwlock_obj {
95 	struct k_sem rd_sem;
96 	struct k_sem wr_sem;
97 	struct k_sem reader_active;/* blocks WR till reader has acquired lock */
98 	int32_t status;
99 	k_tid_t wr_owner;
100 } pthread_rwlock_t;
101 
102 #endif /* CONFIG_PTHREAD_IPC */
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 #endif	/* ZEPHYR_INCLUDE_POSIX_TYPES_H_ */
109