From 380e05d24e5f8e5d9d6b705fc7bbb16dea236b9c Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Thu, 5 Mar 2020 21:15:25 -0500 Subject: [PATCH] common/ceph_timer: Use unique_function, allowing noncopyable events Signed-off-by: Adam C. Emerson --- src/common/ceph_timer.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/common/ceph_timer.h b/src/common/ceph_timer.h index 9d0aabc728620..d5c0d60f37e5d 100644 --- a/src/common/ceph_timer.h +++ b/src/common/ceph_timer.h @@ -15,6 +15,7 @@ #ifndef COMMON_CEPH_TIMER_H #define COMMON_CEPH_TIMER_H +#include #include #include #include @@ -23,6 +24,8 @@ #include #include +#include "include/function2.hpp" + namespace bi = boost::intrusive; namespace ceph { @@ -54,14 +57,14 @@ class timer { struct event { typename TC::time_point t = typename TC::time_point::min(); std::uint64_t id = 0; - std::function f; + fu2::unique_function f; sh schedule_link; sh event_link; event() = default; event(typename TC::time_point t, std::uint64_t id, - std::function f) : t(t), id(id), f(std::move(f)) {} + fu2::unique_function f) : t(t), id(id), f(std::move(f)) {} event(const event&) = delete; event& operator =(const event&) = delete; @@ -171,7 +174,7 @@ public: return; suspended = false; - ceph_assert(!thread.joinable()); + assert(!thread.joinable()); thread = std::thread(&timer::timer_thread, this); } @@ -274,7 +277,7 @@ public: // Returns an event id. If you had an event_id from the first // scheduling, replace it with this return value. std::uint64_t reschedule_me(typename TC::time_point when) { - ceph_assert(std::this_thread::get_id() == thread.get_id()); + assert(std::this_thread::get_id() == thread.get_id()); std::lock_guard l(lock); running->t = when; std::uint64_t id = ++next_id; -- 2.39.5