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 typedef int pid_t; 25 26 #ifndef __useconds_t_defined 27 typedef unsigned long useconds_t; 28 #endif 29 30 /* time related attributes */ 31 #if !defined(CONFIG_NEWLIB_LIBC) && !defined(CONFIG_ARCMWDT_LIBC) 32 #ifndef __clockid_t_defined 33 typedef uint32_t clockid_t; 34 #endif 35 #endif /* !CONFIG_NEWLIB_LIBC && !CONFIG_ARCMWDT_LIBC */ 36 #ifndef __timer_t_defined 37 typedef unsigned long timer_t; 38 #endif 39 40 /* Thread attributes */ 41 struct pthread_attr { 42 void *stack; 43 uint32_t details[2]; 44 }; 45 46 #if defined(CONFIG_MINIMAL_LIBC) || defined(CONFIG_PICOLIBC) || defined(CONFIG_ARMCLANG_STD_LIBC) \ 47 || defined(CONFIG_ARCMWDT_LIBC) 48 typedef struct pthread_attr pthread_attr_t; 49 #endif 50 51 BUILD_ASSERT(sizeof(pthread_attr_t) >= sizeof(struct pthread_attr)); 52 53 typedef uint32_t pthread_t; 54 typedef uint32_t pthread_spinlock_t; 55 56 /* Semaphore */ 57 typedef struct k_sem sem_t; 58 59 /* Mutex */ 60 typedef uint32_t pthread_mutex_t; 61 62 struct pthread_mutexattr { 63 int type; 64 }; 65 #if defined(CONFIG_MINIMAL_LIBC) || defined(CONFIG_PICOLIBC) || defined(CONFIG_ARMCLANG_STD_LIBC) \ 66 || defined(CONFIG_ARCMWDT_LIBC) 67 typedef struct pthread_mutexattr pthread_mutexattr_t; 68 #endif 69 BUILD_ASSERT(sizeof(pthread_mutexattr_t) >= sizeof(struct pthread_mutexattr)); 70 71 /* Condition variables */ 72 typedef uint32_t pthread_cond_t; 73 74 struct pthread_condattr { 75 clockid_t clock; 76 }; 77 78 #if defined(CONFIG_MINIMAL_LIBC) || defined(CONFIG_PICOLIBC) || defined(CONFIG_ARMCLANG_STD_LIBC) \ 79 || defined(CONFIG_ARCMWDT_LIBC) 80 typedef struct pthread_condattr pthread_condattr_t; 81 #endif 82 BUILD_ASSERT(sizeof(pthread_condattr_t) >= sizeof(struct pthread_condattr)); 83 84 /* Barrier */ 85 typedef uint32_t pthread_barrier_t; 86 87 typedef struct pthread_barrierattr { 88 int pshared; 89 } pthread_barrierattr_t; 90 91 typedef uint32_t pthread_rwlockattr_t; 92 93 typedef uint32_t pthread_rwlock_t; 94 95 struct pthread_once { 96 bool flag; 97 }; 98 99 #if defined(CONFIG_MINIMAL_LIBC) || defined(CONFIG_PICOLIBC) || defined(CONFIG_ARMCLANG_STD_LIBC) \ 100 || defined(CONFIG_ARCMWDT_LIBC) 101 typedef uint32_t pthread_key_t; 102 typedef struct pthread_once pthread_once_t; 103 #endif 104 105 /* Newlib typedefs pthread_once_t as a struct with two ints */ 106 BUILD_ASSERT(sizeof(pthread_once_t) >= sizeof(struct pthread_once)); 107 108 #ifdef __cplusplus 109 } 110 #endif 111 112 #endif /* ZEPHYR_INCLUDE_POSIX_TYPES_H_ */ 113