Skip to content

Commit

Permalink
Refactor CurrentTime to CurrentMonotonicTime
Browse files Browse the repository at this point in the history
  • Loading branch information
stefangs0x90 committed Oct 24, 2020
1 parent 8f6ce0f commit 966c85b
Show file tree
Hide file tree
Showing 34 changed files with 103 additions and 103 deletions.
4 changes: 2 additions & 2 deletions common/http/OlaHTTPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ OlaHTTPServer::OlaHTTPServer(const HTTPServer::HTTPServerOptions &options,

StringVariable *data_dir_var = export_map->GetStringVar(K_DATA_DIR_VAR);
data_dir_var->Set(m_server.DataDir());
m_clock.CurrentTime(&m_start_time);
m_clock.CurrentMonotonicTime(&m_start_time);
export_map->GetStringVar(K_UPTIME_VAR);
}

Expand All @@ -73,7 +73,7 @@ int OlaHTTPServer::DisplayDebug(const HTTPRequest*,
HTTPResponse *raw_response) {
auto_ptr<HTTPResponse> response(raw_response);
ola::TimeStamp now;
m_clock.CurrentTime(&now);
m_clock.CurrentMonotonicTime(&now);
ola::TimeInterval diff = now - m_start_time;
ostringstream str;
str << diff.InMilliSeconds();
Expand Down
8 changes: 4 additions & 4 deletions common/io/EPoller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ bool EPoller::Poll(TimeoutManager *timeout_manager,
epoll_event events[MAX_EVENTS];
TimeInterval sleep_interval = poll_interval;
TimeStamp now;
m_clock->CurrentTime(&now);
m_clock->CurrentMonotonicTime(&now);

TimeInterval next_event_in = timeout_manager->ExecuteTimeouts(&now);
if (!next_event_in.IsZero()) {
Expand All @@ -315,7 +315,7 @@ bool EPoller::Poll(TimeoutManager *timeout_manager,
MAX_EVENTS, ms_to_sleep ? ms_to_sleep : 1);

if (ready == 0) {
m_clock->CurrentTime(&m_wake_up_time);
m_clock->CurrentMonotonicTime(&m_wake_up_time);
timeout_manager->ExecuteTimeouts(&m_wake_up_time);
return true;
} else if (ready == -1) {
Expand All @@ -325,7 +325,7 @@ bool EPoller::Poll(TimeoutManager *timeout_manager,
return false;
}

m_clock->CurrentTime(&m_wake_up_time);
m_clock->CurrentMonotonicTime(&m_wake_up_time);

for (int i = 0; i < ready; i++) {
EPollData *descriptor = reinterpret_cast<EPollData*>(
Expand All @@ -346,7 +346,7 @@ bool EPoller::Poll(TimeoutManager *timeout_manager,
}
m_orphaned_descriptors.clear();

m_clock->CurrentTime(&m_wake_up_time);
m_clock->CurrentMonotonicTime(&m_wake_up_time);
timeout_manager->ExecuteTimeouts(&m_wake_up_time);
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions common/io/KQueuePoller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ bool KQueuePoller::Poll(TimeoutManager *timeout_manager,

TimeInterval sleep_interval = poll_interval;
TimeStamp now;
m_clock->CurrentTime(&now);
m_clock->CurrentMonotonicTime(&now);

TimeInterval next_event_in = timeout_manager->ExecuteTimeouts(&now);
if (!next_event_in.IsZero()) {
Expand Down Expand Up @@ -261,7 +261,7 @@ bool KQueuePoller::Poll(TimeoutManager *timeout_manager,
m_next_change_entry = 0;

if (ready == 0) {
m_clock->CurrentTime(&m_wake_up_time);
m_clock->CurrentMonotonicTime(&m_wake_up_time);
timeout_manager->ExecuteTimeouts(&m_wake_up_time);
return true;
} else if (ready == -1) {
Expand All @@ -271,7 +271,7 @@ bool KQueuePoller::Poll(TimeoutManager *timeout_manager,
return false;
}

m_clock->CurrentTime(&m_wake_up_time);
m_clock->CurrentMonotonicTime(&m_wake_up_time);

for (int i = 0; i < ready; i++) {
if (events[i].flags & EV_ERROR) {
Expand All @@ -295,7 +295,7 @@ bool KQueuePoller::Poll(TimeoutManager *timeout_manager,
}
m_orphaned_descriptors.clear();

m_clock->CurrentTime(&m_wake_up_time);
m_clock->CurrentMonotonicTime(&m_wake_up_time);
timeout_manager->ExecuteTimeouts(&m_wake_up_time);
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions common/io/SelectPoller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ bool SelectPoller::Poll(TimeoutManager *timeout_manager,
maxsd = 0;
FD_ZERO(&r_fds);
FD_ZERO(&w_fds);
m_clock->CurrentTime(&now);
m_clock->CurrentMonotonicTime(&now);

TimeInterval next_event_in = timeout_manager->ExecuteTimeouts(&now);
if (!next_event_in.IsZero()) {
Expand Down Expand Up @@ -241,7 +241,7 @@ bool SelectPoller::Poll(TimeoutManager *timeout_manager,
switch (select(maxsd + 1, &r_fds, &w_fds, NULL, &tv)) {
case 0:
// timeout
m_clock->CurrentTime(&m_wake_up_time);
m_clock->CurrentMonotonicTime(&m_wake_up_time);
timeout_manager->ExecuteTimeouts(&m_wake_up_time);

if (closed_descriptors) {
Expand All @@ -258,9 +258,9 @@ bool SelectPoller::Poll(TimeoutManager *timeout_manager,
OLA_WARN << "select() error, " << strerror(errno);
return false;
default:
m_clock->CurrentTime(&m_wake_up_time);
m_clock->CurrentMonotonicTime(&m_wake_up_time);
CheckDescriptors(&r_fds, &w_fds);
m_clock->CurrentTime(&m_wake_up_time);
m_clock->CurrentMonotonicTime(&m_wake_up_time);
timeout_manager->ExecuteTimeouts(&m_wake_up_time);
}

Expand Down
4 changes: 2 additions & 2 deletions common/io/SelectServerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CustomMockClock: public ola::Clock {
: m_timestamp(timestamp) {
}

void CurrentTime(TimeStamp *timestamp) const {
void CurrentMonotonicTime(TimeStamp *timestamp) const {
*timestamp = *m_timestamp;
}

Expand Down Expand Up @@ -632,7 +632,7 @@ void SelectServerTest::testTimeout() {
void SelectServerTest::testOffByOneTimeout() {
TimeStamp now;
ola::Clock actual_clock;
actual_clock.CurrentTime(&now);
actual_clock.CurrentMonotonicTime(&now);

CustomMockClock clock(&now);
SelectServer ss(NULL, &clock);
Expand Down
2 changes: 1 addition & 1 deletion common/io/TimeoutManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ TimeInterval TimeoutManager::ExecuteTimeouts(TimeStamp *now) {
if (m_export_map)
(*m_export_map->GetIntegerVar(K_TIMER_VAR))--;
}
m_clock->CurrentTime(now);
m_clock->CurrentMonotonicTime(now);
}

if (m_events.empty())
Expand Down
2 changes: 1 addition & 1 deletion common/io/TimeoutManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class TimeoutManager {
explicit Event(const TimeInterval &interval, const Clock *clock)
: m_interval(interval) {
TimeStamp now;
clock->CurrentTime(&now);
clock->CurrentMonotonicTime(&now);
m_next = now + m_interval;
}
virtual ~Event() {}
Expand Down
22 changes: 11 additions & 11 deletions common/io/TimeoutManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ void TimeoutManagerTest::testSingleTimeouts() {
TimeStamp last_checked_time;

clock.AdvanceTime(0, 1); // Small offset to work around timer precision
clock.CurrentTime(&last_checked_time);
clock.CurrentMonotonicTime(&last_checked_time);
TimeInterval next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_EQ(0u, GetEventCounter(1));
OLA_ASSERT_LT(next, timeout_interval);

clock.AdvanceTime(0, 500000);
clock.CurrentTime(&last_checked_time);
clock.CurrentMonotonicTime(&last_checked_time);
next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_EQ(0u, GetEventCounter(1));
OLA_ASSERT_LT(next, TimeInterval(0, 500000));

clock.AdvanceTime(0, 500000);
clock.CurrentTime(&last_checked_time);
clock.CurrentMonotonicTime(&last_checked_time);
next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_TRUE(next.IsZero());
OLA_ASSERT_EQ(1u, GetEventCounter(1));
Expand All @@ -127,7 +127,7 @@ void TimeoutManagerTest::testSingleTimeouts() {
timeout_manager.CancelTimeout(id2);

clock.AdvanceTime(1, 0);
clock.CurrentTime(&last_checked_time);
clock.CurrentMonotonicTime(&last_checked_time);
next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_FALSE(timeout_manager.EventsPending());
OLA_ASSERT_EQ(0u, GetEventCounter(2));
Expand All @@ -151,19 +151,19 @@ void TimeoutManagerTest::testRepeatingTimeouts() {
TimeStamp last_checked_time;

clock.AdvanceTime(0, 1); // Small offset to work around timer precision
clock.CurrentTime(&last_checked_time);
clock.CurrentMonotonicTime(&last_checked_time);
TimeInterval next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_EQ(0u, GetEventCounter(1));
OLA_ASSERT_LT(next, timeout_interval);

clock.AdvanceTime(0, 500000);
clock.CurrentTime(&last_checked_time);
clock.CurrentMonotonicTime(&last_checked_time);
next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_EQ(0u, GetEventCounter(1));
OLA_ASSERT_LT(next, TimeInterval(0, 500000));

clock.AdvanceTime(0, 500000);
clock.CurrentTime(&last_checked_time);
clock.CurrentMonotonicTime(&last_checked_time);
next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_LTE(next, timeout_interval);
OLA_ASSERT_EQ(1u, GetEventCounter(1));
Expand All @@ -172,15 +172,15 @@ void TimeoutManagerTest::testRepeatingTimeouts() {

// fire the event again
clock.AdvanceTime(1, 0);
clock.CurrentTime(&last_checked_time);
clock.CurrentMonotonicTime(&last_checked_time);
next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_LTE(next, timeout_interval);
OLA_ASSERT_EQ(2u, GetEventCounter(1));

// cancel the event
timeout_manager.CancelTimeout(id1);
clock.AdvanceTime(1, 0);
clock.CurrentTime(&last_checked_time);
clock.CurrentMonotonicTime(&last_checked_time);
next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_TRUE(next.IsZero());
OLA_ASSERT_EQ(2u, GetEventCounter(1));
Expand All @@ -206,12 +206,12 @@ void TimeoutManagerTest::testAbortedRepeatingTimeouts() {

clock.AdvanceTime(0, 1); // Small offset to work around timer precision
clock.AdvanceTime(1, 0);
clock.CurrentTime(&last_checked_time);
clock.CurrentMonotonicTime(&last_checked_time);
timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_EQ(1u, GetEventCounter(1));

clock.AdvanceTime(1, 0);
clock.CurrentTime(&last_checked_time);
clock.CurrentMonotonicTime(&last_checked_time);
timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_EQ(2u, GetEventCounter(1));

Expand Down
8 changes: 4 additions & 4 deletions common/io/WindowsPoller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ bool WindowsPoller::Poll(TimeoutManager *timeout_manager,
const TimeInterval &poll_interval) {
TimeInterval sleep_interval = poll_interval;
TimeStamp now;
m_clock->CurrentTime(&now);
m_clock->CurrentMonotonicTime(&now);

TimeInterval next_event_in = timeout_manager->ExecuteTimeouts(&now);
if (!next_event_in.IsZero()) {
Expand Down Expand Up @@ -473,7 +473,7 @@ bool WindowsPoller::Poll(TimeoutManager *timeout_manager,
CancelIOs(&data);

if (result == WAIT_TIMEOUT) {
m_clock->CurrentTime(&m_wake_up_time);
m_clock->CurrentMonotonicTime(&m_wake_up_time);
timeout_manager->ExecuteTimeouts(&m_wake_up_time);
// We can't return here since any of the cancelled IO calls still might
// have succeeded.
Expand Down Expand Up @@ -509,7 +509,7 @@ bool WindowsPoller::Poll(TimeoutManager *timeout_manager,
CancelIOs(&data);
}

m_clock->CurrentTime(&m_wake_up_time);
m_clock->CurrentMonotonicTime(&m_wake_up_time);
timeout_manager->ExecuteTimeouts(&m_wake_up_time);

FinalCheckIOs(data);
Expand All @@ -535,7 +535,7 @@ bool WindowsPoller::Poll(TimeoutManager *timeout_manager,
STLDeleteElements(&data);
STLDeleteElements(&event_holders);

m_clock->CurrentTime(&m_wake_up_time);
m_clock->CurrentMonotonicTime(&m_wake_up_time);
timeout_manager->ExecuteTimeouts(&m_wake_up_time);
return return_value;
}
Expand Down
2 changes: 1 addition & 1 deletion common/math/Random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ std::default_random_engine generator_;
void InitRandom() {
Clock clock;
TimeStamp now;
clock.CurrentTime(&now);
clock.CurrentMonotonicTime(&now);

uint64_t seed = (static_cast<uint64_t>(now.MicroSeconds()) << 32) +
static_cast<uint64_t>(getpid());
Expand Down
6 changes: 3 additions & 3 deletions common/rdm/AckTimerResponder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ uint8_t AckTimerResponder::QueuedMessageCount() const {
*/
void AckTimerResponder::QueueAnyNewMessages() {
TimeStamp now;
m_clock.CurrentTime(&now);
m_clock.CurrentMonotonicTime(&now);
PendingResponses::iterator iter = m_upcoming_queued_messages.begin();
while (iter != m_upcoming_queued_messages.end()) {
if ((*iter)->IsValid(now)) {
Expand Down Expand Up @@ -336,7 +336,7 @@ RDMResponse *AckTimerResponder::SetDmxStartAddress(const RDMRequest *request) {
m_start_address = address;

TimeStamp valid_after;
m_clock.CurrentTime(&valid_after);
m_clock.CurrentMonotonicTime(&valid_after);
valid_after += TimeInterval(0, ACK_TIMER_MS * 1000);

QueuedResponse *our_response = new QueuedResponse(
Expand Down Expand Up @@ -379,7 +379,7 @@ RDMResponse *AckTimerResponder::SetIdentify(const RDMRequest *request) {
}

TimeStamp valid_after;
m_clock.CurrentTime(&valid_after);
m_clock.CurrentMonotonicTime(&valid_after);
valid_after += TimeInterval(0, ACK_TIMER_MS * 1000);

QueuedResponse *our_response = new QueuedResponse(
Expand Down
4 changes: 2 additions & 2 deletions common/thread/PeriodicThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void *PeriodicThread::Run() {
Clock clock;
TimeStamp last_run_at;

clock.CurrentTime(&last_run_at);
clock.CurrentMonotonicTime(&last_run_at);
if (!m_callback->Run()) {
return NULL;
}
Expand All @@ -72,7 +72,7 @@ void *PeriodicThread::Run() {
continue;
}
}
clock.CurrentTime(&last_run_at);
clock.CurrentMonotonicTime(&last_run_at);
if (!m_callback->Run()) {
return NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions common/utils/Clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ const TimeStamp TimeStamp::operator-(const TimeInterval &interval) const {
return TimeStamp(m_tv - interval.m_interval);
}

void Clock::CurrentTime(TimeStamp *timestamp) const {
void Clock::CurrentMonotonicTime(TimeStamp *timestamp) const {
struct timeval tv;
#ifdef CLOCK_MONOTONIC
struct timespec ts;
Expand Down Expand Up @@ -279,7 +279,7 @@ void MockClock::AdvanceTime(int32_t sec, int32_t usec) {
m_offset += interval;
}

void MockClock::CurrentTime(TimeStamp *timestamp) const {
void MockClock::CurrentMonotonicTime(TimeStamp *timestamp) const {
struct timeval tv;
gettimeofday(&tv, NULL);
*timestamp = tv;
Expand Down
Loading

0 comments on commit 966c85b

Please sign in to comment.