Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
Fix build on macOS.
Browse files Browse the repository at this point in the history
The prototypes for `cgsleep_ms_r` and `cgsleep_us_r` didn't match the
implementation, and have been updated accordingly.
  • Loading branch information
brndnmtthws committed Dec 14, 2018
1 parent b8491c6 commit fb525da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
23 changes: 17 additions & 6 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1495,22 +1495,25 @@ static void nanosleep_abstime(struct timespec *ts_end)
* from the beginning of the actual sleep, allowing scheduling delays to be
* counted in the sleep. */
#ifdef USE_BITMAIN_SOC
void cgsleep_ms_r(cgtimer_t *ts_start, int ms)
int cgsleep_ms_r(cgtimer_t *ts_start, int ms)
{
struct timespec ts_end;

ms_to_timespec(&ts_end, ms);
timeraddspec(&ts_end, ts_start);
nanosleep_abstime(&ts_end);

}

void cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
int64_t cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
{
struct timespec ts_end;

us_to_timespec(&ts_end, us);
timeraddspec(&ts_end, ts_start);
nanosleep_abstime(&ts_end);

return 0;
}
#else /* USE_BITMAIN_SOC */
int cgsleep_ms_r(cgtimer_t *ts_start, int ms)
Expand Down Expand Up @@ -1622,15 +1625,17 @@ static void liSleep(LARGE_INTEGER *li, int timeout)
CloseHandle(hTimer);
}

void cgsleep_ms_r(cgtimer_t *ts_start, int ms)
int cgsleep_ms_r(cgtimer_t *ts_start, int ms)
{
LARGE_INTEGER li;

li.QuadPart = ts_start->QuadPart + (int64_t)ms * 10000LL;
liSleep(&li, ms);

return 0;
}

void cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
int64_t cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
{
LARGE_INTEGER li;
int ms;
Expand All @@ -1640,6 +1645,8 @@ void cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
if (!ms)
ms = 1;
liSleep(&li, ms);

return 0;
}
#else /* WIN32 */
static void cgsleep_spec(struct timespec *ts_diff, const struct timespec *ts_start)
Expand All @@ -1654,20 +1661,24 @@ static void cgsleep_spec(struct timespec *ts_diff, const struct timespec *ts_sta
nanosleep(ts_diff, NULL);
}

void cgsleep_ms_r(cgtimer_t *ts_start, int ms)
int cgsleep_ms_r(cgtimer_t *ts_start, int ms)
{
struct timespec ts_diff;

ms_to_timespec(&ts_diff, ms);
cgsleep_spec(&ts_diff, ts_start);

return 0;
}

void cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
int64_t cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
{
struct timespec ts_diff;

us_to_timespec(&ts_diff, us);
cgsleep_spec(&ts_diff, ts_start);

return 0;
}
#endif /* WIN32 */
#endif /* CLOCK_MONOTONIC */
Expand Down
4 changes: 2 additions & 2 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ void cgsleep_us(int64_t us);
void cgtimer_time(cgtimer_t *ts_start);
#define cgsleep_prepare_r(ts_start) cgtimer_time(ts_start)
#ifdef USE_BITMAIN_SOC
void cgsleep_ms_r(cgtimer_t *ts_start, int ms);
void cgsleep_us_r(cgtimer_t *ts_start, int64_t us);
int cgsleep_ms_r(cgtimer_t *ts_start, int ms);
int64_t cgsleep_us_r(cgtimer_t *ts_start, int64_t us);
#else
int cgsleep_ms_r(cgtimer_t *ts_start, int ms);
int64_t cgsleep_us_r(cgtimer_t *ts_start, int64_t us);
Expand Down

0 comments on commit fb525da

Please sign in to comment.