Microsoft libc does not provide sleep(), so code that wants to wait a few seconds has to be wrapped in RTE_EXEC_ENV_WINDOWS conditionals or use rte_delay_us_sleep() instead.
Add a sleep() to the Windows unistd.h shim, implemented with rte_delay_us_sleep(). Nothing on Windows interrupts the wait so it always returns 0, not the number of seconds remaining. Signed-off-by: Stephen Hemminger <[email protected]> --- lib/eal/windows/include/unistd.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/eal/windows/include/unistd.h b/lib/eal/windows/include/unistd.h index f95888f4e1..456eb19718 100644 --- a/lib/eal/windows/include/unistd.h +++ b/lib/eal/windows/include/unistd.h @@ -5,13 +5,14 @@ #ifndef _UNISTD_H_ #define _UNISTD_H_ /** - * This file is added to support common code in eal_common_lcore.c - * as Microsoft libc does not contain unistd.h. This may be removed - * in future releases. + * This file provides the parts of unistd.h that are used by DPDK + * but missing from Microsoft libc. */ #include <io.h> +#include <rte_cycles.h> + /* * Windows appears to be missing STD*_FILENO macros, so define here. * For simplicity, assume that if STDIN_FILENO is missing, all are, @@ -30,4 +31,19 @@ #define R_OK 0x04 /* test for read permission */ #endif +/* + * Microsoft libc has no sleep(). Nothing on Windows interrupts the + * wait, so unlike POSIX this always sleeps the full time and returns 0 + * rather than the number of seconds left. Loop a second at a time to + * avoid overflowing the microsecond argument. + */ +static inline unsigned int +sleep(unsigned int seconds) +{ + while (seconds-- > 0) + rte_delay_us_sleep(US_PER_S); + + return 0; +} + #endif /* _UNISTD_H_ */ -- 2.53.0

