diff --git a/apps/memcached/memcache.cc b/apps/memcached/memcache.cc index a82c602131..5a70d04a47 100644 --- a/apps/memcached/memcache.cc +++ b/apps/memcached/memcache.cc @@ -290,6 +290,11 @@ public: } } + // needed by timer_set + bool cancel() { + return false; + } + friend bool operator==(const item_type &a, const item_type &b) { return a._key == b._key; } diff --git a/core/reactor.hh b/core/reactor.hh index a42a23568d..fcfda49db9 100644 --- a/core/reactor.hh +++ b/core/reactor.hh @@ -645,6 +645,16 @@ public: static boost::program_options::options_description get_options_description(); reactor(); reactor(const reactor&) = delete; + ~reactor() { + auto eraser = [](auto& list) { + while (!list.empty()) { + auto timer = *list.begin(); + timer.cancel(); + } + }; + eraser(_expired_timers); + eraser(_expired_lowres_timers); + } void operator=(const reactor&) = delete; void configure(boost::program_options::variables_map config); diff --git a/core/timer-set.hh b/core/timer-set.hh index d07a292b4c..c5edb73bc3 100644 --- a/core/timer-set.hh +++ b/core/timer-set.hh @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "bitset-iter.hh" @@ -48,7 +49,7 @@ private: // The last bucket is reserved for active timers with timeout <= _last. static constexpr int n_buckets = timestamp_bits + 1; - timer_list_t _buckets[n_buckets]; + std::array _buckets; timestamp_t _last; timestamp_t _next; @@ -92,6 +93,15 @@ public: { } + ~timer_set() { + for (auto&& list : _buckets) { + while (!list.empty()) { + auto& timer = *list.begin(); + timer.cancel(); + } + } + } + /** * Adds timer to the active set. *