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