1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2019 Intel Corporation 3 */ 4 5 #ifndef _PTHREAD_H_ 6 #define _PTHREAD_H_ 7 8 #include <stdint.h> 9 #include <sched.h> 10 11 /** 12 * This file is required to support the common code in eal_common_proc.c, 13 * eal_common_thread.c and common\include\rte_per_lcore.h as Microsoft libc 14 * does not contain pthread.h. This may be removed in future releases. 15 */ 16 #include <rte_common.h> 17 #include <rte_windows.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 #define PTHREAD_BARRIER_SERIAL_THREAD TRUE 24 25 /* defining pthread_t type on Windows since there is no in Microsoft libc*/ 26 typedef uintptr_t pthread_t; 27 28 /* defining pthread_attr_t type on Windows since there is no in Microsoft libc*/ 29 typedef void *pthread_attr_t; 30 31 typedef void *pthread_mutexattr_t; 32 33 typedef CRITICAL_SECTION pthread_mutex_t; 34 35 typedef SYNCHRONIZATION_BARRIER pthread_barrier_t; 36 37 #define pthread_barrier_init(barrier, attr, count) \ 38 !InitializeSynchronizationBarrier(barrier, count, -1) 39 #define pthread_barrier_wait(barrier) EnterSynchronizationBarrier(barrier, \ 40 SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY) 41 #define pthread_barrier_destroy(barrier) \ 42 !DeleteSynchronizationBarrier(barrier) 43 #define pthread_cancel(thread) !TerminateThread((HANDLE) thread, 0) 44 45 static inline int 46 pthread_create(void *threadid, const void *threadattr, void *threadfunc, 47 void *args) 48 { 49 RTE_SET_USED(threadattr); 50 HANDLE hThread; 51 hThread = CreateThread(NULL, 0, 52 (LPTHREAD_START_ROUTINE)(uintptr_t)threadfunc, 53 args, 0, (LPDWORD)threadid); 54 if (hThread) { 55 SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS); 56 SetThreadPriority(hThread, THREAD_PRIORITY_NORMAL); 57 } 58 return ((hThread != NULL) ? 0 : E_FAIL); 59 } 60 61 static inline int 62 pthread_mutex_init(pthread_mutex_t *mutex, 63 __rte_unused pthread_mutexattr_t *attr) 64 { 65 InitializeCriticalSection(mutex); 66 return 0; 67 } 68 69 static inline int 70 pthread_mutex_lock(pthread_mutex_t *mutex) 71 { 72 EnterCriticalSection(mutex); 73 return 0; 74 } 75 76 static inline int 77 pthread_mutex_unlock(pthread_mutex_t *mutex) 78 { 79 LeaveCriticalSection(mutex); 80 return 0; 81 } 82 83 static inline int 84 pthread_mutex_destroy(pthread_mutex_t *mutex) 85 { 86 DeleteCriticalSection(mutex); 87 return 0; 88 } 89 90 #ifdef __cplusplus 91 } 92 #endif 93 94 #endif /* _PTHREAD_H_ */ 95