Skip to content

Commit

Permalink
iox-#2150 Add 'iox' prefix to POSIX time functions
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Jan 10, 2024
1 parent df33c6c commit 204b3ec
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 61 deletions.
4 changes: 2 additions & 2 deletions iceoryx_hoofs/posix/time/source/deadline_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ iox::units::Duration deadline_timer::remainingTime() const noexcept
iox::units::Duration deadline_timer::getCurrentMonotonicTime() noexcept
{
timespec time_since_epoch{0, 0};
IOX_ENSURES_WITH_MSG(!IOX_POSIX_CALL(clock_gettime)(CLOCK_MONOTONIC, &time_since_epoch)
IOX_ENSURES_WITH_MSG(!IOX_POSIX_CALL(iox_clock_gettime)(CLOCK_MONOTONIC, &time_since_epoch)
.failureReturnValue(-1)
.evaluate()
.has_error(),
"An error which should never happen occured during 'clock_gettime'!");
"An error which should never happen occured during 'iox_clock_gettime'!");
return iox::units::Duration{time_since_epoch};
}
} // namespace iox
2 changes: 1 addition & 1 deletion iceoryx_hoofs/reporting/source/console_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void ConsoleLogger::createLogMessageHeader(const char* file,
{
timespec timestamp{0, 0};
// intentionally avoid using 'IOX_POSIX_CALL' here to keep the logger dependency free
if (clock_gettime(CLOCK_REALTIME, &timestamp) != 0)
if (iox_clock_gettime(CLOCK_REALTIME, &timestamp) != 0)
{
timestamp = {0, 0};
// intentionally do nothing since a timestamp from 01.01.1970 already indicates an issue with the clock
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_hoofs/test/moduletests/test_time_unit_duration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,13 +1080,13 @@ TEST(Duration_test, ConvertTimespecWithMonotonicReference)
constexpr int64_t NANOSECONDS{66};

struct timespec referenceTimeForMonotonicEpoch = {};
ASSERT_FALSE((IOX_POSIX_CALL(clock_gettime)(CLOCK_MONOTONIC, &referenceTimeForMonotonicEpoch)
ASSERT_FALSE((IOX_POSIX_CALL(iox_clock_gettime)(CLOCK_MONOTONIC, &referenceTimeForMonotonicEpoch)
.failureReturnValue(-1)
.evaluate()
.has_error()));

struct timespec referenceTimeForUnixEpoch = {};
ASSERT_FALSE((IOX_POSIX_CALL(clock_gettime)(CLOCK_REALTIME, &referenceTimeForUnixEpoch)
ASSERT_FALSE((IOX_POSIX_CALL(iox_clock_gettime)(CLOCK_REALTIME, &referenceTimeForUnixEpoch)
.failureReturnValue(-1)
.evaluate()
.has_error()));
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_hoofs/time/source/duration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ struct timespec Duration::timespec(const TimeSpecReference reference) const noex
// AXIVION Next Construct AutosarC++19_03-M5.0.3: False positive! CLOCK_REALTIME and CLOCK_MONOTONIC are of type clockid_t
const clockid_t clockId{(reference == TimeSpecReference::Epoch) ? CLOCK_REALTIME : CLOCK_MONOTONIC};
IOX_ENSURES_WITH_MSG(
!IOX_POSIX_CALL(clock_gettime)(clockId, &referenceTime).failureReturnValue(-1).evaluate().has_error(),
"An error which should never happen occured during 'clock_gettime'!");
!IOX_POSIX_CALL(iox_clock_gettime)(clockId, &referenceTime).failureReturnValue(-1).evaluate().has_error(),
"An error which should never happen occured during 'iox_clock_gettime'!");

const auto targetTime = Duration(referenceTime) + *this;

Expand Down
12 changes: 12 additions & 0 deletions iceoryx_platform/freertos/include/iceoryx_platform/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@

#include "FreeRTOS_POSIX.h"
#include "FreeRTOS_POSIX/time.h"
#include <sys/time.h>
#include <time.h>

using iox_clockid_t = clockid_t;

inline int iox_clock_gettime(iox_clockid_t clk_id, struct timespec* tp)
{
return clock_gettime(clk_id, tp);
}
inline int iox_gettimeofday(struct timeval* tp, struct timezone* tzp)
{
return gettimeofday(tp, tzp);
}

#endif // IOX_HOOFS_FREERTOS_PLATFORM_TIME_HPP
12 changes: 12 additions & 0 deletions iceoryx_platform/linux/include/iceoryx_platform/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,17 @@
#define IOX_HOOFS_LINUX_PLATFORM_TIME_HPP

#include <sys/time.h>
#include <time.h>

using iox_clockid_t = clockid_t;

inline int iox_clock_gettime(iox_clockid_t clk_id, struct timespec* tp)
{
return clock_gettime(clk_id, tp);
}
inline int iox_gettimeofday(struct timeval* tp, struct timezone* tzp)
{
return gettimeofday(tp, tzp);
}

#endif // IOX_HOOFS_LINUX_PLATFORM_TIME_HPP
27 changes: 20 additions & 7 deletions iceoryx_platform/mac/include/iceoryx_platform/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
#include <sys/time.h>
#include <thread>

using iox_useconds_t = useconds_t;
using iox_clockid_t = clockid_t;

struct itimerspec
{
timespec it_interval;
timespec it_value;
};

struct appleTimer_t
struct IceoryxPlatformTimer_t
{
std::thread thread;
void (*callback)(union sigval);
Expand All @@ -48,12 +51,22 @@ struct appleTimer_t
} parameter;
};

using timer_t = appleTimer_t*;
using iox_timer_t = IceoryxPlatformTimer_t*;

int iox_timer_create(iox_clockid_t clockid, struct sigevent* sevp, iox_timer_t* timerid);
int iox_timer_delete(iox_timer_t timerid);
int iox_timer_settime(iox_timer_t timerid, int flags, const struct itimerspec* new_value, struct itimerspec* old_value);
int iox_timer_gettime(iox_timer_t timerid, struct itimerspec* curr_value);
int iox_timer_getoverrun(iox_timer_t timerid);


int timer_create(clockid_t clockid, struct sigevent* sevp, timer_t* timerid);
int timer_delete(timer_t timerid);
int timer_settime(timer_t timerid, int flags, const struct itimerspec* new_value, struct itimerspec* old_value);
int timer_gettime(timer_t timerid, struct itimerspec* curr_value);
int timer_getoverrun(timer_t timerid);
inline int iox_clock_gettime(iox_clockid_t clk_id, struct timespec* tp)
{
return clock_gettime(clk_id, tp);
}
inline int iox_gettimeofday(struct timeval* tp, struct timezone* tzp)
{
return gettimeofday(tp, tzp);
}

#endif // IOX_HOOFS_MAC_PLATFORM_TIME_HPP
24 changes: 12 additions & 12 deletions iceoryx_platform/mac/source/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static std::chrono::nanoseconds getNanoSeconds(const timespec& value)
+ static_cast<uint64_t>(value.tv_nsec));
}

static void stopTimerThread(timer_t timerid)
static void stopTimerThread(iox_timer_t timerid)
{
timerid->parameter.mutex.lock();
timerid->parameter.keepRunning = false;
Expand All @@ -37,15 +37,15 @@ static void stopTimerThread(timer_t timerid)
}
}

static bool waitForExecution(timer_t timerid)
static bool waitForExecution(iox_timer_t timerid)
{
using timePoint_t = std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>;
std::unique_lock<std::mutex> ulock(timerid->parameter.mutex);

if (timerid->parameter.isTimerRunning)
{
timespec waitUntil;
clock_gettime(CLOCK_REALTIME, &waitUntil);
iox_clock_gettime(CLOCK_REALTIME, &waitUntil);
waitUntil.tv_sec += timerid->parameter.timeParameters.it_value.tv_sec;
waitUntil.tv_nsec += timerid->parameter.timeParameters.it_value.tv_nsec;
timerid->parameter.wakeup.wait_until(ulock, timePoint_t(getNanoSeconds(waitUntil)), [timerid] {
Expand All @@ -62,19 +62,19 @@ static bool waitForExecution(timer_t timerid)
}

static void
setTimeParameters(timer_t timerid, const itimerspec& timeParameters, const bool runOnce, const bool isTimerRunning)
setTimeParameters(iox_timer_t timerid, const itimerspec& timeParameters, const bool runOnce, const bool isTimerRunning)
{
std::lock_guard<std::mutex> l(timerid->parameter.mutex);
clock_gettime(CLOCK_REALTIME, &timerid->parameter.startTime);
iox_clock_gettime(CLOCK_REALTIME, &timerid->parameter.startTime);
timerid->parameter.timeParameters = timeParameters;
timerid->parameter.runOnce = runOnce;
timerid->parameter.wasCallbackCalled = false;
timerid->parameter.isTimerRunning = isTimerRunning;
}

int timer_create(clockid_t, struct sigevent* sevp, timer_t* timerid)
int iox_timer_create(iox_clockid_t, struct sigevent* sevp, iox_timer_t* timerid)
{
timer_t timer = new appleTimer_t();
iox_timer_t timer = new IceoryxPlatformTimer_t();
timer->callback = sevp->sigev_notify_function;
timer->callbackParameter = sevp->sigev_value;

Expand Down Expand Up @@ -106,14 +106,14 @@ int timer_create(clockid_t, struct sigevent* sevp, timer_t* timerid)
return 0;
}

int timer_delete(timer_t timerid)
int iox_timer_delete(iox_timer_t timerid)
{
stopTimerThread(timerid);
delete timerid;
return 0;
}

int timer_settime(timer_t timerid, int, const struct itimerspec* new_value, struct itimerspec*)
int iox_timer_settime(iox_timer_t timerid, int, const struct itimerspec* new_value, struct itimerspec*)
{
// disarm timer
if (new_value->it_value.tv_sec == 0 && new_value->it_value.tv_nsec == 0)
Expand All @@ -135,11 +135,11 @@ int timer_settime(timer_t timerid, int, const struct itimerspec* new_value, stru
return 0;
}

int timer_gettime(timer_t timerid, struct itimerspec* curr_value)
int iox_timer_gettime(iox_timer_t timerid, struct itimerspec* curr_value)
{
constexpr int64_t NANO_SECONDS{1000000000};
timespec currentTime;
clock_gettime(CLOCK_REALTIME, &currentTime);
iox_clock_gettime(CLOCK_REALTIME, &currentTime);
int64_t currentTimeNs = currentTime.tv_sec * NANO_SECONDS + currentTime.tv_nsec;
int64_t intervalTimeNs{0}, startTimeNs{0};
{
Expand All @@ -155,7 +155,7 @@ int timer_gettime(timer_t timerid, struct itimerspec* curr_value)
return 0;
}

int timer_getoverrun(timer_t)
int iox_timer_getoverrun(iox_timer_t)
{
return 0;
}
12 changes: 12 additions & 0 deletions iceoryx_platform/qnx/include/iceoryx_platform/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,17 @@
#define IOX_HOOFS_QNX_PLATFORM_TIME_HPP

#include <sys/time.h>
#include <time.h>

using iox_clockid_t = clockid_t;

inline int iox_clock_gettime(iox_clockid_t clk_id, struct timespec* tp)
{
return clock_gettime(clk_id, tp);
}
inline int iox_gettimeofday(struct timeval* tp, struct timezone* tzp)
{
return gettimeofday(tp, tzp);
}

#endif // IOX_HOOFS_QNX_PLATFORM_TIME_HPP
12 changes: 12 additions & 0 deletions iceoryx_platform/unix/include/iceoryx_platform/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,17 @@
#define IOX_HOOFS_UNIX_PLATFORM_TIME_HPP

#include <sys/time.h>
#include <time.h>

using iox_clockid_t = clockid_t;

inline int iox_clock_gettime(iox_clockid_t clk_id, struct timespec* tp)
{
return clock_gettime(clk_id, tp);
}
inline int iox_gettimeofday(struct timeval* tp, struct timezone* tzp)
{
return gettimeofday(tp, tzp);
}

#endif // IOX_HOOFS_UNIX_PLATFORM_TIME_HPP
33 changes: 19 additions & 14 deletions iceoryx_platform/win/include/iceoryx_platform/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

#if defined(__GNUC__) || defined(__GNUG__)
#include <sys/time.h>
#elif defined(_MSC_VER)
#include <time.h>
#endif

#include "iceoryx_platform/signal.hpp"
#include "iceoryx_platform/win32_errorHandling.hpp"
#include "iceoryx_platform/windows.hpp"
Expand All @@ -32,19 +34,23 @@
#include <mutex>
#include <thread>

using iox_useconds_t = uint64_t;
using iox_clockid_t = int;

#if defined(_MSC_VER)

#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1

using suseconds_t = uint64_t;
using clockid_t = int;

struct itimerspec
{
timespec it_interval;
timespec it_value;
};

struct appleTimer_t
#endif

struct IceoryxPlatformTimer_t
{
std::thread thread;
void (*callback)(union sigval);
Expand All @@ -63,16 +69,15 @@ struct appleTimer_t
} parameter;
};

using timer_t = appleTimer_t*;
using iox_timer_t = IceoryxPlatformTimer_t*;

int timer_create(clockid_t clockid, struct sigevent* sevp, timer_t* timerid);
int timer_delete(timer_t timerid);
int timer_settime(timer_t timerid, int flags, const struct itimerspec* new_value, struct itimerspec* old_value);
int timer_gettime(timer_t timerid, struct itimerspec* curr_value);
int timer_getoverrun(timer_t timerid);
int iox_timer_create(iox_clockid_t clockid, struct sigevent* sevp, iox_timer_t* timerid);
int iox_timer_delete(iox_timer_t timerid);
int iox_timer_settime(iox_timer_t timerid, int flags, const struct itimerspec* new_value, struct itimerspec* old_value);
int iox_timer_gettime(iox_timer_t timerid, struct itimerspec* curr_value);
int iox_timer_getoverrun(iox_timer_t timerid);

int clock_gettime(clockid_t clk_id, struct timespec* tp);
int gettimeofday(struct timeval* tp, struct timezone* tzp);
#endif
int iox_clock_gettime(iox_clockid_t clk_id, struct timespec* tp);
int iox_gettimeofday(struct timeval* tp, struct timezone* tzp);

#endif // IOX_HOOFS_WIN_PLATFORM_TIME_HPP
Loading

0 comments on commit 204b3ec

Please sign in to comment.