add sm_decrementer
This commit is contained in:
parent
dedf5edecc
commit
61a6db080d
3
Makefile
3
Makefile
@ -13,6 +13,7 @@ SOURCE=\
|
||||
metadata_dumper.cc \
|
||||
metadata_disk_structures.cc \
|
||||
restore_emitter.cc \
|
||||
space_map.cc \
|
||||
space_map_disk.cc \
|
||||
thin_pool.cc \
|
||||
transaction_manager.cc \
|
||||
@ -25,7 +26,7 @@ PROGRAM_SOURCE=\
|
||||
|
||||
OBJECTS=$(subst .cc,.o,$(SOURCE))
|
||||
TOP_DIR:=$(PWD)
|
||||
CPPFLAGS=-Wall -g -I$(TOP_DIR) -O8
|
||||
CPPFLAGS=-Wall -g -I$(TOP_DIR)
|
||||
#CPPFLAGS=-Wall -std=c++0x -g -I$(TOP_DIR)
|
||||
LIBS=-lstdc++ -lboost_program_options -lexpat
|
||||
|
||||
|
23
space_map.cc
Normal file
23
space_map.cc
Normal file
@ -0,0 +1,23 @@
|
||||
#include "space_map.h"
|
||||
|
||||
using namespace persistent_data;
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
sm_decrementer::sm_decrementer(space_map::ptr sm, block_address b)
|
||||
: sm_(sm),
|
||||
b_(b),
|
||||
released_(false) {
|
||||
}
|
||||
|
||||
sm_decrementer::~sm_decrementer() {
|
||||
if (!released_)
|
||||
sm_->dec(b_);
|
||||
}
|
||||
|
||||
void
|
||||
sm_decrementer::dont_bother() {
|
||||
released_ = true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
47
space_map.h
47
space_map.h
@ -48,6 +48,53 @@ namespace persistent_data {
|
||||
virtual size_t root_size() = 0;
|
||||
virtual void copy_root(void *dest, size_t len) = 0;
|
||||
};
|
||||
|
||||
class sm_adjust {
|
||||
public:
|
||||
sm_adjust(space_map::ptr sm, block_address b, int delta)
|
||||
: sm_(sm),
|
||||
b_(b),
|
||||
delta_(delta) {
|
||||
|
||||
adjust_count(delta_);
|
||||
}
|
||||
|
||||
~sm_adjust() {
|
||||
adjust_count(-delta_);
|
||||
}
|
||||
|
||||
void release() {
|
||||
delta_ = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
void adjust_count(int delta) {
|
||||
if (delta == 1)
|
||||
sm_->inc(b_);
|
||||
|
||||
else if (delta == -1)
|
||||
sm_->dec(b_);
|
||||
|
||||
else
|
||||
sm_->set_count(b_, sm_->get_count(b_) + delta);
|
||||
}
|
||||
|
||||
space_map::ptr sm_;
|
||||
block_address b_;
|
||||
int delta_;
|
||||
};
|
||||
|
||||
class sm_decrementer {
|
||||
public:
|
||||
sm_decrementer(space_map::ptr sm, block_address b);
|
||||
~sm_decrementer();
|
||||
void dont_bother();
|
||||
|
||||
private:
|
||||
space_map::ptr sm_;
|
||||
block_address b_;
|
||||
bool released_;
|
||||
};
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user