Add superblock_lock method to lock_tracker.

This commit is contained in:
Joe Thornber 2013-01-07 15:30:51 +00:00
parent 2a427ca925
commit 26b97908bd
3 changed files with 23 additions and 2 deletions

View File

@ -325,7 +325,7 @@ typename block_manager<BlockSize>::write_ref
block_manager<BlockSize>::superblock(block_address location,
typename block_manager<BlockSize>::validator::ptr v)
{
tracker_.write_lock(location);
tracker_.superblock_lock(location);
try {
check(location);
@ -353,7 +353,7 @@ typename block_manager<BlockSize>::write_ref
block_manager<BlockSize>::superblock_zero(block_address location,
typename block_manager<BlockSize>::validator::ptr v)
{
tracker_.write_lock(location);
tracker_.superblock_lock(location);
try {
check(location);

View File

@ -59,6 +59,21 @@ lock_tracker::write_lock(uint64_t key)
locks_.insert(make_pair(key, -1));
}
void
lock_tracker::superblock_lock(uint64_t key)
{
if (superblock_)
throw runtime_error("superblock already held");
superblock_ = boost::optional<uint64_t>(key);
try {
write_lock(key);
} catch (...) {
superblock_ = boost::optional<uint64_t>();
}
}
void
lock_tracker::unlock(uint64_t key)
{
@ -72,6 +87,9 @@ lock_tracker::unlock(uint64_t key)
locks_.insert(make_pair(key, it->second - 1));
else
locks_.erase(key);
if (superblock_ && *superblock_ == key)
superblock_ = boost::optional<uint64_t>();
}
bool

View File

@ -20,6 +20,7 @@
#define LOCK_TRACKER_H
#include <boost/noncopyable.hpp>
#include <boost/optional.hpp>
#include <map>
#include <stdint.h>
@ -33,6 +34,7 @@ namespace persistent_data {
void read_lock(uint64_t key);
void write_lock(uint64_t key);
void superblock_lock(uint64_t key);
void unlock(uint64_t key);
private:
@ -45,6 +47,7 @@ namespace persistent_data {
// Positive for read lock, negative for write lock
LockMap locks_;
boost::optional<uint64_t> superblock_;
uint64_t low_;
uint64_t high_;