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