// SPDX-FileCopyrightText: 2022 GustavoLCR // SPDX-FileCopyrightText: 2022 deroad // SPDX-License-Identifier: LGPL-3.0-only #ifndef RZ_THREAD_INTERNAL_H #define RZ_THREAD_INTERNAL_H #ifdef _GNU_SOURCE #undef _GNU_SOURCE #endif #define _GNU_SOURCE #include #include #include #if __WINDOWS__ #include #define RZ_TH_TID HANDLE #define RZ_TH_LOCK_T CRITICAL_SECTION #define RZ_TH_COND_T CONDITION_VARIABLE #define RZ_TH_SEM_T HANDLE #define RZ_TH_RET_T DWORD WINAPI #elif HAVE_PTHREAD #define __GNU #include #include #if __linux__ #include #endif #if __linux__ && __GLIBC_MINOR < 12 #define HAVE_PTHREAD_NP 0 #else #define HAVE_PTHREAD_NP 1 #endif #if __APPLE__ #include #endif #if __FreeBSD__ || __OpenBSD__ || __DragonFly__ #if __FreeBSD__ #include #endif #include #endif #define RZ_TH_TID pthread_t #define RZ_TH_LOCK_T pthread_mutex_t #define RZ_TH_COND_T pthread_cond_t #define RZ_TH_SEM_T sem_t * #define RZ_TH_RET_T void * #else #error Threading library only supported for pthread and w32 #endif #if __APPLE__ // Here to avoid polluting mach types macro redefinitions... #include #include #endif #if __APPLE__ || __NetBSD__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __sun #include #include #endif #if __sun #include #endif #if __HAIKU__ #include #include #endif struct rz_th_sem_t { RZ_TH_SEM_T sem; }; struct rz_th_lock_t { RZ_TH_LOCK_T lock; }; struct rz_th_cond_t { RZ_TH_COND_T cond; }; struct rz_th_t { RZ_TH_TID tid; ///< Thread identifier. RzThreadFunction function; ///< User defined thread function. void *user; ///< User defined thread data to pass (can be NULL). void *retv; ///< Thread return value. }; RZ_IPI RZ_TH_TID rz_th_self(void); #endif /* RZ_THREAD_INTERNAL_H */