mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-11 07:17:58 +00:00
Make the cgsleep functions build on windows.
This commit is contained in:
parent
17447ec7e2
commit
703c7309c2
@ -88,6 +88,7 @@ case $target in
|
|||||||
DLOPEN_FLAGS=""
|
DLOPEN_FLAGS=""
|
||||||
WS2_LIBS="-lws2_32"
|
WS2_LIBS="-lws2_32"
|
||||||
MM_LIBS="-lwinmm"
|
MM_LIBS="-lwinmm"
|
||||||
|
RT_LIBS=""
|
||||||
AC_DEFINE([_WIN32_WINNT], [0x0501], "WinNT version for XP+ support")
|
AC_DEFINE([_WIN32_WINNT], [0x0501], "WinNT version for XP+ support")
|
||||||
;;
|
;;
|
||||||
powerpc-*-darwin*)
|
powerpc-*-darwin*)
|
||||||
|
118
util.c
118
util.c
@ -885,83 +885,111 @@ void timeraddspec(struct timespec *a, const struct timespec *b)
|
|||||||
|
|
||||||
/* These are cgminer specific sleep functions that use an absolute nanosecond
|
/* These are cgminer specific sleep functions that use an absolute nanosecond
|
||||||
* resolution timer to avoid pool usleep accuracy and overruns. */
|
* resolution timer to avoid pool usleep accuracy and overruns. */
|
||||||
void cgsleep_ms(int ms)
|
#ifdef CLOCK_MONOTONIC
|
||||||
|
void cgsleep_prepare_r(struct timespec *ts_start)
|
||||||
|
{
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, ts_start);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void nanosleep_abstime(struct timespec *ts_end)
|
||||||
{
|
{
|
||||||
struct timespec ts_start, ts_end;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
do {
|
||||||
|
ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, ts_end, NULL);
|
||||||
|
} while (ret == EINTR);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
void cgsleep_prepare_r(struct timespec *ts_start)
|
||||||
|
{
|
||||||
|
struct timeval tv_start;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
timeBeginPeriod(1);
|
timeBeginPeriod(1);
|
||||||
#endif
|
#endif
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts_start);
|
gettimeofday(&tv_start, NULL);
|
||||||
ms_to_timespec(&ts_end, ms);
|
timeval_to_spec(ts_start, &tv_start);
|
||||||
timeraddspec(&ts_end, &ts_start);
|
|
||||||
do {
|
|
||||||
ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts_end, NULL);
|
|
||||||
} while (ret == EINTR);
|
|
||||||
#ifdef WIN32
|
|
||||||
timeEndPeriod(1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cgsleep_us(int64_t us)
|
static uint64_t timespec_to_ns(struct timespec *ts)
|
||||||
{
|
{
|
||||||
struct timespec ts_start, ts_end;
|
uint64_t ret;
|
||||||
int ret;
|
|
||||||
|
|
||||||
#ifdef WIN32
|
ret = (uint64_t)ts->tv_sec * 1000000000;
|
||||||
timeBeginPeriod(1);
|
ret += ts->tv_nsec;
|
||||||
#endif
|
return ret;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts_start);
|
}
|
||||||
us_to_timespec(&ts_end, us);
|
|
||||||
timeraddspec(&ts_end, &ts_start);
|
static uint64_t timeval_to_ns(struct timeval *tv)
|
||||||
do {
|
{
|
||||||
ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts_end, NULL);
|
uint64_t ret;
|
||||||
} while (ret == EINTR);
|
|
||||||
|
ret = (uint64_t)tv->tv_sec * 1000000000;
|
||||||
|
ret += tv->tv_usec * 1000;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ns_to_timespec(struct timespec *ts, uint64_t ns)
|
||||||
|
{
|
||||||
|
ts->tv_sec = ns / 1000000000;
|
||||||
|
ts->tv_nsec = ns - ((uint64_t)ts->tv_sec * 1000000000ull);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void nanosleep_abstime(struct timespec *ts_end)
|
||||||
|
{
|
||||||
|
uint64_t now_ns, end_ns, diff_ns;
|
||||||
|
struct timespec ts_diff;
|
||||||
|
struct timeval now;
|
||||||
|
|
||||||
|
end_ns = timespec_to_ns(ts_end);
|
||||||
|
gettimeofday(&now, NULL);
|
||||||
|
now_ns = timeval_to_ns(&now);
|
||||||
|
if (unlikely(now_ns >= end_ns))
|
||||||
|
return;
|
||||||
|
diff_ns = end_ns - now_ns;
|
||||||
|
ns_to_timespec(&ts_diff, diff_ns);
|
||||||
|
nanosleep(&ts_diff, NULL);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
timeEndPeriod(1);
|
timeEndPeriod(1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Reentrant version of cgsleep functions allow start time to be set separately
|
/* Reentrant version of cgsleep functions allow start time to be set separately
|
||||||
* from the beginning of the actual sleep, allowing scheduling delays to be
|
* from the beginning of the actual sleep, allowing scheduling delays to be
|
||||||
* counted in the sleep. */
|
* counted in the sleep. */
|
||||||
void cgsleep_prepare_r(struct timespec *ts_start)
|
|
||||||
{
|
|
||||||
#ifdef WIN32
|
|
||||||
timeBeginPeriod(1);
|
|
||||||
#endif
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, ts_start);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cgsleep_ms_r(struct timespec *ts_start, int ms)
|
void cgsleep_ms_r(struct timespec *ts_start, int ms)
|
||||||
{
|
{
|
||||||
struct timespec ts_end;
|
struct timespec ts_end;
|
||||||
int ret;
|
|
||||||
|
|
||||||
ms_to_timespec(&ts_end, ms);
|
ms_to_timespec(&ts_end, ms);
|
||||||
timeraddspec(&ts_end, ts_start);
|
timeraddspec(&ts_end, ts_start);
|
||||||
do {
|
nanosleep_abstime(&ts_end);
|
||||||
ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts_end, NULL);
|
|
||||||
} while (ret == EINTR);
|
|
||||||
#ifdef WIN32
|
|
||||||
timeEndPeriod(1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cgsleep_us_r(struct timespec *ts_start, int us)
|
void cgsleep_us_r(struct timespec *ts_start, int us)
|
||||||
{
|
{
|
||||||
struct timespec ts_end;
|
struct timespec ts_end;
|
||||||
int ret;
|
|
||||||
|
|
||||||
us_to_timespec(&ts_end, us);
|
us_to_timespec(&ts_end, us);
|
||||||
timeraddspec(&ts_end, ts_start);
|
timeraddspec(&ts_end, ts_start);
|
||||||
do {
|
nanosleep_abstime(&ts_end);
|
||||||
ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts_end, NULL);
|
}
|
||||||
} while (ret == EINTR);
|
|
||||||
#ifdef WIN32
|
void cgsleep_ms(int ms)
|
||||||
timeEndPeriod(1);
|
{
|
||||||
#endif
|
struct timespec ts_start;
|
||||||
|
|
||||||
|
cgsleep_prepare_r(&ts_start);
|
||||||
|
cgsleep_ms_r(&ts_start, ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cgsleep_us(int64_t us)
|
||||||
|
{
|
||||||
|
struct timespec ts_start;
|
||||||
|
|
||||||
|
cgsleep_prepare_r(&ts_start);
|
||||||
|
cgsleep_us_r(&ts_start, us);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provide a ms based sleep that uses nanosleep to avoid poor usleep accuracy
|
/* Provide a ms based sleep that uses nanosleep to avoid poor usleep accuracy
|
||||||
|
Loading…
Reference in New Issue
Block a user