Skip to content

Commit 1203a91

Browse files
authored
Merge pull request #67 from basiliscos/v0.35-dev
v0.35 dev
2 parents 2edf680 + 0e04ab8 commit 1203a91

File tree

6 files changed

+53
-8
lines changed

6 files changed

+53
-8
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)
22

33
cmake_policy(SET CMP0074 NEW)
44

5-
set(ROTOR_VERSION "0.34")
5+
set(ROTOR_VERSION "0.35")
66
project (rotor LANGUAGES CXX VERSION ${ROTOR_VERSION})
77
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
88

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ project.
6767

6868
## Changelog
6969

70+
### 0.35 (07-Oct-2025)
71+
- [breaking] asio supervisor uses steady clock instead of system clock (aka deadline_timer)
72+
7073
### 0.34 (25-Mar-2025)
7174
- [feature] improve c++20 support
7275
- [workaround, fltk] more realiable message delivery for fltk backend. Fltk

docs/Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
[reliable]: https://en.wikipedia.org/wiki/Reliability_(computer_networking) "reliable"
55
[request-response]: https://en.wikipedia.org/wiki/Request%E2%80%93response
66

7+
### 0.35 (07-Oct-2025)
8+
- [breaking] asio supervisor uses steady clock instead of system clock (aka deadline_timer)
9+
710
### 0.34 (25-Mar-2025)
811
- [feature] improve c++20 support
912
- [workaround, fltk] more realiable message delivery for fltk backend. Fltk

include/rotor/asio/supervisor_asio.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
//
4-
// Copyright (c) 2019-2022 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
4+
// Copyright (c) 2019-2025 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
55
//
66
// Distributed under the MIT Software License
77
//
@@ -90,15 +90,15 @@ struct ROTOR_ASIO_API supervisor_asio_t : public supervisor_t {
9090

9191
protected:
9292
/** \struct timer_t
93-
* \brief boos::asio::deadline_timer with embedded timer handler */
94-
struct timer_t : public asio::deadline_timer {
93+
* \brief boos::asio::steady_timer with embedded timer handler */
94+
struct timer_t : public asio::steady_timer {
9595

9696
/** \brief non-owning pointer to timer handler */
9797
timer_handler_base_t *handler;
9898

9999
/** \brief constructs timer using timer handler and boost asio io_context */
100100
timer_t(timer_handler_base_t *handler_, asio::io_context &io_context)
101-
: asio::deadline_timer(io_context), handler{handler_} {}
101+
: asio::steady_timer(io_context), handler{handler_} {}
102102
};
103103

104104
/** \brief unique pointer to timer */

src/rotor/asio/supervisor_asio.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2019-2022 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
2+
// Copyright (c) 2019-2025 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
33
//
44
// Distributed under the MIT Software License
55
//
@@ -40,8 +40,10 @@ void supervisor_asio_t::start() noexcept { create_forwarder (&supervisor_asio_t:
4040
void supervisor_asio_t::shutdown() noexcept { create_forwarder (&supervisor_asio_t::invoke_shutdown)(); }
4141

4242
void supervisor_asio_t::do_start_timer(const pt::time_duration &interval, timer_handler_base_t &handler) noexcept {
43-
auto timer = std::make_unique<supervisor_asio_t::timer_t>(&handler, strand->context());
44-
timer->expires_from_now(interval);
43+
using namespace asio::chrono;
44+
auto timer = std::make_unique<timer_t>(&handler, strand->context());
45+
auto micro_seconds = microseconds(interval.total_microseconds());
46+
timer->expires_after(duration_cast<timer_t::duration>(micro_seconds));
4547

4648
intrusive_ptr_t<supervisor_asio_t> self(this);
4749
request_id_t timer_id = handler.request_id;

tests/104-asio_timer.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ struct bad_actor_t : public r::actor_base_t {
4747
}
4848
};
4949

50+
struct timer_actor_t: r::actor_base_t {
51+
using r::actor_base_t::actor_base_t;
52+
void on_start() noexcept override {
53+
r::actor_base_t::on_start();
54+
auto timeout = r::pt::time_duration{r::pt::seconds{-1}};
55+
auto req_id = start_timer(timeout, *this, &timer_actor_t::on_timer);
56+
}
57+
58+
void on_timer(r::request_id_t req, bool cancelled){
59+
timer_triggered = true;
60+
do_shutdown();
61+
}
62+
63+
bool timer_triggered = false;
64+
};
65+
5066
TEST_CASE("timer", "[supervisor][asio]") {
5167
asio::io_context io_context{1};
5268
auto timeout = r::pt::milliseconds{10};
@@ -68,3 +84,24 @@ TEST_CASE("timer", "[supervisor][asio]") {
6884
REQUIRE(sup->get_leader_queue().size() == 0);
6985
CHECK(rt::empty(sup->get_subscription()));
7086
}
87+
88+
TEST_CASE("zero timeout", "[supervisor][asio]") {
89+
asio::io_context io_context{1};
90+
auto timeout = r::pt::milliseconds{10};
91+
auto system_context = ra::system_context_asio_t::ptr_t{new ra::system_context_asio_t(io_context)};
92+
auto strand = std::make_shared<asio::io_context::strand>(io_context);
93+
94+
auto sup = system_context->create_supervisor<rt::supervisor_asio_test_t>().strand(strand).timeout(timeout).finish();
95+
auto actor = sup->create_actor<timer_actor_t>().timeout(timeout).autoshutdown_supervisor().finish();
96+
97+
sup->start();
98+
io_context.run();
99+
100+
CHECK(actor->timer_triggered);
101+
102+
REQUIRE(static_cast<r::actor_base_t *>(actor.get())->access<rt::to::state>() == r::state_t::SHUT_DOWN);
103+
104+
REQUIRE(sup->get_state() == r::state_t::SHUT_DOWN);
105+
REQUIRE(sup->get_leader_queue().size() == 0);
106+
CHECK(rt::empty(sup->get_subscription()));
107+
}

0 commit comments

Comments
 (0)