Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iox #32 implement posix timer and introduced timing test #69

Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
14908e1
iox-#32 added first dispatch timer example in posix platform
elfenpiff Feb 29, 2020
aa517f7
iox-#32 added timing_test helper construct for gtest timing tests; te…
elfenpiff Mar 1, 2020
41322b0
iox-#32 using timing tests also in semaphore
elfenpiff Mar 1, 2020
848c394
iox-#32 reviewed the documentation of the timing test
elfenpiff Mar 1, 2020
be6c5ea
iox-#32 in windows context switching seems extremely expensive, there…
elfenpiff Mar 1, 2020
e594e0f
iox-#32 working on timing tests
elfenpiff Mar 17, 2020
ce407a6
Merge branch 'iox-#32-implement-posix-timer-via-dispatch-timer' of gi…
elfenpiff Mar 17, 2020
53db9b9
iox-#32 interface cleanup
elfenpiff Mar 18, 2020
1cc689c
iox-#32 working on unit tests for timer
elfenpiff Mar 18, 2020
22fdad7
Merge branch 'iox-#32-implement-posix-timer-via-dispatch-timer' of gi…
elfenpiff Mar 18, 2020
d7080d2
iox-#32 writing some more tests for the timer
elfenpiff Mar 18, 2020
2d718ec
iox-#32 merged with iox-#32-mac-os-support-part-II
elfenpiff Mar 19, 2020
7ba0132
iox-#32 working in timer
elfenpiff Mar 19, 2020
22899e3
iox-#32 added dispatch timer implementation
elfenpiff Mar 19, 2020
887e034
iox-#32 added partial timer implementation
elfenpiff Mar 19, 2020
157e1fa
iox-#32 implemented timer with condition variables
elfenpiff Mar 19, 2020
4bd81d7
iox-#32 fixed if condition
elfenpiff Mar 20, 2020
fb301ce
Merge branch 'master' of https://github.com/eclipse/iceoryx into iox-…
elfenpiff Mar 20, 2020
e014312
Merge branch 'iox-#32-implement-posix-timer-via-dispatch-timer' of gi…
elfenpiff Mar 20, 2020
f6bedb7
iox-#32 switched from bool and mutex to atomic
elfenpiff Mar 20, 2020
f576c87
iox-#32 added some more test to define the behavior of the timer
elfenpiff Mar 20, 2020
7b33a80
iox-#32 slowed down the test a bit so that the also run on heavy syst…
elfenpiff Mar 20, 2020
3a2a69d
iox-#32 stopping the timer is not blocking anymore
elfenpiff Mar 20, 2020
ec223a8
iox-#32 added more test to verify the blocking nature
elfenpiff Mar 20, 2020
6c35ef1
iox-#32 implemented gettime
elfenpiff Mar 20, 2020
eaa870f
iox-#32 condition variable use wait_until
elfenpiff Mar 20, 2020
46300c0
iox-#32 implemented posix timer and adjusted timing tests
elfenpiff Mar 21, 2020
0f29b4b
iox-#32 code cleanup
elfenpiff Mar 21, 2020
b55b8cc
iox-#32 corrected documentation
elfenpiff Mar 21, 2020
14d206d
iox-#32 fixed undefined behavior in semaphore va_arg list
elfenpiff Mar 22, 2020
caf7460
iox-#32 some code cleanup
elfenpiff Mar 22, 2020
6c47af5
iox-#32 fixed review findings
elfenpiff Mar 22, 2020
618cd44
iox-#32 merged current develop and fixed unsigned int hickup
elfenpiff May 20, 2020
60d6772
iox-#32 overload for fromString conversion to unsigned long only for …
elfenpiff May 20, 2020
ab1f8ce
iox-#32 fixed review findings
elfenpiff May 20, 2020
318c4b9
iox-#32 fixed further review findings
elfenpiff May 26, 2020
b2ecbe8
iox-#32 removed memory order to prevent reordering
elfenpiff May 27, 2020
9f9c425
iox-#32 review findings
elfenpiff May 27, 2020
df9b15d
iox-#32 possible negative nanoseconds when time difference is positiv…
elfenpiff May 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class MqBase
MqBase() = delete;
// TODO: unique identifier problem, multiple MqBase objects with the
// same InterfaceName are using the same message queue
MqBase(const std::string& InterfaceName, const long maxMessages, const long messageSize) noexcept;
MqBase(const std::string& InterfaceName, const int64_t maxMessages, const int64_t messageSize) noexcept;
virtual ~MqBase() = default;

/// @brief delete copy and move ctor and assignment since they are not needed
Expand Down Expand Up @@ -243,8 +243,8 @@ class MqInterfaceUser : public MqBase
/// @param[in] maxMessages maximum number of queued messages
/// @param[in] message size maximum message size
MqInterfaceUser(const std::string& name,
const long maxMessages = APP_MAX_MESSAGES,
const long messageSize = APP_MESSAGE_SIZE) noexcept;
const int64_t maxMessages = APP_MAX_MESSAGES,
const int64_t messageSize = APP_MESSAGE_SIZE) noexcept;

/// @brief The copy constructor and assignment operator are deleted since
/// this class manages a resource (message queue) which cannot
Expand Down Expand Up @@ -272,8 +272,8 @@ class MqInterfaceCreator : public MqBase
/// @param[in] maxMessages maximum number of queued messages
/// @param[in] message size maximum message size
MqInterfaceCreator(const std::string& name,
const long maxMessages = ROUDI_MAX_MESSAGES,
const long messageSize = ROUDI_MESSAGE_SIZE) noexcept;
const int64_t maxMessages = ROUDI_MAX_MESSAGES,
const int64_t messageSize = ROUDI_MESSAGE_SIZE) noexcept;

/// @brief The copy constructor and assignment operator is deleted since
/// this class manages a resource (message queue) which cannot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ MemPoolCollectionMemoryBlock::~MemPoolCollectionMemoryBlock() noexcept

uint64_t MemPoolCollectionMemoryBlock::size() const noexcept
{
return cxx::align(sizeof(mepoo::MemoryManager), mepoo::MemPool::MEMORY_ALIGNMENT)
return cxx::align(static_cast<uint64_t>(sizeof(mepoo::MemoryManager)), mepoo::MemPool::MEMORY_ALIGNMENT)
+ mepoo::MemoryManager::requiredFullMemorySize(m_memPoolConfig);
}

uint64_t MemPoolCollectionMemoryBlock::alignment() const noexcept
{
// algorithm::align doesn't like constexpr values
auto memPoolAlignment = mepoo::MemPool::MEMORY_ALIGNMENT;
return algorithm::max(alignof(mepoo::MemoryManager), memPoolAlignment);
return algorithm::max(static_cast<uint64_t>(alignof(mepoo::MemoryManager)), memPoolAlignment);
}

void MemPoolCollectionMemoryBlock::memoryAvailable(void* memory) noexcept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ MemPoolSegmentManagerMemoryBlock::~MemPoolSegmentManagerMemoryBlock() noexcept

uint64_t MemPoolSegmentManagerMemoryBlock::size() const noexcept
{
return cxx::align(sizeof(mepoo::SegmentManager<>), SHARED_MEMORY_ALIGNMENT)
return cxx::align(static_cast<uint64_t>(sizeof(mepoo::SegmentManager<>)), SHARED_MEMORY_ALIGNMENT)
+ mepoo::SegmentManager<>::requiredManagementMemorySize(m_segmentConfig);
}

uint64_t MemPoolSegmentManagerMemoryBlock::alignment() const noexcept
{
return algorithm::max(alignof(mepoo::SegmentManager<>), SHARED_MEMORY_ALIGNMENT);
return algorithm::max(static_cast<uint64_t>(alignof(mepoo::SegmentManager<>)), SHARED_MEMORY_ALIGNMENT);
}

void MemPoolSegmentManagerMemoryBlock::memoryAvailable(void* memory) noexcept
Expand Down
1 change: 0 additions & 1 deletion iceoryx_posh/source/roudi/roudi_multi_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "iceoryx_posh/runtime/port_config_info.hpp"
#include "iceoryx_utils/cxx/convert.hpp"
#include "iceoryx_utils/fixed_string/string100.hpp"
#include "iceoryx_utils/posix_wrapper/timer.hpp"

namespace iox
{
Expand Down
3 changes: 2 additions & 1 deletion iceoryx_posh/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.5)
project(test_iceoryx_posh VERSION ${test_iceoryx_posh})
set(test_iceoryx_posh_VERSION 0)
project(test_iceoryx_posh VERSION ${test_iceoryx_posh_VERSION})
elfenpiff marked this conversation as resolved.
Show resolved Hide resolved

find_package(iceoryx_utils_testing REQUIRED)

Expand Down
23 changes: 19 additions & 4 deletions iceoryx_utils/include/iceoryx_utils/internal/cxx/convert.inl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <limits>
namespace iox
{
namespace cxx
Expand Down Expand Up @@ -105,15 +104,18 @@ inline bool convert::stringIsNumberWithErrorMessage(const char* v, const NumberT
std::cerr << v << " is not ";
switch (type)
{
case NumberType::FLOAT: {
case NumberType::FLOAT:
{
std::cerr << "a float";
break;
}
case NumberType::INTEGER: {
case NumberType::INTEGER:
{
std::cerr << "a signed integer";
break;
}
case NumberType::UNSIGNED_INTEGER: {
case NumberType::UNSIGNED_INTEGER:
{
std::cerr << "an unsigned integer";
break;
}
Expand Down Expand Up @@ -205,6 +207,19 @@ inline bool convert::fromString<uint64_t>(const char* v, uint64_t& dest)
return true;
}

#ifdef __APPLE__
/// introduced for mac os since unsigned long is not uint64_t despite it has the same size
/// who knows why ¯\_(ツ)_/¯
template <>
inline bool convert::fromString<unsigned long>(const char* v, unsigned long& dest)
{
uint64_t temp{0};
bool retVal = fromString(v, temp);
dest = temp;
return retVal;
}
#endif

template <>
inline bool convert::fromString<uint32_t>(const char* v, uint32_t& dest)
{
Expand Down
14 changes: 8 additions & 6 deletions iceoryx_utils/include/iceoryx_utils/posix_wrapper/timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ enum class TimerError
NO_PERMISSION,
INVALID_POINTER,
NO_TIMER_TO_DELETE,
TIMEOUT_IS_ZERO,
INTERNAL_LOGIC_ERROR
};

Expand Down Expand Up @@ -115,7 +116,7 @@ class Timer
/// @brief Wrapper that can be registered with the operating system
static void callbackHelper(sigval data);

OsTimer(units::Duration timeToWait, std::function<void()> callback) noexcept;
OsTimer(const units::Duration timeToWait, const std::function<void()>& callback) noexcept;

OsTimer(const OsTimer&) = delete;
OsTimer(OsTimer&&) = delete;
Expand All @@ -129,7 +130,8 @@ class Timer
///
/// The callback is called by the operating system after the time has expired.
///
/// @param[in] periodic - can be a periodic timer if set to true, default false
/// @param[in] periodic - can be a periodic timer if set to RunMode::PERIODIC or
/// once when in RunMode::ONCE
/// @note Shall only be called when callback is given
cxx::expected<TimerError> start(const RunMode runMode) noexcept;

Expand All @@ -155,7 +157,7 @@ class Timer
bool hasError() const noexcept;

/// @brief Returns the error that occured on constructing the object
cxx::error<TimerError> getError() const noexcept;
TimerError getError() const noexcept;

private:
/// @brief Call the user-defined callback
Expand Down Expand Up @@ -196,7 +198,7 @@ class Timer
/// @param[in] timeToWait - How long should be waited?
/// @note Does not set up an operating system timer, but uses CLOCK_REALTIME instead
/// @todo refactor this cTor and its functionality to a class called StopWatch
Timer(units::Duration timeToWait) noexcept;
Timer(const units::Duration timeToWait) noexcept;

/// @brief Creates a timer with an operating system callback
///
Expand All @@ -206,7 +208,7 @@ class Timer
/// @param[in] callback - Function called after timeToWait (User needs to ensure lifetime of function till stop()
/// call)
/// @note Operating systems needs a valid reference to this object, hence DesignPattern::Creation can't be used
Timer(units::Duration timeToWait, std::function<void()> callback) noexcept;
Timer(const units::Duration timeToWait, const std::function<void()>& callback) noexcept;

/// @brief creates Duration from the result of clock_gettime(CLOCK_REALTIME, ...)
/// @return if the clock_gettime call failed TimerError is returned otherwise Duration
Expand Down Expand Up @@ -266,7 +268,7 @@ class Timer
bool hasError() const noexcept;

/// @brief Returns the error that occured on constructing the object
cxx::error<TimerError> getError() const noexcept;
TimerError getError() const noexcept;

private:
cxx::optional<OsTimer> m_osTimer;
Expand Down
49 changes: 26 additions & 23 deletions iceoryx_utils/platform/mac/include/iceoryx_utils/platform/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,40 @@

#pragma once

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

using timer_t = void*;
#include <thread>

struct itimerspec
{
timespec it_interval;
timespec it_value;
};

inline int timer_create(clockid_t clockid, struct sigevent* sevp, timer_t* timerid)
{
return 0;
}

inline int timer_delete(timer_t timerid)
{
return 0;
}

inline int timer_settime(timer_t timerid, int flags, const struct itimerspec* new_value, struct itimerspec* old_value)
struct appleTimer_t
{
return 0;
}
std::thread thread;
void (*callback)(union sigval);
sigval callbackParameter;
std::atomic_bool keepRunning{true};

struct
{
std::mutex mutex;
timespec startTime;
bool wasCallbackCalled{false};
bool runOnce{false};
bool isTimerRunning{false};
itimerspec timeParameters;
std::condition_variable wakeup;
} parameter;
};

inline int timer_gettime(timer_t timerid, struct itimerspec* curr_value)
{
return 0;
}
using timer_t = appleTimer_t*;

inline int timer_getoverrun(timer_t timerid)
{
return 0;
}
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);
5 changes: 4 additions & 1 deletion iceoryx_utils/platform/mac/source/semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ iox_sem_t* iox_sem_open_impl(const char* name, int oflag, ...)
{
va_list va;
va_start(va, oflag);
mode_t mode = va_arg(va, mode_t);
// mode_t is an alias for unsigned short but this causes undefined
// behavior in va_arg since it is a promotable type - which will be
// promoted to int
mode_t mode = static_cast<mode_t>(va_arg(va, unsigned int));
unsigned int value = va_arg(va, unsigned int);
va_end(va);

Expand Down
Loading