iceoryx_hoofs 2.0.3
deadline_timer.hpp
1// Copyright (c) 2021 by Robert Bosch GmbH. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// SPDX-License-Identifier: Apache-2.0
16#ifndef IOX_HOOFS_CXX_DEADLINETIMER_HPP
17#define IOX_HOOFS_CXX_DEADLINETIMER_HPP
18
19#include "iceoryx_hoofs/internal/units/duration.hpp"
20#include "iceoryx_hoofs/platform/signal.hpp"
21
22#include <chrono>
23#include <cstdint>
24
25namespace iox
26{
27namespace cxx
28{
44{
45 public:
48 explicit DeadlineTimer(const iox::units::Duration timeToWait) noexcept;
49
52 bool hasExpired() const noexcept;
53
56 void reset() noexcept;
57
62 void reset(const iox::units::Duration timeToWait) noexcept;
63
66 iox::units::Duration remainingTime() const noexcept;
67
68 private:
69 static iox::units::Duration getCurrentMonotonicTime() noexcept;
70
71 iox::units::Duration m_timeToWait;
72 iox::units::Duration m_endTime;
73};
74
75} // namespace cxx
76} // namespace iox
77
78
79#endif // IOX_HOOFS_CXX_DEADLINETIMER_HPP
This offers the deadline timer functionality. It has user convenient methods to reset the timer [by d...
Definition: deadline_timer.hpp:44
bool hasExpired() const noexcept
Checks if the timer has expired compared to its absolute end time.
DeadlineTimer(const iox::units::Duration timeToWait) noexcept
Constructor.
iox::units::Duration remainingTime() const noexcept
calculates the remaining time before the timer goes off
void reset() noexcept
reinitializes the ending time for the timer. The absolute end time is calculated by adding time to wa...
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:29