add sm_decrementer

This commit is contained in:
Joe Thornber 2011-11-08 11:08:16 +00:00
parent dedf5edecc
commit 61a6db080d
3 changed files with 72 additions and 1 deletions

View File

@ -13,6 +13,7 @@ SOURCE=\
metadata_dumper.cc \ metadata_dumper.cc \
metadata_disk_structures.cc \ metadata_disk_structures.cc \
restore_emitter.cc \ restore_emitter.cc \
space_map.cc \
space_map_disk.cc \ space_map_disk.cc \
thin_pool.cc \ thin_pool.cc \
transaction_manager.cc \ transaction_manager.cc \
@ -25,7 +26,7 @@ PROGRAM_SOURCE=\
OBJECTS=$(subst .cc,.o,$(SOURCE)) OBJECTS=$(subst .cc,.o,$(SOURCE))
TOP_DIR:=$(PWD) 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) #CPPFLAGS=-Wall -std=c++0x -g -I$(TOP_DIR)
LIBS=-lstdc++ -lboost_program_options -lexpat LIBS=-lstdc++ -lboost_program_options -lexpat

23
space_map.cc Normal file
View 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;
}
//----------------------------------------------------------------

View File

@ -48,6 +48,53 @@ namespace persistent_data {
virtual size_t root_size() = 0; virtual size_t root_size() = 0;
virtual void copy_root(void *dest, size_t len) = 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_;
};
} }
//---------------------------------------------------------------- //----------------------------------------------------------------