From c6ec14a39aa1a6fe98fe4bec1ee3d545be9d5410 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Wed, 18 Jan 2017 10:44:58 +0000 Subject: win32: implement nanosleep and enable float sleep by default Don't expect sleeping for fractions of a second to be very accurate. --- configs/mingw32_defconfig | 2 +- configs/mingw64_defconfig | 2 +- include/mingw.h | 2 ++ win32/mingw.c | 18 ++++++++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/configs/mingw32_defconfig b/configs/mingw32_defconfig index a9fa2ee4b..2d0e24891 100644 --- a/configs/mingw32_defconfig +++ b/configs/mingw32_defconfig @@ -279,7 +279,7 @@ CONFIG_SEQ=y CONFIG_SHUF=y CONFIG_SLEEP=y CONFIG_FEATURE_FANCY_SLEEP=y -# CONFIG_FEATURE_FLOAT_SLEEP is not set +CONFIG_FEATURE_FLOAT_SLEEP=y CONFIG_SORT=y CONFIG_FEATURE_SORT_BIG=y CONFIG_SPLIT=y diff --git a/configs/mingw64_defconfig b/configs/mingw64_defconfig index 085158971..7ee4e58f9 100644 --- a/configs/mingw64_defconfig +++ b/configs/mingw64_defconfig @@ -279,7 +279,7 @@ CONFIG_SEQ=y CONFIG_SHUF=y CONFIG_SLEEP=y CONFIG_FEATURE_FANCY_SLEEP=y -# CONFIG_FEATURE_FLOAT_SLEEP is not set +CONFIG_FEATURE_FLOAT_SLEEP=y CONFIG_SORT=y CONFIG_FEATURE_SORT_BIG=y CONFIG_SPLIT=y diff --git a/include/mingw.h b/include/mingw.h index 04700963c..6d4d2b31c 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -341,6 +341,8 @@ struct timespec { }; #endif +int nanosleep(const struct timespec *req, struct timespec *rem); + /* * sys/wait.h */ diff --git a/win32/mingw.c b/win32/mingw.c index 23ca5d3dd..1170cd9d5 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -452,6 +452,24 @@ unsigned int sleep (unsigned int seconds) return 0; } +int nanosleep(const struct timespec *req, struct timespec *rem) +{ + if (req->tv_nsec < 0 || 1000000000 <= req->tv_nsec) { + errno = EINVAL; + return -1; + } + + Sleep(req->tv_sec*1000 + req->tv_nsec/1000000); + + /* Sleep is not interruptible. So there is no remaining delay. */ + if (rem != NULL) { + rem->tv_sec = 0; + rem->tv_nsec = 0; + } + + return 0; +} + /* * Windows' mktemp returns NULL on error whereas POSIX always returns the * template and signals an error by making it an empty string. -- cgit v1.2.3-55-g6feb