1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-22 20:44:19 +00:00

Provide an nusleep equivalent function to nmsleep.

This commit is contained in:
Con Kolivas 2013-05-28 23:00:14 +10:00
parent 7740ed839a
commit d52ab244ee
2 changed files with 24 additions and 0 deletions

23
util.c
View File

@ -844,6 +844,29 @@ void nmsleep(unsigned int msecs)
#endif
}
/* Same for usecs */
void nusleep(unsigned int usecs)
{
struct timespec twait, tleft;
int ret;
ldiv_t d;
#ifdef WIN32
timeBeginPeriod(1);
#endif
d = ldiv(usecs, 1000000);
tleft.tv_sec = d.quot;
tleft.tv_nsec = d.rem * 1000;
do {
twait.tv_sec = tleft.tv_sec;
twait.tv_nsec = tleft.tv_nsec;
ret = nanosleep(&twait, &tleft);
} while (ret == -1 && errno == EINTR);
#ifdef WIN32
timeEndPeriod(1);
#endif
}
/* This is a cgminer gettimeofday wrapper. Since we always call gettimeofday
* with tz set to NULL, and windows' default resolution is only 15ms, this
* gives us higher resolution times on windows. */

1
util.h
View File

@ -58,6 +58,7 @@ int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (
void thr_info_freeze(struct thr_info *thr);
void thr_info_cancel(struct thr_info *thr);
void nmsleep(unsigned int msecs);
void nusleep(unsigned int usecs);
void cgtime(struct timeval *tv);
void subtime(struct timeval *a, struct timeval *b);
void addtime(struct timeval *a, struct timeval *b);