Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/linux/time.h
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
timeval_to_ns(const struct timeval *tv) | timeval_to_ns(const struct timeval *tv) | ||||
{ | { | ||||
return ((int64_t)tv->tv_sec * NSEC_PER_SEC) + | return ((int64_t)tv->tv_sec * NSEC_PER_SEC) + | ||||
tv->tv_usec * NSEC_PER_USEC; | tv->tv_usec * NSEC_PER_USEC; | ||||
} | } | ||||
#define getrawmonotonic(ts) nanouptime(ts) | #define getrawmonotonic(ts) nanouptime(ts) | ||||
static inline struct timespec | static inline struct timespec | ||||
timespec_sub(struct timespec lhs, struct timespec rhs) | timespec_sub(struct timespec lhs, struct timespec rhs) | ||||
jilles: Apart from violating `-Waggregate-return`, this is a nice and simple API. There is no need to… | |||||
Not Done Inline ActionsYeah. The aggregate return issue only applies to Linux KPI, and my revision doesn't change it. asomers: Yeah. The aggregate return issue only applies to Linux KPI, and my revision doesn't change it. | |||||
{ | { | ||||
struct timespec ts; | struct timespec ts; | ||||
ts.tv_sec = lhs.tv_sec; | timespecsub(&lhs, &rhs, &ts); | ||||
ts.tv_nsec = lhs.tv_nsec; | |||||
timespecsub(&ts, &rhs); | |||||
return ts; | return ts; | ||||
} | } | ||||
static inline void | static inline void | ||||
set_normalized_timespec(struct timespec *ts, time_t sec, int64_t nsec) | set_normalized_timespec(struct timespec *ts, time_t sec, int64_t nsec) | ||||
{ | { | ||||
/* XXX: this doesn't actually normalize anything */ | /* XXX: this doesn't actually normalize anything */ | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |
Apart from violating -Waggregate-return, this is a nice and simple API. There is no need to think about pointer aliasing, and struct timespec is small enough that copying is not an undue burden.
Since we do not want to remove previously working warning flags from users, this may not be a good idea for a userland API.