From: Adam C. Emerson Date: Thu, 5 Mar 2020 21:16:15 +0000 (-0500) Subject: common/ceph_timer: Fix namespaces X-Git-Tag: v15.1.1~42^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f19ee383d3c5576e6b476adc2c3111a889e72ac9;p=ceph.git common/ceph_timer: Fix namespaces Stuffing things into 'detail' and using them just makes backtraces and valgrind illegible. Signed-off-by: Adam C. Emerson --- diff --git a/src/common/ceph_timer.h b/src/common/ceph_timer.h index 56649eb2e6ec..4e7331f2864e 100644 --- a/src/common/ceph_timer.h +++ b/src/common/ceph_timer.h @@ -22,22 +22,15 @@ #include #include +namespace bi = boost::intrusive; namespace ceph { + /// Newly constructed timer should be suspended at point of /// construction. struct construct_suspended_t { }; constexpr construct_suspended_t construct_suspended { }; -namespace timer_detail { -using boost::intrusive::member_hook; -using boost::intrusive::set_member_hook; -using boost::intrusive::link_mode; -using boost::intrusive::normal_link; -using boost::intrusive::set; -using boost::intrusive::constant_time_size; -using boost::intrusive::compare; - // Compared to the SafeTimer this does fewer allocations (you // don't have to allocate a new Context every time you // want to cue the next tick.) @@ -55,21 +48,21 @@ using boost::intrusive::compare; template class timer { - using sh = set_member_hook >; + using sh = bi::set_member_hook>; struct event { typename TC::time_point t; - uint64_t id; + std::uint64_t id; std::function f; sh schedule_link; sh event_link; event() : t(TC::time_point::min()), id(0) {} - event(uint64_t _id) : t(TC::time_point::min()), id(_id) {} - event(typename TC::time_point _t, uint64_t _id, + event(std::uint64_t _id) : t(TC::time_point::min()), id(_id) {} + event(typename TC::time_point _t, std::uint64_t _id, std::function&& _f) : t(_t), id(_id), f(_f) {} - event(typename TC::time_point _t, uint64_t _id, + event(typename TC::time_point _t, std::uint64_t _id, const std::function& _f) : t(_t), id(_id), f(_f) {} bool operator <(const event& e) { return t == e.t ? id < e.id : t < e.t; @@ -86,17 +79,18 @@ class timer { } }; - using schedule_type = set, - constant_time_size, - compare >; + using schedule_type = bi::set, + bi::constant_time_size, + bi::compare>; schedule_type schedule; - using event_set_type = set, - constant_time_size, - compare >; + using event_set_type = bi::set, + bi::constant_time_size, + bi::compare>; event_set_type events; @@ -106,7 +100,7 @@ class timer { std::condition_variable cond; event* running{ nullptr }; - uint64_t next_id{ 0 }; + std::uint64_t next_id{ 0 }; bool suspended; std::thread thread; @@ -198,8 +192,8 @@ public: // Schedule an event in the relative future template - uint64_t add_event(typename TC::duration duration, - Callable&& f, Args&&... args) { + std::uint64_t add_event(typename TC::duration duration, + Callable&& f, Args&&... args) { typename TC::time_point when = TC::now(); when += duration; return add_event(when, @@ -209,12 +203,12 @@ public: // Schedule an event in the absolute future template - uint64_t add_event(typename TC::time_point when, - Callable&& f, Args&&... args) { + std::uint64_t add_event(typename TC::time_point when, + Callable&& f, Args&&... args) { std::lock_guard l(lock); event& e = *(new event( when, ++next_id, - std::forward >( + std::forward>( std::bind(std::forward(f), std::forward(args)...)))); auto i = schedule.insert(e); @@ -235,12 +229,12 @@ public: } // Adjust the timeout of a currently-scheduled event (relative) - bool adjust_event(uint64_t id, typename TC::duration duration) { + bool adjust_event(std::uint64_t id, typename TC::duration duration) { return adjust_event(id, TC::now() + duration); } // Adjust the timeout of a currently-scheduled event (absolute) - bool adjust_event(uint64_t id, typename TC::time_point when) { + bool adjust_event(std::uint64_t id, typename TC::time_point when) { std::lock_guard l(lock); event key(id); @@ -261,7 +255,7 @@ public: // Cancel an event. If the event has already come and gone (or you // never submitted it) you will receive false. Otherwise you will // receive true and it is guaranteed the event will not execute. - bool cancel_event(const uint64_t id) { + bool cancel_event(const std::uint64_t id) { std::lock_guard l(lock); event dummy(id); auto p = events.find(dummy); @@ -286,7 +280,7 @@ public: // // Returns an event id. If you had an event_id from the first // scheduling, replace it with this return value. - uint64_t reschedule_me(typename TC::duration duration) { + std::uint64_t reschedule_me(typename TC::duration duration) { return reschedule_me(TC::now() + duration); } @@ -299,12 +293,12 @@ public: // // Returns an event id. If you had an event_id from the first // scheduling, replace it with this return value. - uint64_t reschedule_me(typename TC::time_point when) { + std::uint64_t reschedule_me(typename TC::time_point when) { if (std::this_thread::get_id() != thread.get_id()) throw std::make_error_condition(std::errc::operation_not_permitted); std::lock_guard l(lock); running->t = when; - uint64_t id = ++next_id; + std::uint64_t id = ++next_id; running->id = id; schedule.insert(*running); events.insert(*running); @@ -328,9 +322,6 @@ public: } } }; // timer -}; // timer_detail - -using timer_detail::timer; -}; // ceph +} // namespace ceph #endif