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.
21 #define PTHREAD_BARRIER_SERIAL_THREAD TRUE
23 /* defining pthread_t type on Windows since there is no in Microsoft libc*/
24 typedef uintptr_t pthread_t;
26 /* defining pthread_attr_t type on Windows since there is no in Microsoft libc*/
27 typedef void *pthread_attr_t;
29 typedef SYNCHRONIZATION_BARRIER pthread_barrier_t;
31 #define pthread_barrier_init(barrier, attr, count) \
32 InitializeSynchronizationBarrier(barrier, count, -1)
33 #define pthread_barrier_wait(barrier) EnterSynchronizationBarrier(barrier, \
34 SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY)
35 #define pthread_barrier_destroy(barrier) \
36 DeleteSynchronizationBarrier(barrier)
37 #define pthread_cancel(thread) TerminateThread((HANDLE) thread, 0)
39 /* pthread function overrides */
40 #define pthread_self() \
41 ((pthread_t)GetCurrentThreadId())
42 #define pthread_setaffinity_np(thread, size, cpuset) \
43 eal_set_thread_affinity_mask(thread, (unsigned long *) cpuset)
44 #define pthread_getaffinity_np(thread, size, cpuset) \
45 eal_get_thread_affinity_mask(thread, (unsigned long *) cpuset)
46 #define pthread_create(threadid, threadattr, threadfunc, args) \
47 eal_create_thread(threadid, threadfunc, args)
50 eal_set_thread_affinity_mask(pthread_t threadid, unsigned long *cpuset)
52 SetThreadAffinityMask((HANDLE) threadid, *cpuset);
57 eal_get_thread_affinity_mask(pthread_t threadid, unsigned long *cpuset)
59 /* Workaround for the lack of a GetThreadAffinityMask()
62 /* obtain previous mask by setting dummy mask */
63 DWORD dwprevaffinitymask =
64 SetThreadAffinityMask((HANDLE) threadid, 0x1);
66 SetThreadAffinityMask((HANDLE) threadid, dwprevaffinitymask);
67 *cpuset = dwprevaffinitymask;
72 eal_create_thread(void *threadid, void *threadfunc, void *args)
75 hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)threadfunc,
76 args, 0, (LPDWORD)threadid);
78 SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
79 SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
81 return ((hThread != NULL) ? 0 : E_FAIL);
85 pthread_join(__rte_unused pthread_t thread,
86 __rte_unused void **value_ptr)
95 #endif /* _PTHREAD_H_ */