xref: /dpdk/lib/eal/windows/eal_thread.c (revision 57ecf14806c52d6efcfe7bcfb30ae8293e0f159c)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Intel Corporation
3  */
4 
5 #include <io.h>
6 
7 #include <rte_atomic.h>
8 #include <rte_debug.h>
9 #include <rte_launch.h>
10 #include <rte_lcore.h>
11 #include <rte_per_lcore.h>
12 #include <rte_common.h>
13 #include <rte_memory.h>
14 
15 #include "eal_private.h"
16 #include "eal_thread.h"
17 #include "eal_windows.h"
18 
19 int
eal_thread_wake_worker(unsigned int worker_id)20 eal_thread_wake_worker(unsigned int worker_id)
21 {
22 	int m2w = lcore_config[worker_id].pipe_main2worker[1];
23 	int w2m = lcore_config[worker_id].pipe_worker2main[0];
24 	char c = 0;
25 	int n;
26 
27 	do {
28 		n = _write(m2w, &c, 1);
29 	} while (n == 0 || (n < 0 && errno == EINTR));
30 	if (n < 0)
31 		return -EPIPE;
32 
33 	do {
34 		n = _read(w2m, &c, 1);
35 	} while (n < 0 && errno == EINTR);
36 	if (n <= 0)
37 		return -EPIPE;
38 	return 0;
39 }
40 
41 void
eal_thread_wait_command(void)42 eal_thread_wait_command(void)
43 {
44 	unsigned int lcore_id = rte_lcore_id();
45 	int m2w;
46 	char c;
47 	int n;
48 
49 	m2w = lcore_config[lcore_id].pipe_main2worker[0];
50 	do {
51 		n = _read(m2w, &c, 1);
52 	} while (n < 0 && errno == EINTR);
53 	if (n <= 0)
54 		rte_panic("cannot read on configuration pipe\n");
55 }
56 
57 void
eal_thread_ack_command(void)58 eal_thread_ack_command(void)
59 {
60 	unsigned int lcore_id = rte_lcore_id();
61 	char c = 0;
62 	int w2m;
63 	int n;
64 
65 	w2m = lcore_config[lcore_id].pipe_worker2main[1];
66 	do {
67 		n = _write(w2m, &c, 1);
68 	} while (n == 0 || (n < 0 && errno == EINTR));
69 	if (n < 0)
70 		rte_panic("cannot write on configuration pipe\n");
71 }
72 
73 /* get current thread ID */
74 int
rte_sys_gettid(void)75 rte_sys_gettid(void)
76 {
77 	return GetCurrentThreadId();
78 }
79