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 <bhalevy@scylladb.com>
This commit is contained in:
Benny Halevy
2021-02-08 18:55:08 +02:00
parent a12c9638b6
commit d752ea7e91
2 changed files with 3 additions and 3 deletions

View File

@@ -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<std::chrono::seconds>::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;

View File

@@ -101,7 +101,7 @@ private:
struct inactive_read : public bi::list_base_hook<bi::link_mode<bi::auto_unlink>> {
flat_mutation_reader reader;
eviction_notify_handler notify_handler;
std::optional<timer<lowres_clock>> ttl_timer;
timer<lowres_clock> ttl_timer;
explicit inactive_read(flat_mutation_reader reader_) noexcept
: reader(std::move(reader_))