mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-10 23:08:07 +00:00
timeGetTime uses huge resources on windows so revert to using timevals for its implementation of cgtimer_t
This commit is contained in:
parent
bedd8eeead
commit
7d448cd754
72
util.c
72
util.c
@ -812,48 +812,17 @@ void cgtime(struct timeval *tv)
|
|||||||
{
|
{
|
||||||
gettimeofday(tv, NULL);
|
gettimeofday(tv, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void timeval_to_cgtimer(cgtimer_t *cgt, const struct timeval *tv)
|
|
||||||
{
|
|
||||||
timeval_to_spec(cgt, tv);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cgtimer_to_timeval(struct timeval *tv, const cgtimer_t *cgt)
|
|
||||||
{
|
|
||||||
timespec_to_val(tv, cgt);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
static void dtime_to_timeval(struct timeval *tv, DWORD dtime)
|
static void __cgtime(struct timeval *tv)
|
||||||
{
|
{
|
||||||
ldiv_t tvdiv = ldiv(dtime, 1000);
|
gettimeofday(tv, NULL);
|
||||||
|
|
||||||
tv->tv_sec = tvdiv.quot;
|
|
||||||
tv->tv_usec = tvdiv.rem * 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cgtime(struct timeval *tv)
|
void cgtime(struct timeval *tv)
|
||||||
{
|
{
|
||||||
DWORD dtime;
|
timeBeginPeriod(1);
|
||||||
|
__cgtime(tv);
|
||||||
//timeBeginPeriod(1);
|
timeEndPeriod(1);
|
||||||
dtime = timeGetTime();
|
|
||||||
//timeEndPeriod(1);
|
|
||||||
dtime_to_timeval(tv, dtime);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void timeval_to_dtime(DWORD *dtime, const struct timeval *tv)
|
|
||||||
{
|
|
||||||
*dtime = tv->tv_sec * 1000 + tv->tv_usec / 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
void timeval_to_cgtimer(cgtimer_t *cgt, const struct timeval *tv)
|
|
||||||
{
|
|
||||||
timeval_to_dtime(cgt, tv);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cgtimer_to_timeval(struct timeval *tv, const cgtimer_t *cgt)
|
|
||||||
{
|
|
||||||
dtime_to_timeval(tv, *cgt);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -967,31 +936,32 @@ void cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
static void dtime_to_timespec(struct timespec *ts, DWORD dtime)
|
|
||||||
{
|
|
||||||
ldiv_t tsdiv = ldiv(dtime, 1000);
|
|
||||||
|
|
||||||
ts->tv_sec = tsdiv.quot;
|
|
||||||
ts->tv_nsec = tsdiv.rem * 1000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cgsleep_prepare_r(cgtimer_t *ts_start)
|
void cgsleep_prepare_r(cgtimer_t *ts_start)
|
||||||
{
|
{
|
||||||
timeBeginPeriod(1);
|
timeBeginPeriod(1);
|
||||||
*ts_start = timeGetTime();
|
__cgtime(ts_start);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ms_to_timeval(struct timeval *val, int ms)
|
||||||
|
{
|
||||||
|
ldiv_t tvdiv = ldiv(ms, 1000);
|
||||||
|
|
||||||
|
val->tv_sec = tvdiv.quot;
|
||||||
|
val->tv_usec = tvdiv.rem * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cgsleep_ms_r(cgtimer_t *ts_start, int ms)
|
void cgsleep_ms_r(cgtimer_t *ts_start, int ms)
|
||||||
{
|
{
|
||||||
DWORD dnow, dend, ddiff;
|
struct timeval now, tv_end, tv_diff;
|
||||||
struct timespec ts_diff;
|
struct timespec ts_diff;
|
||||||
|
|
||||||
dend = *ts_start + ms;
|
ms_to_timeval(&tv_diff, ms);
|
||||||
dnow = timeGetTime();
|
timeradd(ts_start, &tv_diff, &tv_end);
|
||||||
if (unlikely(dnow >= dend))
|
__cgtime(&now);
|
||||||
|
if (unlikely(time_more(&now, &tv_end)))
|
||||||
goto out;
|
goto out;
|
||||||
ddiff = dend - dnow;
|
timersub(&tv_end, &now, &tv_diff);
|
||||||
dtime_to_timespec(&ts_diff, ddiff);
|
timeval_to_spec(&ts_diff, &tv_diff);
|
||||||
nanosleep(&ts_diff, NULL);
|
nanosleep(&ts_diff, NULL);
|
||||||
out:
|
out:
|
||||||
timeEndPeriod(1);
|
timeEndPeriod(1);
|
||||||
|
4
util.h
4
util.h
@ -45,7 +45,7 @@
|
|||||||
#ifndef in_addr_t
|
#ifndef in_addr_t
|
||||||
#define in_addr_t uint32_t
|
#define in_addr_t uint32_t
|
||||||
#endif
|
#endif
|
||||||
typedef DWORD cgtimer_t;
|
typedef struct timeval cgtimer_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if JANSSON_MAJOR_VERSION >= 2
|
#if JANSSON_MAJOR_VERSION >= 2
|
||||||
@ -75,8 +75,6 @@ void thr_info_cancel(struct thr_info *thr);
|
|||||||
void nmsleep(unsigned int msecs);
|
void nmsleep(unsigned int msecs);
|
||||||
void nusleep(unsigned int usecs);
|
void nusleep(unsigned int usecs);
|
||||||
void cgtime(struct timeval *tv);
|
void cgtime(struct timeval *tv);
|
||||||
void timeval_to_cgtimer(cgtimer_t *cgt, const struct timeval *tv);
|
|
||||||
void cgtimer_to_timeval(struct timeval *tv, const cgtimer_t *cgt);
|
|
||||||
void subtime(struct timeval *a, struct timeval *b);
|
void subtime(struct timeval *a, struct timeval *b);
|
||||||
void addtime(struct timeval *a, struct timeval *b);
|
void addtime(struct timeval *a, struct timeval *b);
|
||||||
bool time_more(struct timeval *a, struct timeval *b);
|
bool time_more(struct timeval *a, struct timeval *b);
|
||||||
|
Loading…
Reference in New Issue
Block a user