[block] use an enum to designate a block as a super block

This commit is contained in:
Joe Thornber 2011-08-31 13:22:37 +01:00
parent 2973c64e00
commit dec79974b2
2 changed files with 13 additions and 8 deletions

11
block.h
View File

@ -63,6 +63,11 @@ namespace persistent_data {
void prepare(block &b) const {}
};
enum block_type {
BT_SUPERBLOCK,
BT_NORMAL
};
struct block {
typedef boost::shared_ptr<block> ptr;
@ -70,13 +75,13 @@ namespace persistent_data {
const_buffer &data,
unsigned &count,
unsigned &type_count,
bool is_superblock, // FIXME: make this an enum
block_type bt,
typename validator::ptr v)
: location_(location),
adjuster_(count),
type_adjuster_(type_count),
validator_(v),
is_superblock_(is_superblock) {
bt_(bt) {
::memcpy(data_, data, sizeof(data));
}
@ -85,7 +90,7 @@ namespace persistent_data {
count_adjuster type_adjuster_;
buffer data_;
typename validator::ptr validator_;
bool is_superblock_;
block_type bt_;
};
class read_ref {

View File

@ -77,7 +77,7 @@ block_manager<BlockSize>::read_lock(block_address location,
buffer buf;
read_buffer(location, buf);
typename block::ptr b(new block(location, buf, lock_count_, ordinary_count_, false, v),
typename block::ptr b(new block(location, buf, lock_count_, ordinary_count_, BT_NORMAL, v),
bind(&block_manager::read_release, this, _1));
register_lock(location, READ_LOCK);
return read_ref(b);
@ -100,7 +100,7 @@ block_manager<BlockSize>::write_lock(block_address location,
buffer buf;
read_buffer(location, buf);
typename block::ptr b(new block(location, buf, lock_count_, ordinary_count_, false, v),
typename block::ptr b(new block(location, buf, lock_count_, ordinary_count_, BT_NORMAL, v),
bind(&block_manager::write_release, this, _1));
register_lock(location, WRITE_LOCK);
return write_ref(b);
@ -115,7 +115,7 @@ block_manager<BlockSize>::write_lock_zero(block_address location,
buffer buf;
zero_buffer(buf);
typename block::ptr b(new block(location, buf, lock_count_, ordinary_count_, false, v),
typename block::ptr b(new block(location, buf, lock_count_, ordinary_count_, BT_NORMAL, v),
bind(&block_manager::write_release, this, _1));
register_lock(location, WRITE_LOCK);
return write_ref(b);
@ -133,7 +133,7 @@ block_manager<BlockSize>::superblock(block_address location,
buffer buf;
read_buffer(location, buf);
typename block::ptr b(new block(location, buf, lock_count_, superblock_count_, true, v),
typename block::ptr b(new block(location, buf, lock_count_, superblock_count_, BT_SUPERBLOCK, v),
bind(&block_manager::write_release, this, _1));
register_lock(location, WRITE_LOCK);
return write_ref(b);
@ -225,7 +225,7 @@ template <uint32_t BlockSize>
void
block_manager<BlockSize>::write_release(block *b)
{
if (b->is_superblock_) {
if (b->bt_ == BT_SUPERBLOCK) {
if (lock_count_ != 1)
throw runtime_error("superblock isn't the last block");
}