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-1391 Move time-related classes to Time module #1863

10 changes: 10 additions & 0 deletions .clang-tidy-diff-scans.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
./iceoryx_hoofs/test/moduletests/test_polymorphic_handler.cpp
./iceoryx_hoofs/test/moduletests/test_static_lifetime_guard.cpp

./iceoryx_hoofs/posix/**/*

./iceoryx_hoofs/container/include/iox/**/*
./iceoryx_hoofs/test/moduletests/test_container_*

Expand All @@ -53,6 +55,14 @@

./iceoryx_hoofs/design/**/*
./iceoryx_hoofs/test/moduletests/test_design_*
./iceoryx_hoofs/utility/**/*
./iceoryx_hoofs/test/moduletests/test_utility_*

./iceoryx_hoofs/primitives/**/*
./iceoryx_hoofs/test/moduletests/test_primitives_*

./iceoryx_hoofs/time/**/*
./iceoryx_hoofs/test/moduletests/test_time_*

# IMPORTANT:
# after the first # everything is considered a comment, add new files and
Expand Down
22 changes: 22 additions & 0 deletions doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -998,3 +998,25 @@
// iox::string to std::string
std::string myConvertedIoxString = iox::into<std::string>(myIoxString);
```

44. Move and rename `DeadlineTimer`
mossmaurice marked this conversation as resolved.
Show resolved Hide resolved

```cpp
// before
#include "iceoryx_hoofs/cxx/deadline_timer.hpp"
iox::cxx::DeadlineTimer myTimer;

// after
#include "iox/deadline_timer.hpp"
iox::deadline_timer myTimer;
```

45. Changed include path of `iox::units::Duration`
mossmaurice marked this conversation as resolved.
Show resolved Hide resolved

```cpp
// before
#include "iceoryx_hoofs/internal/units/duration.hpp"

// after
#include "iox/duration.hpp"
```
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

#include "iceoryx_dust/design/creation.hpp"
#include "iceoryx_hoofs/internal/posix_wrapper/ipc_channel.hpp"
#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_platform/fcntl.hpp"
#include "iceoryx_platform/mqueue.hpp"
#include "iceoryx_platform/stat.hpp"
#include "iox/duration.hpp"
#include "iox/optional.hpp"

namespace iox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include "iceoryx_hoofs/concurrent/lockfree_queue.hpp"
#include "iceoryx_hoofs/internal/posix_wrapper/ipc_channel.hpp"
#include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp"
#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_hoofs/posix_wrapper/unnamed_semaphore.hpp"
#include "iceoryx_platform/semaphore.hpp"
#include "iox/duration.hpp"
#include "iox/expected.hpp"
#include "iox/optional.hpp"
#include "iox/string.hpp"
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_dust/source/posix_wrapper/named_pipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "iceoryx_dust/posix_wrapper/named_pipe.hpp"
#include "iceoryx_dust/cxx/std_string_support.hpp"
#include "iceoryx_hoofs/cxx/deadline_timer.hpp"
#include "iox/deadline_timer.hpp"
#include "iox/into.hpp"

#include <thread>
Expand Down Expand Up @@ -389,7 +389,7 @@ bool NamedPipe::NamedPipeData::waitForInitialization() const noexcept
return true;
}

cxx::DeadlineTimer deadlineTimer(WAIT_FOR_INIT_TIMEOUT);
deadline_timer deadlineTimer(WAIT_FOR_INIT_TIMEOUT);

while (!deadlineTimer.hasExpired())
{
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_examples/iceperf/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "example_common.hpp"
#include "topic_data.hpp"

#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iox/duration.hpp"

#include <chrono>
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_examples/iceperf/mq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#include "base.hpp"

#include "iceoryx_hoofs/internal/posix_wrapper/ipc_channel.hpp"
#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_platform/fcntl.hpp"
#include "iceoryx_platform/mqueue.hpp"
#include "iceoryx_platform/stat.hpp"
#include "iox/duration.hpp"
#include "iox/optional.hpp"

#include <string>
Expand Down
5 changes: 4 additions & 1 deletion iceoryx_hoofs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ cc_library(
"source/**/*.hpp",
"memory/source/*.cpp",
"design/source/*.cpp",
"posix/time/source/*.cpp",
]),
hdrs = glob(["include/**"]) + glob(["legacy/**"]) + glob(["memory/**"]) + glob(["container/**"]) + glob(["vocabulary/**"]) + glob(["utility/**"]) + glob(["primitives/**"]) + glob(["design/**"]) + [
hdrs = glob(["include/**"]) + glob(["legacy/**"]) + glob(["memory/**"]) + glob(["container/**"]) + glob(["vocabulary/**"]) + glob(["time/**"]) + glob(["utility/**"]) + glob(["primitives/**"]) + glob(["posix/**"]) + glob(["design/**"]) + [
":iceoryx_hoofs_deployment_hpp",
],
includes = [
Expand All @@ -45,7 +46,9 @@ cc_library(
"include/",
"legacy/include/",
"memory/include/",
"posix/time/include/",
"primitives/include/",
"time/include/",
"utility/include/",
"vocabulary/include/",
],
Expand Down
8 changes: 6 additions & 2 deletions iceoryx_hoofs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ iox_add_library(
${PROJECT_SOURCE_DIR}/utility/include
${PROJECT_SOURCE_DIR}/primitives/include
${PROJECT_SOURCE_DIR}/design/include
${PROJECT_SOURCE_DIR}/time/include
${PROJECT_SOURCE_DIR}/posix/time/include
${CMAKE_BINARY_DIR}/generated/iceoryx_hoofs/include
INSTALL_INTERFACE include/${PREFIX}
EXPORT_INCLUDE_DIRS include/
Expand All @@ -64,10 +66,12 @@ iox_add_library(
utility/include/
primitives/include/
design/include/
time/include/
posix/time/include/
FILES
source/concurrent/loffli.cpp
source/cxx/adaptive_wait.cpp
source/cxx/deadline_timer.cpp
posix/time/source/adaptive_wait.cpp
posix/time/source/deadline_timer.cpp
source/cxx/filesystem.cpp
source/cxx/requires.cpp
source/cxx/type_traits.cpp
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ setTimeout(5_ms); // 5 milliseconds
| class | internal | description |
|:-------------------:|:--------:|:--------------------------------------------------------------------------------------------------------------------------------------------|
|`Duration` | i | Represents the unit time, is convertible to `timespec` and `timeval`. User defined literals are available for convenience and readability. |
|`DeadlineTimer` | | Polling based timer to check for an elapsed deadline. |
|`deadline_timer | | Polling based timer to check for an elapsed deadline. |
|`adaptive_wait` | i | Building block to realize busy waiting loops with low CPU load. |

<center>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#ifndef IOX_HOOFS_CONCURRENT_PERIODIC_TASK_HPP
#define IOX_HOOFS_CONCURRENT_PERIODIC_TASK_HPP

#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_hoofs/posix_wrapper/thread.hpp"
#include "iceoryx_hoofs/posix_wrapper/unnamed_semaphore.hpp"
#include "iox/duration.hpp"
#include "iox/string.hpp"

#include <thread>
Expand All @@ -46,7 +46,7 @@ static constexpr PeriodicTaskManualStart_t PeriodicTaskManualStart;
/// This can be a struct with a 'operator()()' overload, a 'cxx::function_ref<void()>' or 'std::fuction<void()>'.
/// @code
/// #include <iceoryx_hoofs/internal/concurrent/periodic_task.hpp>
/// #include <iceoryx_hoofs/internal/units/duration.hpp>
/// #include <iox/duration.hpp>
/// #include <iostream>
///
/// int main()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#ifndef IOX_HOOFS_POSIX_WRAPPER_SEMAPHORE_INTERFACE_HPP
#define IOX_HOOFS_POSIX_WRAPPER_SEMAPHORE_INTERFACE_HPP

#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_platform/semaphore.hpp"
#include "iox/duration.hpp"
#include "iox/expected.hpp"

namespace iox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

#include "iceoryx_hoofs/cxx/filesystem.hpp"
#include "iceoryx_hoofs/internal/posix_wrapper/ipc_channel.hpp"
#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_platform/fcntl.hpp"
#include "iceoryx_platform/platform_settings.hpp"
#include "iceoryx_platform/socket.hpp"
#include "iceoryx_platform/stat.hpp"
#include "iceoryx_platform/un.hpp"
#include "iox/duration.hpp"
#include "iox/optional.hpp"

namespace iox
Expand Down
33 changes: 33 additions & 0 deletions iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/deadline_timer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2023 by Apex.AI Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_HOOFS_CXX_DEADLINE_TIMER_HPP
#define IOX_HOOFS_CXX_DEADLINE_TIMER_HPP

#include "iox/deadline_timer.hpp"

namespace iox
{
/// @todo iox-#1593 Deprecate include
/// [[deprecated("Deprecated in 3.0, removed in 4.0, please include 'iox/deadline_timer.hpp' instead")]]
namespace cxx
{
/// @deprecated use `iox::deadline_timer` instead of `iox::cxx::DeadlineTimer`
using DeadlineTimer = iox::deadline_timer;
} // namespace cxx
} // namespace iox

#endif // IOX_HOOFS_CXX_DEADLINE_TIMER_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_CXX_DEADLINETIMER_HPP
#define IOX_HOOFS_CXX_DEADLINETIMER_HPP
#ifndef IOX_HOOFS_TIME_DEADLINE_TIMER_HPP
#define IOX_HOOFS_TIME_DEADLINE_TIMER_HPP

#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_platform/signal.hpp"
#include "iox/duration.hpp"

#include <chrono>
#include <cstdint>

namespace iox
{
namespace cxx
{
/// @brief This offers the deadline timer functionality. It has user convenient methods to reset the timer [by default
/// it uses the intialized duration], reset timer to a customized duration, check if the timer is active and user can
/// also get to know about the remaining time before the timer goes off
/// @code
/// iox::cxx::DeadlineTimer deadlineTimer(1000_ms);
/// iox::cxx::deadline_timer deadlineTimer(1000_ms);
///
/// // to check if the timer is active
/// if( deadlineTimer.hasExpired()){
Expand All @@ -40,12 +38,12 @@ namespace cxx
/// deadlineTimer.reset();
///
/// @endcode
class DeadlineTimer
class deadline_timer
{
public:
/// @brief Constructor
/// @param[in] timeToWait duration until the timer expires
explicit DeadlineTimer(const iox::units::Duration timeToWait) noexcept;
explicit deadline_timer(const iox::units::Duration timeToWait) noexcept;

/// @brief Checks if the timer has expired compared to its absolute end time
/// @return false if the timer is still active and true if it is expired
Expand All @@ -71,9 +69,7 @@ class DeadlineTimer
iox::units::Duration m_timeToWait;
iox::units::Duration m_endTime;
};

} // namespace cxx
} // namespace iox


#endif // IOX_HOOFS_CXX_DEADLINETIMER_HPP
#endif // IOX_HOOFS_TIME_DEADLINE_TIMER_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_HOOFS_CXX_ADAPTIVE_WAIT_HPP
#define IOX_HOOFS_CXX_ADAPTIVE_WAIT_HPP
#ifndef IOX_HOOFS_TIME_ADAPTIVE_WAIT_HPP
#define IOX_HOOFS_TIME_ADAPTIVE_WAIT_HPP

#include "iceoryx_hoofs/cxx/function_ref.hpp"
#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iox/duration.hpp"

#include <cstdint>

namespace iox
{
namespace cxx
{
namespace internal
namespace detail
{
/// @brief Building block to implement a busy waiting loop efficiently. It
/// pursues a strategy where in the beginning the behavior is like a
Expand Down Expand Up @@ -56,7 +54,7 @@ class adaptive_wait

/// @brief Waits in a loop in a smart wait until continueToWait returns false.
/// @param[in] continueToWait callable which returns if the wait should continue
void wait_loop(const function_ref<bool()>& continueToWait) noexcept;
void wait_loop(const cxx::function_ref<bool()>& continueToWait) noexcept;

protected:
/// @note All numbers are not accurate and are just rough estimates
Expand Down Expand Up @@ -104,8 +102,7 @@ class adaptive_wait
private:
uint64_t m_yieldCount = 0U;
};
} // namespace internal
} // namespace cxx
} // namespace detail
} // namespace iox

#endif
#endif // IOX_HOOFS_TIME_ADAPTIVE_WAIT_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_hoofs/internal/cxx/adaptive_wait.hpp"
#include "iox/detail/adaptive_wait.hpp"

#include <thread>

namespace iox
{
namespace cxx
{
namespace internal
namespace detail
{
constexpr std::chrono::microseconds adaptive_wait::INITIAL_WAITING_TIME;
constexpr std::chrono::milliseconds adaptive_wait::FINAL_WAITING_TIME;
Expand All @@ -47,13 +45,12 @@ void adaptive_wait::wait() noexcept
}
}

void adaptive_wait::wait_loop(const function_ref<bool()>& continueToWait) noexcept
void adaptive_wait::wait_loop(const cxx::function_ref<bool()>& continueToWait) noexcept
{
while (continueToWait())
{
wait();
}
}
} // namespace internal
} // namespace cxx
} // namespace detail
} // namespace iox
Loading