From 2c31bb55334bf000372afceb2815bf0b120d5a28 Mon Sep 17 00:00:00 2001 From: Ivo Ivanov Date: Thu, 19 Feb 2026 20:36:35 +0100 Subject: [PATCH 01/40] T --- icey/include/icey/icey_async_await.hpp | 65 +++++++++++++++++++++----- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/icey/include/icey/icey_async_await.hpp b/icey/include/icey/icey_async_await.hpp index 2fb7d1e..dda1f53 100644 --- a/icey/include/icey/icey_async_await.hpp +++ b/icey/include/icey/icey_async_await.hpp @@ -12,9 +12,12 @@ #include #include #include +#include #include #include /// for ID #include +#include +#include #include "rclcpp/rclcpp.hpp" #include "rclcpp/version.h" @@ -113,6 +116,7 @@ struct NodeBase { template void add_task_for(uint64_t id, const Duration &timeout, CallbackT on_timeout, rclcpp::CallbackGroup::SharedPtr group = nullptr) { + std::lock_guard lock{oneoff_tasks_mutex_}; oneoff_cancelled_timers_.clear(); oneoff_active_timers_.emplace(id, create_wall_timer( timeout, @@ -125,6 +129,7 @@ struct NodeBase { /// Cancel a previously scheduled task by key (no-op if not present) bool cancel_task_for(uint64_t id) { + std::lock_guard lock{oneoff_tasks_mutex_}; auto it = oneoff_active_timers_.find(id); if (it == oneoff_active_timers_.end()) return false; auto timer = it->second; @@ -201,11 +206,18 @@ struct NodeBase { std::unordered_set> oneoff_cancelled_timers_; /// Active one-off tasks keyed by a stable uintptr_t key std::unordered_map> oneoff_active_timers_; + mutable std::mutex oneoff_tasks_mutex_; public: // Test helpers (introspection) - std::size_t oneoff_active_task_count() const { return oneoff_active_timers_.size(); } - std::size_t oneoff_cancelled_task_count() const { return oneoff_cancelled_timers_.size(); } + std::size_t oneoff_active_task_count() const { + std::lock_guard lock{oneoff_tasks_mutex_}; + return oneoff_active_timers_.size(); + } + std::size_t oneoff_cancelled_task_count() const { + std::lock_guard lock{oneoff_tasks_mutex_}; + return oneoff_cancelled_timers_.size(); + } }; /// A subscription + buffer for transforms that allows for asynchronous lookups and to subscribe on @@ -253,6 +265,8 @@ struct TransformBufferImpl { OnTransform on_transform; OnError on_error; std::optional