1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
9 * This file is required to support the common code in eal_common_proc.c,
10 * eal_common_thread.c and common\include\rte_per_lcore.h as Microsoft libc
11 * does not contain pthread.h. This may be removed in future releases.
19 #define PTHREAD_BARRIER_SERIAL_THREAD TRUE
21 /* defining pthread_t type on Windows since there is no in Microsoft libc*/
22 typedef uintptr_t pthread_t;
24 /* defining pthread_attr_t type on Windows since there is no in Microsoft libc*/
25 typedef void *pthread_attr_t;
27 typedef SYNCHRONIZATION_BARRIER pthread_barrier_t;
29 #define pthread_barrier_init(barrier, attr, count) \
30 InitializeSynchronizationBarrier(barrier, count, -1)
31 #define pthread_barrier_wait(barrier) EnterSynchronizationBarrier(barrier, \
32 SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY)
33 #define pthread_barrier_destroy(barrier) \
34 DeleteSynchronizationBarrier(barrier)
35 #define pthread_cancel(thread) TerminateThread((HANDLE) thread, 0)
37 /* pthread function overrides */
38 #define pthread_self() \
39 ((pthread_t)GetCurrentThreadId())
40 #define pthread_setaffinity_np(thread, size, cpuset) \
41 eal_set_thread_affinity_mask(thread, (unsigned long *) cpuset)
42 #define pthread_getaffinity_np(thread, size, cpuset) \
43 eal_get_thread_affinity_mask(thread, (unsigned long *) cpuset)
44 #define pthread_create(threadid, threadattr, threadfunc, args) \
45 eal_create_thread(threadid, threadfunc, args)
48 eal_set_thread_affinity_mask(pthread_t threadid, unsigned long *cpuset)
50 SetThreadAffinityMask((HANDLE) threadid, *cpuset);
55 eal_get_thread_affinity_mask(pthread_t threadid, unsigned long *cpuset)
57 /* Workaround for the lack of a GetThreadAffinityMask()
60 /* obtain previous mask by setting dummy mask */
61 DWORD dwprevaffinitymask =
62 SetThreadAffinityMask((HANDLE) threadid, 0x1);
64 SetThreadAffinityMask((HANDLE) threadid, dwprevaffinitymask);
65 *cpuset = dwprevaffinitymask;
70 eal_create_thread(void *threadid, void *threadfunc, void *args)
73 hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)threadfunc,
74 args, 0, (LPDWORD)threadid);
76 SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
77 SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
79 return ((hThread != NULL) ? 0 : E_FAIL);
83 pthread_join(__rte_unused pthread_t thread,
84 __rte_unused void **value_ptr)
93 #endif /* _PTHREAD_H_ */