summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-06-06 18:02:28 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-06 18:02:28 +0200
commit29a94302465c2bb6879e1750606fb4b4c533313b (patch)
tree37d9969bba8f5e8453e9f92e4f9b1757456c2515
parentbf905225e7f674204376650325f41081143aeca5 (diff)
downloadserenity-29a94302465c2bb6879e1750606fb4b4c533313b.zip
AK: Make timeval_add() and timeval_sub() take references.
-rw-r--r--AK/Time.h27
-rw-r--r--Kernel/Process.cpp6
-rw-r--r--LibCore/CElapsedTimer.cpp2
-rw-r--r--LibCore/CEventLoop.cpp2
4 files changed, 19 insertions, 18 deletions
diff --git a/AK/Time.h b/AK/Time.h
index cab8ec54ba..da06a34e6e 100644
--- a/AK/Time.h
+++ b/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;
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 588c6278d8..a4a9e03205 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -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, &current->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, &current->m_select_timeout);
+ timeval_add(kgettimeofday(), tvtimeout, current->m_select_timeout);
current->m_select_has_timeout = true;
} else {
current->m_select_has_timeout = false;
diff --git a/LibCore/CElapsedTimer.cpp b/LibCore/CElapsedTimer.cpp
index e783f59b0d..4e8902d348 100644
--- a/LibCore/CElapsedTimer.cpp
+++ b/LibCore/CElapsedTimer.cpp
@@ -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;
}
diff --git a/LibCore/CEventLoop.cpp b/LibCore/CEventLoop.cpp
index 3fca8b9239..3bfe98893f 100644
--- a/LibCore/CEventLoop.cpp
+++ b/LibCore/CEventLoop.cpp
@@ -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;
}