2019-05-18 00:00:01 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
2019-05-28 11:48:06 +00:00
|
|
|
template<typename TimevalType>
|
2019-06-06 16:02:28 +00:00
|
|
|
inline void timeval_sub(const TimevalType& a, const TimevalType& b, TimevalType& result)
|
2019-05-18 00:00:01 +00:00
|
|
|
{
|
2019-06-06 16:02:28 +00:00
|
|
|
result.tv_sec = a.tv_sec - b.tv_sec;
|
|
|
|
result.tv_usec = a.tv_usec - b.tv_usec;
|
|
|
|
if (result.tv_usec < 0) {
|
|
|
|
--result.tv_sec;
|
|
|
|
result.tv_usec += 1000000;
|
2019-05-18 00:00:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-28 11:48:06 +00:00
|
|
|
template<typename TimevalType>
|
2019-06-06 16:02:28 +00:00
|
|
|
inline void timeval_add(const TimevalType& a, const TimevalType& b, TimevalType& result)
|
2019-05-18 00:00:01 +00:00
|
|
|
{
|
2019-06-06 16:02:28 +00:00
|
|
|
result.tv_sec = a.tv_sec + b.tv_sec;
|
|
|
|
result.tv_usec = a.tv_usec + b.tv_usec;
|
|
|
|
if (result.tv_usec > 1000000) {
|
|
|
|
++result.tv_sec;
|
|
|
|
result.tv_usec -= 1000000;
|
2019-05-18 00:00:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-06-06 16:02:28 +00:00
|
|
|
|
|
|
|
using AK::timeval_add;
|
|
|
|
using AK::timeval_sub;
|