diff options
author | Dana Robinson <43805+derobins@users.noreply.github.com> | 2021-03-22 10:55:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-22 10:55:40 (GMT) |
commit | 05bc1905cb37d145c29c036bacb1caac63c7f0c9 (patch) | |
tree | 12158b6aff0277d55d9be7d42ce3fe1ea0b69138 /src/H5system.c | |
parent | 03864c675c9037209a0c7fb9cd16a6d26233ac6c (diff) | |
download | hdf5-05bc1905cb37d145c29c036bacb1caac63c7f0c9.zip hdf5-05bc1905cb37d145c29c036bacb1caac63c7f0c9.tar.gz hdf5-05bc1905cb37d145c29c036bacb1caac63c7f0c9.tar.bz2 |
Adds an implementation for nanosleep on Windows (#483)
* Adds an implementation for nanosleep on Windows
* Committing clang-format changes
* Fix insane formatter issue
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'src/H5system.c')
-rw-r--r-- | src/H5system.c | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/src/H5system.c b/src/H5system.c index 53307a8..1d94816 100644 --- a/src/H5system.c +++ b/src/H5system.c @@ -655,25 +655,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 * @@ -1052,6 +1033,9 @@ done: * * Purpose: Sleep for a given # of nanoseconds * + * Note that commodity hardware is probably going to have a + * resolution of milliseconds, not nanoseconds. + * * Return: SUCCEED/FAIL * * Programmer: Quincey Koziol @@ -1061,15 +1045,26 @@ done: void H5_nanosleep(uint64_t nanosec) { - struct timespec sleeptime; /* Struct to hold time to sleep */ - FUNC_ENTER_NOAPI_NOINIT_NOERR - /* Set up time to sleep */ - sleeptime.tv_sec = 0; - sleeptime.tv_nsec = (long)nanosec; +#ifdef H5_HAVE_WIN32_API + + /* On Windows, Sleep() is in milliseconds. Passing 0 to Sleep() + * causes the thread to relinquish the rest of its time slice. + */ + Sleep(nanosec / (1000 * 1000)); - HDnanosleep(&sleeptime, NULL); +#else + { + struct timespec sleeptime; /* Struct to hold time to sleep */ + + /* Set up time to sleep */ + sleeptime.tv_sec = 0; + sleeptime.tv_nsec = (long)nanosec; + + HDnanosleep(&sleeptime, NULL); + } +#endif FUNC_LEAVE_NOAPI_VOID } /* end H5_nanosleep() */ |