Skip to content

Commit 0372e8a

Browse files
committed
fix: timespec helpers
1 parent ab12a61 commit 0372e8a

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

include/robotkernel/helpers.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ inline void timespec_add(timespec& ts, time_t sec, long nsec)
145145
ts.tv_nsec += nsec;
146146
ts.tv_sec += sec;
147147

148-
if (ts.tv_nsec >= 1'000'000'000L) {
149-
ts.tv_nsec -= 1'000'000'000L;
148+
if (ts.tv_nsec >= 1000000000L) {
149+
ts.tv_nsec -= 1000000000L;
150150
ts.tv_sec++;
151151
}
152152
}
@@ -182,11 +182,16 @@ inline bool timespec_cmp(const timespec& lhs, const timespec& rhs, Compare cmp)
182182
/**
183183
* @brief Convenience functions for common comparisons.
184184
*/
185-
inline bool timespec_eq(const timespec& a, const timespec& b) { return timespec_cmp(a, b, std::equal_to<>{}); }
186-
inline bool timespec_lt(const timespec& a, const timespec& b) { return timespec_cmp(a, b, std::less<>{}); }
187-
inline bool timespec_le(const timespec& a, const timespec& b) { return timespec_cmp(a, b, std::less_equal<>{}); }
188-
inline bool timespec_gt(const timespec& a, const timespec& b) { return timespec_cmp(a, b, std::greater<>{}); }
189-
inline bool timespec_ge(const timespec& a, const timespec& b) { return timespec_cmp(a, b, std::greater_equal<>{}); }
185+
inline bool timespec_eq(const timespec& a, const timespec& b)
186+
{ return timespec_cmp(a, b, [](auto lhs, auto rhs){ return lhs == rhs; }); }
187+
inline bool timespec_lt(const timespec& a, const timespec& b)
188+
{ return timespec_cmp(a, b, [](auto lhs, auto rhs){ return lhs < rhs; }); }
189+
inline bool timespec_le(const timespec& a, const timespec& b)
190+
{ return timespec_cmp(a, b, [](auto lhs, auto rhs){ return lhs <= rhs; }); }
191+
inline bool timespec_gt(const timespec& a, const timespec& b)
192+
{ return timespec_cmp(a, b, [](auto lhs, auto rhs){ return lhs > rhs; }); }
193+
inline bool timespec_ge(const timespec& a, const timespec& b)
194+
{ return timespec_cmp(a, b, [](auto lhs, auto rhs){ return lhs >= rhs; }); }
190195

191196
/**
192197
* @brief Resolve a symbol from a shared object and assign it to a variable.

0 commit comments

Comments
 (0)