From 50f8e792d30feb2b8dd4f0e28b423886101041ed Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 26 May 2020 09:12:45 +0100 Subject: [PATCH] [space-map] Make the version of inc/dec that take a count the only one. --- persistent-data/space-maps/careful_alloc.cc | 10 +++++----- persistent-data/space-maps/core.h | 8 ++++---- persistent-data/space-maps/disk.cc | 11 ----------- persistent-data/space-maps/noop.h | 4 ++-- persistent-data/space-maps/recursive.cc | 12 ++++++------ persistent-data/space_map.h | 15 ++------------- 6 files changed, 19 insertions(+), 41 deletions(-) diff --git a/persistent-data/space-maps/careful_alloc.cc b/persistent-data/space-maps/careful_alloc.cc index 9991430..4609883 100644 --- a/persistent-data/space-maps/careful_alloc.cc +++ b/persistent-data/space-maps/careful_alloc.cc @@ -58,18 +58,18 @@ namespace { clear_freed(); } - virtual void inc(block_address b) { + virtual void inc(block_address b, ref_t count) override { if (was_freed(b)) throw runtime_error("inc of block freed within current transaction"); - sm_->inc(b); + sm_->inc(b, count); } - virtual void dec(block_address b) { - if (sm_->get_count(b) == 1) + virtual void dec(block_address b, ref_t count) override { + if (sm_->get_count(b) == count) mark_freed(b); - sm_->dec(b); + sm_->dec(b, count); } virtual maybe_block find_free(span_iterator &it) { diff --git a/persistent-data/space-maps/core.h b/persistent-data/space-maps/core.h index e2af33a..73b555c 100644 --- a/persistent-data/space-maps/core.h +++ b/persistent-data/space-maps/core.h @@ -63,15 +63,15 @@ namespace persistent_data { void commit() { } - void inc(block_address b) { + void inc(block_address b, ref_t count) override { if (counts_[b] == 0) nr_free_--; - counts_[b]++; + counts_[b] += count; } - void dec(block_address b) { - counts_[b]--; + void dec(block_address b, ref_t count) override { + counts_[b] -= count; if (counts_[b] == 0) { if (b < search_start_) diff --git a/persistent-data/space-maps/disk.cc b/persistent-data/space-maps/disk.cc index df3ab5b..51a4b78 100644 --- a/persistent-data/space-maps/disk.cc +++ b/persistent-data/space-maps/disk.cc @@ -383,17 +383,6 @@ namespace { indexes_->commit_ies(); } - void inc(block_address b) override { - if (b == search_start_) - search_start_++; - - modify_count(b, [](ref_t c) {return c + 1;}); - } - - void dec(block_address b) override { - modify_count(b, [](ref_t c) {return c - 1;}); - } - void inc(block_address b, uint32_t count) override { if (b == search_start_) search_start_++; diff --git a/persistent-data/space-maps/noop.h b/persistent-data/space-maps/noop.h index fdd58a4..925936c 100644 --- a/persistent-data/space-maps/noop.h +++ b/persistent-data/space-maps/noop.h @@ -51,11 +51,11 @@ namespace persistent_data { fail(); } - void inc(block_address b) { + void inc(block_address b, ref_t count) { fail(); } - void dec(block_address b) { + void dec(block_address b, ref_t count) { fail(); } diff --git a/persistent-data/space-maps/recursive.cc b/persistent-data/space-maps/recursive.cc index d904b8c..634c530 100644 --- a/persistent-data/space-maps/recursive.cc +++ b/persistent-data/space-maps/recursive.cc @@ -106,21 +106,21 @@ namespace { sm_->commit(); } - virtual void inc(block_address b) { + virtual void inc(block_address b, ref_t count) override { if (depth_) - add_op(b, block_op(INC, 1)); + add_op(b, block_op(INC, count)); else { recursing_lock lock(*this); - return sm_->inc(b); + return sm_->inc(b, count); } } - virtual void dec(block_address b) { + virtual void dec(block_address b, ref_t count) override { if (depth_) - add_op(b, block_op(INC, -1)); + add_op(b, block_op(INC, -count)); else { recursing_lock lock(*this); - return sm_->dec(b); + return sm_->dec(b, count); } } diff --git a/persistent-data/space_map.h b/persistent-data/space_map.h index eacc558..930626a 100644 --- a/persistent-data/space_map.h +++ b/persistent-data/space_map.h @@ -45,19 +45,8 @@ namespace persistent_data { virtual void set_count(block_address b, ref_t c) = 0; virtual void commit() = 0; - virtual void inc(block_address b) = 0; - virtual void dec(block_address b) = 0; - - // slow default implementation - virtual void inc(block_address b, uint32_t count) { - for (uint32_t i = 0; i < count; i++) - inc(b); - } - - virtual void dec(block_address b, uint32_t count) { - for (uint32_t i = 0; i < count; i++) - dec(b); - } + virtual void inc(block_address b, ref_t count = 1) = 0; + virtual void dec(block_address b, ref_t count = 1) = 0; // FIXME: change these to return an optional, failure is // not that rare if we're restricting the area that's