mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
AK: Make timeval_add() and timeval_sub() take references.
This commit is contained in:
parent
bf905225e7
commit
29a9430246
Notes:
sideshowbarker
2024-07-19 13:43:30 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/29a94302465
4 changed files with 19 additions and 18 deletions
27
AK/Time.h
27
AK/Time.h
|
@ -3,25 +3,28 @@
|
|||
namespace AK {
|
||||
|
||||
template<typename TimevalType>
|
||||
inline void timeval_sub(const TimevalType* a, const TimevalType* b, TimevalType* result)
|
||||
inline void timeval_sub(const TimevalType& a, const TimevalType& b, TimevalType& result)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TimevalType>
|
||||
inline void timeval_add(const TimevalType* a, const TimevalType* b, TimevalType* result)
|
||||
inline void timeval_add(const TimevalType& a, const TimevalType& b, TimevalType& result)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::timeval_add;
|
||||
using AK::timeval_sub;
|
||||
|
|
|
@ -1767,8 +1767,7 @@ int Process::sys$select(const Syscall::SC_select_params* params)
|
|||
return -EINVAL;
|
||||
|
||||
if (params->timeout && (params->timeout->tv_sec || params->timeout->tv_usec)) {
|
||||
auto now = kgettimeofday();
|
||||
AK::timeval_add(&now, params->timeout, ¤t->m_select_timeout);
|
||||
timeval_add(kgettimeofday(), *params->timeout, current->m_select_timeout);
|
||||
current->m_select_has_timeout = true;
|
||||
} else {
|
||||
current->m_select_has_timeout = false;
|
||||
|
@ -1842,8 +1841,7 @@ int Process::sys$poll(pollfd* fds, int nfds, int timeout)
|
|||
timeout -= 1000;
|
||||
}
|
||||
tvtimeout.tv_usec = timeout * 1000;
|
||||
auto now = kgettimeofday();
|
||||
AK::timeval_add(&now, &tvtimeout, ¤t->m_select_timeout);
|
||||
timeval_add(kgettimeofday(), tvtimeout, current->m_select_timeout);
|
||||
current->m_select_has_timeout = true;
|
||||
} else {
|
||||
current->m_select_has_timeout = false;
|
||||
|
|
|
@ -15,6 +15,6 @@ int CElapsedTimer::elapsed() const
|
|||
struct timeval now;
|
||||
gettimeofday(&now, nullptr);
|
||||
struct timeval diff;
|
||||
AK::timeval_sub(&now, &m_start_time, &diff);
|
||||
timeval_sub(now, m_start_time, diff);
|
||||
return diff.tv_sec * 1000 + diff.tv_usec / 1000;
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ void CEventLoop::wait_for_event(WaitMode mode)
|
|||
if (!s_timers->is_empty() && queued_events_is_empty) {
|
||||
gettimeofday(&now, nullptr);
|
||||
get_next_timer_expiration(timeout);
|
||||
AK::timeval_sub(&timeout, &now, &timeout);
|
||||
timeval_sub(timeout, now, timeout);
|
||||
} else {
|
||||
should_wait_forever = true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue