[space-map] Make the version of inc/dec that take a count the only one.

This commit is contained in:
Joe Thornber 2020-05-26 09:12:45 +01:00
parent cc806a0daa
commit 50f8e792d3
6 changed files with 19 additions and 41 deletions

View File

@ -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) {

View File

@ -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_)

View File

@ -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_++;

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -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