Move a couple of functions to where they are actually needed

This commit is contained in:
Kovid Goyal 2019-12-19 16:43:51 +05:30
parent 87e2f7f86d
commit 2baa34beb8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 63 additions and 52 deletions

View File

@ -163,6 +163,14 @@ prepareForPoll(EventLoopData *eld, monotonic_t timeout) {
return timeout;
}
static inline struct timespec
calc_time(monotonic_t nsec) {
struct timespec result;
result.tv_sec = nsec / (1000LL * 1000LL * 1000LL);
result.tv_nsec = nsec % (1000LL * 1000LL * 1000LL);
return result;
}
int
pollWithTimeout(struct pollfd *fds, nfds_t nfds, monotonic_t timeout) {
struct timespec tv = calc_time(timeout);

View File

@ -16,7 +16,59 @@
typedef int64_t monotonic_t;
static inline monotonic_t calc_nano_time(struct timespec time) {
static inline monotonic_t
s_double_to_monotonic_t(double time) {
time *= 1000.0;
time *= 1000.0;
time *= 1000.0;
return (monotonic_t)time;
}
static inline monotonic_t
ms_double_to_monotonic_t(double time) {
time *= 1000.0;
time *= 1000.0;
return (monotonic_t)time;
}
static inline monotonic_t
s_to_monotonic_t(monotonic_t time) {
return time * 1000ll * 1000ll * 1000ll;
}
static inline monotonic_t
ms_to_monotonic_t(monotonic_t time) {
return time * 1000ll * 1000ll;
}
static inline int
monotonic_t_to_ms(monotonic_t time) {
return (int)(time / 1000ll / 1000ll);
}
static inline double
monotonic_t_to_s_double(monotonic_t time) {
return (double)time / 1000.0 / 1000.0 / 1000.0;
}
extern monotonic_t monotonic_start_time;
extern monotonic_t monotonic_(void);
static inline monotonic_t
monotonic(void) {
return monotonic_() - monotonic_start_time;
}
static inline void
init_monotonic(void) {
monotonic_start_time = monotonic_();
}
#ifdef MONOTONIC_IMPLEMENTATION
monotonic_t monotonic_start_time = 0;
static inline monotonic_t
calc_nano_time(struct timespec time) {
int64_t result = (monotonic_t)time.tv_sec;
result *= 1000LL;
result *= 1000LL;
@ -25,57 +77,8 @@ static inline monotonic_t calc_nano_time(struct timespec time) {
return result;
}
static inline struct timespec calc_time(monotonic_t nsec) {
struct timespec result;
result.tv_sec = nsec / (1000LL * 1000LL * 1000LL);
result.tv_nsec = nsec % (1000LL * 1000LL * 1000LL);
return result;
}
static inline monotonic_t s_double_to_monotonic_t(double time) {
time *= 1000.0;
time *= 1000.0;
time *= 1000.0;
return (monotonic_t)time;
}
static inline monotonic_t ms_double_to_monotonic_t(double time) {
time *= 1000.0;
time *= 1000.0;
return (monotonic_t)time;
}
static inline monotonic_t s_to_monotonic_t(monotonic_t time) {
return time * 1000ll * 1000ll * 1000ll;
}
static inline monotonic_t ms_to_monotonic_t(monotonic_t time) {
return time * 1000ll * 1000ll;
}
static inline int monotonic_t_to_ms(monotonic_t time) {
return (int)(time / 1000ll / 1000ll);
}
static inline double monotonic_t_to_s_double(monotonic_t time) {
return (double)time / 1000.0 / 1000.0 / 1000.0;
}
extern monotonic_t monotonic_start_time;
extern monotonic_t monotonic_(void);
static inline monotonic_t monotonic(void) {
return monotonic_() - monotonic_start_time;
}
static inline void init_monotonic(void) {
monotonic_start_time = monotonic_();
}
#ifdef MONOTONIC_IMPLEMENTATION
monotonic_t monotonic_start_time = 0;
monotonic_t monotonic_(void) {
monotonic_t
monotonic_(void) {
struct timespec ts = {0};
#ifdef CLOCK_HIGHRES
clock_gettime(CLOCK_HIGHRES, &ts);