From dea61b33b3904ae8db5ab3b2075a00822ae02c10 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Tue, 2 Mar 2021 16:38:17 -0800 Subject: Removed Wnanosleep stub and adds Win32 code to H5_nanosleep() --- src/H5system.c | 40 ++++++++++++++++------------------------ src/H5win32defs.h | 2 -- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/H5system.c b/src/H5system.c index fff4c8c..c645105 100644 --- a/src/H5system.c +++ b/src/H5system.c @@ -1040,26 +1040,6 @@ Wflock(int fd, int operation) { return 0; } /* end Wflock() */ - - /*-------------------------------------------------------------------------- - * Function: Wnanosleep - * - * Purpose: Sleep for a given # of nanoseconds (Windows version) - * - * Return: SUCCEED/FAIL - * - * Programmer: Dana Robinson - * Fall 2016 - *-------------------------------------------------------------------------- - */ -int -Wnanosleep(const struct timespec *req, struct timespec *rem) -{ - /* XXX: Currently just a placeholder */ - return 0; - -} /* end Wnanosleep() */ - /*------------------------------------------------------------------------- * Function: Wllround, Wllroundf, Wlround, Wlroundf, Wround, Wroundf @@ -1439,15 +1419,13 @@ done: * * Purpose: Sleep for a given # of nanoseconds * - * Return: SUCCEED/FAIL - * - * Programmer: Quincey Koziol - * October 01, 2016 + * Return: void *-------------------------------------------------------------------------- */ void H5_nanosleep(uint64_t nanosec) { +#ifndef H5_HAVE_WIN32_API const uint64_t nanosec_per_sec = 1000 * 1000 * 1000; struct timespec sleeptime; /* Struct to hold time to sleep */ @@ -1476,6 +1454,20 @@ H5_nanosleep(uint64_t nanosec) } FUNC_LEAVE_NOAPI_VOID +#else + DWORD dwMilliseconds = (DWORD)HDceil(nanosec / 1000.0); + DWORD ignore; + + FUNC_ENTER_NOAPI_NOINIT_NOERR + + /* Windows can't sleep at a ns resolution. Best we can do is ~1 ms. We + * don't care about the return value since the second parameter + * (bAlertable) is FALSE, so it will always be zero. + */ + ignore = SleepEx(dwMilliseconds, FALSE); + + FUNC_LEAVE_NOAPI_VOID +#endif /* H5_HAVE_WIN32_API */ } /* end H5_nanosleep() */ #ifdef H5_HAVE_WIN32_API diff --git a/src/H5win32defs.h b/src/H5win32defs.h index 8a73182..ab3acb9 100644 --- a/src/H5win32defs.h +++ b/src/H5win32defs.h @@ -86,7 +86,6 @@ typedef __int64 h5_stat_size_t; #define HDlseek(F,O,W) _lseeki64(F,O,W) #define HDlstat(S,B) _lstati64(S,B) #define HDmkdir(S,M) _mkdir(S) -#define HDnanosleep(N, O) Wnanosleep(N, O) #define HDoff_t __int64 /* Note that the variadic HDopen macro is using a VC++ extension @@ -169,7 +168,6 @@ extern "C" { H5_DLL char* Wgetlogin(void); H5_DLL int c99_snprintf(char* str, size_t size, const char* format, ...); H5_DLL int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap); - H5_DLL int Wnanosleep(const struct timespec *req, struct timespec *rem); H5_DLL herr_t H5_expand_windows_env_vars(char **env_var); H5_DLL const wchar_t *H5_get_utf16_str(const char *s); H5_DLL int Wopen_utf8(const char *path, int oflag, ...); -- cgit v0.12