Skip to content

Commit

Permalink
iox-eclipse-iceoryx#337 Adapt the code to iceoryx_hoofs
Browse files Browse the repository at this point in the history
Signed-off-by: Sankara Narayanan Chandrasekar (RBEI/EMT2) <[email protected]>
  • Loading branch information
shankar-in committed May 28, 2021
1 parent ea298b1 commit 8aca662
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_UTILS_PERIODIC_TIMER_HPP
#define IOX_UTILS_PERIODIC_TIMER_HPP
#ifndef IOX_HOOFS_PERIODIC_TIMER_HPP
#define IOX_HOOFS_PERIODIC_TIMER_HPP

#include "iceoryx_utils/error_handling/error_handling.hpp"
#include "iceoryx_utils/internal/units/duration.hpp"
#include "iceoryx_utils/posix_wrapper/semaphore.hpp"
#include "iceoryx_hoofs/error_handling/error_handling.hpp"
#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_hoofs/posix_wrapper/semaphore.hpp"
#include <thread>

namespace iox
Expand Down Expand Up @@ -119,4 +119,4 @@ class PeriodicTimer
} // namespace posix
} // namespace iox

#endif // IOX_UTILS_PERIODIC_TIMER_HPP
#endif // IOX_HOOFS_PERIODIC_TIMER_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_utils/posix_wrapper/periodic_timer.hpp"
#include "iceoryx_hoofs/posix_wrapper/periodic_timer.hpp"
#include "iceoryx_hoofs/posix_wrapper/posix_call.hpp"

using namespace iox::units::duration_literals;

Expand All @@ -34,7 +35,7 @@ PeriodicTimer::PeriodicTimer(const iox::units::Duration interval) noexcept
void PeriodicTimer::start() noexcept
{
stop();
auto waitResult = m_waitSemaphore.timedWait(m_interval, true);
auto waitResult = m_waitSemaphore.timedWait(m_interval);
cxx::Ensures(!waitResult.has_error());
m_timeForNextActivation = now().value() + m_interval;
}
Expand All @@ -58,11 +59,11 @@ cxx::expected<units::Duration, TimerErrorCause> PeriodicTimer::now() noexcept
{
struct timespec ts;
auto result =
cxx::makeSmartC(clock_gettime, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {-1}, {}, CLOCK_REALTIME, &ts);
posixCall(clock_gettime)(CLOCK_REALTIME, &ts).failureReturnValue(-1).evaluate();

if (result.hasErrors())
if (result.has_error())
{
return createErrorCodeFromErrNo(result.getErrNum());
return createErrorCodeFromErrNo(result.get_error().errnum);
}

return cxx::success<units::Duration>(ts);
Expand Down Expand Up @@ -96,7 +97,7 @@ cxx::expected<iox::posix::WaitResult, TimerErrorCause> PeriodicTimer::wait(Timer
m_timeForNextActivation = m_timeForNextActivation + m_interval; // Skip to the next activation
}
auto timeDiff = m_timeForNextActivation - now().value(); // calculate remaining time for activation
auto waitResult = m_waitSemaphore.timedWait(timeDiff, true);
auto waitResult = m_waitSemaphore.timedWait(timeDiff);
if (waitResult.has_error())
{
return cxx::error<TimerErrorCause>(TimerErrorCause::INTERNAL_LOGIC_ERROR);
Expand All @@ -118,7 +119,7 @@ cxx::expected<iox::posix::WaitResult, TimerErrorCause> PeriodicTimer::wait(Timer
else
{
auto actualWaitDuration = m_timeForNextActivation - now().value();
auto waitResult = m_waitSemaphore.timedWait(actualWaitDuration, true);
auto waitResult = m_waitSemaphore.timedWait(actualWaitDuration);
if (waitResult.has_error())
{
return cxx::error<TimerErrorCause>(TimerErrorCause::INTERNAL_LOGIC_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_utils/error_handling/error_handling.hpp"
#include "iceoryx_utils/internal/units/duration.hpp"
#include "iceoryx_utils/posix_wrapper/periodic_timer.hpp"
#include "iceoryx_utils/testing/timing_test.hpp"
#include "iceoryx_hoofs/error_handling/error_handling.hpp"
#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_hoofs/posix_wrapper/periodic_timer.hpp"
#include "iceoryx_hoofs/testing/timing_test.hpp"
#include "test.hpp"

#include <chrono>
Expand Down

0 comments on commit 8aca662

Please sign in to comment.