2
0
mirror of https://github.com/boostorg/thread.git synced 2026-01-26 19:12:11 +00:00

Don't use subtraction to compare xtime.sec because it could overflow.

[SVN r24361]
This commit is contained in:
Michael Glassford
2004-08-09 21:46:34 +00:00
parent 792cd49310
commit 33da34b4bf

View File

@@ -33,26 +33,23 @@ enum xtime_clock_types
struct xtime
{
#if defined(BOOST_NO_INT64_T)
int_fast32_t sec;
int_fast32_t sec; //INT_FAST32_MIN <= sec <= INT_FAST32_MAX
#else
int_fast64_t sec;
int_fast64_t sec; //INT_FAST64_MIN <= sec <= INT_FAST64_MAX
#endif
int_fast32_t nsec;
int_fast32_t nsec; //0 <= xtime.nsec < NANOSECONDS_PER_SECOND
};
int BOOST_THREAD_DECL xtime_get(struct xtime* xtp, int clock_type);
inline int xtime_cmp(const xtime& xt1, const xtime& xt2)
{
int res = (int)(xt1.sec - xt2.sec);
if (res == 0)
res = (int)(xt1.nsec - xt2.nsec);
return res;
if (xt1.sec == xt2.sec)
return (int)(xt1.nsec - xt2.nsec);
else
return (xt1.sec > xt2.sec) ? 1 : -1;
}
} // namespace boost
// Change Log:
// 8 Feb 01 WEKEMPF Initial version.
#endif // BOOST_XTIME_WEK070601_HPP
#endif //BOOST_XTIME_WEK070601_HPP