Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds an implementation for nanosleep on Windows #483

Merged
merged 5 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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