Skip to content

Commit

Permalink
Adds an implementation for nanosleep on Windows (#483)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
derobins and github-actions[bot] authored Mar 22, 2021
1 parent 03864c6 commit 05bc190
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
8 changes: 4 additions & 4 deletions src/H5Tconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -3843,7 +3843,7 @@ H5T__conv_i_i(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, siz
size_t half_size; /*half the type size */
size_t olap; /*num overlapping elements */
uint8_t * s, *sp, *d, *dp; /*source and dest traversal ptrs*/
uint8_t * src_rev = NULL; /*order-reversed source buffer */
uint8_t * src_rev = NULL; /*order-reversed source buffer */
uint8_t dbuf[64] = {0}; /*temp destination buffer */
size_t first;
ssize_t sfirst; /*a signed version of `first' */
Expand Down Expand Up @@ -4286,7 +4286,7 @@ H5T__conv_f_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, siz
size_t olap; /*num overlapping elements */
ssize_t bitno = 0; /*bit number */
uint8_t * s, *sp, *d, *dp; /*source and dest traversal ptrs*/
uint8_t * src_rev = NULL; /*order-reversed source buffer */
uint8_t * src_rev = NULL; /*order-reversed source buffer */
uint8_t dbuf[64] = {0}; /*temp destination buffer */
uint8_t tmp1, tmp2; /*temp variables for swapping bytes*/

Expand Down Expand Up @@ -8401,7 +8401,7 @@ H5T__conv_f_i(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, siz
size_t tsize; /*type size for swapping bytes */
size_t olap; /*num overlapping elements */
uint8_t * s, *sp, *d, *dp; /*source and dest traversal ptrs*/
uint8_t * src_rev = NULL; /*order-reversed source buffer */
uint8_t * src_rev = NULL; /*order-reversed source buffer */
uint8_t dbuf[64] = {0}; /*temp destination buffer */
uint8_t tmp1, tmp2; /*temp variables for swapping bytes*/

Expand Down Expand Up @@ -9027,7 +9027,7 @@ H5T__conv_i_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, siz
size_t tsize; /*type size for swapping bytes */
size_t olap; /*num overlapping elements */
uint8_t * s, *sp, *d, *dp; /*source and dest traversal ptrs*/
uint8_t * src_rev = NULL; /*order-reversed source buffer */
uint8_t * src_rev = NULL; /*order-reversed source buffer */
uint8_t dbuf[64] = {0}; /*temp destination buffer */
uint8_t tmp1, tmp2; /*temp variables for swapping bytes*/

Expand Down
45 changes: 20 additions & 25 deletions src/H5system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -1052,6 +1033,9 @@ H5_combine_path(const char *path1, const char *path2, char **full_name /*out*/)
*
* 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
Expand All @@ -1061,15 +1045,26 @@ H5_combine_path(const char *path1, const char *path2, char **full_name /*out*/)
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() */
Expand Down
1 change: 0 additions & 1 deletion src/H5win32defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ H5_DLL int Wflock(int fd, int operation);
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 wchar_t *H5_get_utf16_str(const char *s);
H5_DLL int Wopen_utf8(const char *path, int oflag, ...);
Expand Down

0 comments on commit 05bc190

Please sign in to comment.