Add superblock_lock method to lock_tracker.
This commit is contained in:
parent
2a427ca925
commit
26b97908bd
@ -325,7 +325,7 @@ typename block_manager<BlockSize>::write_ref
|
|||||||
block_manager<BlockSize>::superblock(block_address location,
|
block_manager<BlockSize>::superblock(block_address location,
|
||||||
typename block_manager<BlockSize>::validator::ptr v)
|
typename block_manager<BlockSize>::validator::ptr v)
|
||||||
{
|
{
|
||||||
tracker_.write_lock(location);
|
tracker_.superblock_lock(location);
|
||||||
try {
|
try {
|
||||||
check(location);
|
check(location);
|
||||||
|
|
||||||
@ -353,7 +353,7 @@ typename block_manager<BlockSize>::write_ref
|
|||||||
block_manager<BlockSize>::superblock_zero(block_address location,
|
block_manager<BlockSize>::superblock_zero(block_address location,
|
||||||
typename block_manager<BlockSize>::validator::ptr v)
|
typename block_manager<BlockSize>::validator::ptr v)
|
||||||
{
|
{
|
||||||
tracker_.write_lock(location);
|
tracker_.superblock_lock(location);
|
||||||
try {
|
try {
|
||||||
check(location);
|
check(location);
|
||||||
|
|
||||||
|
@ -59,6 +59,21 @@ lock_tracker::write_lock(uint64_t key)
|
|||||||
locks_.insert(make_pair(key, -1));
|
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
|
void
|
||||||
lock_tracker::unlock(uint64_t key)
|
lock_tracker::unlock(uint64_t key)
|
||||||
{
|
{
|
||||||
@ -72,6 +87,9 @@ lock_tracker::unlock(uint64_t key)
|
|||||||
locks_.insert(make_pair(key, it->second - 1));
|
locks_.insert(make_pair(key, it->second - 1));
|
||||||
else
|
else
|
||||||
locks_.erase(key);
|
locks_.erase(key);
|
||||||
|
|
||||||
|
if (superblock_ && *superblock_ == key)
|
||||||
|
superblock_ = boost::optional<uint64_t>();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#define LOCK_TRACKER_H
|
#define LOCK_TRACKER_H
|
||||||
|
|
||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ namespace persistent_data {
|
|||||||
|
|
||||||
void read_lock(uint64_t key);
|
void read_lock(uint64_t key);
|
||||||
void write_lock(uint64_t key);
|
void write_lock(uint64_t key);
|
||||||
|
void superblock_lock(uint64_t key);
|
||||||
void unlock(uint64_t key);
|
void unlock(uint64_t key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -45,6 +47,7 @@ namespace persistent_data {
|
|||||||
|
|
||||||
// Positive for read lock, negative for write lock
|
// Positive for read lock, negative for write lock
|
||||||
LockMap locks_;
|
LockMap locks_;
|
||||||
|
boost::optional<uint64_t> superblock_;
|
||||||
|
|
||||||
uint64_t low_;
|
uint64_t low_;
|
||||||
uint64_t high_;
|
uint64_t high_;
|
||||||
|
Loading…
Reference in New Issue
Block a user