From: Adam C. Emerson Date: Fri, 6 Mar 2020 02:15:25 +0000 (-0500) Subject: common/ceph_timer: Use unique_function, allowing noncopyable events X-Git-Tag: v15.1.1~42^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=380e05d24e5f8e5d9d6b705fc7bbb16dea236b9c;p=ceph.git common/ceph_timer: Use unique_function, allowing noncopyable events Signed-off-by: Adam C. Emerson --- diff --git a/src/common/ceph_timer.h b/src/common/ceph_timer.h index 9d0aabc72862..d5c0d60f37e5 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;