From d752ea7e91905568286b964fdbc76b8efbc8aa76 Mon Sep 17 00:00:00 2001 From: Benny Halevy Date: Mon, 8 Feb 2021 18:55:08 +0200 Subject: [PATCH] reader_concurrency_semaphore: inactive_read: make ttl_timer non-optional By default it will be unarmed and with no callback so there's no need to wrap it in a std::optional. This saves an allocation and another potential error case. Signed-off-by: Benny Halevy --- reader_concurrency_semaphore.cc | 4 ++-- reader_concurrency_semaphore.hh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/reader_concurrency_semaphore.cc b/reader_concurrency_semaphore.cc index ea080c7114..88e7a7433b 100644 --- a/reader_concurrency_semaphore.cc +++ b/reader_concurrency_semaphore.cc @@ -390,10 +390,10 @@ reader_concurrency_semaphore::inactive_read_handle reader_concurrency_semaphore: auto& ir = *irp; ir.notify_handler = std::move(notify_handler); if (ttl != std::chrono::duration_values::max()) { - ir.ttl_timer.emplace([this, &ir] { + ir.ttl_timer.set_callback([this, &ir] { evict(ir, evict_reason::time); }); - ir.ttl_timer->arm(lowres_clock::now() + ttl); + ir.ttl_timer.arm(lowres_clock::now() + ttl); } _inactive_reads.push_back(ir); ++_stats.inactive_reads; diff --git a/reader_concurrency_semaphore.hh b/reader_concurrency_semaphore.hh index 3e1f9d72ce..bc82bcc71c 100644 --- a/reader_concurrency_semaphore.hh +++ b/reader_concurrency_semaphore.hh @@ -101,7 +101,7 @@ private: struct inactive_read : public bi::list_base_hook> { flat_mutation_reader reader; eviction_notify_handler notify_handler; - std::optional> ttl_timer; + timer ttl_timer; explicit inactive_read(flat_mutation_reader reader_) noexcept : reader(std::move(reader_))