From b63a921d44f71be29f699fc59f2177c22a4e4a15 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Mon, 7 Jan 2013 15:57:19 +0000 Subject: [PATCH] make lock_tracker throw if the superblock is unlocked while other locks are still held. --- persistent-data/lock_tracker.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/persistent-data/lock_tracker.cc b/persistent-data/lock_tracker.cc index b21aa54..eac9752 100644 --- a/persistent-data/lock_tracker.cc +++ b/persistent-data/lock_tracker.cc @@ -36,12 +36,12 @@ lock_tracker::read_lock(uint64_t key) { check_key(key); - LockMap::const_iterator it = locks_.find(key); + LockMap::iterator it = locks_.find(key); if (found(it)) { if (it->second < 0) throw runtime_error("already write locked"); - locks_.insert(make_pair(key, it->second + 1)); + it->second++; } else locks_.insert(make_pair(key, 1)); @@ -83,13 +83,18 @@ lock_tracker::unlock(uint64_t key) if (!found(it)) throw runtime_error("not locked"); + if (superblock_ && *superblock_ == key) { + if (locks_.size() > 1) + throw runtime_error("superblock unlocked while other locks still held"); + + superblock_ = boost::optional(); + } + if (it->second > 1) locks_.insert(make_pair(key, it->second - 1)); else locks_.erase(key); - if (superblock_ && *superblock_ == key) - superblock_ = boost::optional(); } bool