1 /*
2  * Copyright (c) 2018 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_INCLUDE_POSIX_SYS_TYPES_H_
8 #define ZEPHYR_INCLUDE_POSIX_SYS_TYPES_H_
9 
10 #ifndef CONFIG_ARCH_POSIX
11 #include <sys/types.h>
12 #endif
13 
14 #include <kernel.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #ifndef __useconds_t_defined
21 typedef unsigned long useconds_t;
22 #endif
23 
24 /* time related attributes */
25 #if !defined(CONFIG_NEWLIB_LIBC) && !defined(CONFIG_ARCMWDT_LIBC)
26 #ifndef __clockid_t_defined
27 typedef uint32_t clockid_t;
28 #endif
29 #endif /* !CONFIG_NEWLIB_LIBC && !CONFIG_ARCMWDT_LIBC */
30 #ifndef __timer_t_defined
31 typedef unsigned long timer_t;
32 #endif
33 
34 #ifdef CONFIG_PTHREAD_IPC
35 /* Thread attributes */
36 typedef struct pthread_attr_t {
37 	int priority;
38 	void *stack;
39 	size_t stacksize;
40 	uint32_t flags;
41 	uint32_t delayedstart;
42 	uint32_t schedpolicy;
43 	int32_t detachstate;
44 	uint32_t initialized;
45 } pthread_attr_t;
46 
47 typedef void *pthread_t;
48 
49 /* Semaphore */
50 typedef struct k_sem sem_t;
51 
52 /* Mutex */
53 typedef struct pthread_mutex {
54 	pthread_t owner;
55 	uint16_t lock_count;
56 	int type;
57 	_wait_q_t wait_q;
58 } pthread_mutex_t;
59 
60 typedef struct pthread_mutexattr {
61 	int type;
62 } pthread_mutexattr_t;
63 
64 /* Condition variables */
65 typedef struct pthread_cond {
66 	_wait_q_t wait_q;
67 } pthread_cond_t;
68 
69 typedef struct pthread_condattr {
70 } pthread_condattr_t;
71 
72 /* Barrier */
73 typedef struct pthread_barrier {
74 	_wait_q_t wait_q;
75 	int max;
76 	int count;
77 } pthread_barrier_t;
78 
79 typedef struct pthread_barrierattr {
80 } pthread_barrierattr_t;
81 
82 typedef uint32_t pthread_rwlockattr_t;
83 
84 typedef struct pthread_rwlock_obj {
85 	struct k_sem rd_sem;
86 	struct k_sem wr_sem;
87 	struct k_sem reader_active;/* blocks WR till reader has acquired lock */
88 	int32_t status;
89 	k_tid_t wr_owner;
90 } pthread_rwlock_t;
91 
92 #endif /* CONFIG_PTHREAD_IPC */
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 
98 #endif	/* ZEPHYR_INCLUDE_POSIX_SYS_TYPES_H_ */
99