[block, lock_checker] add an is_locked() method for use in unit tests.

This commit is contained in:
Joe Thornber 2013-04-29 12:31:30 +01:00
parent a0f53f47aa
commit a7c0b0c39b
4 changed files with 21 additions and 0 deletions

View File

@ -198,6 +198,11 @@ namespace persistent_data {
void flush() const;
// This is just for unit tests, don't call in application
// code.
bool is_locked(block_address b) const;
private:
void check(block_address b) const;
void write_block(typename block::ptr b) const;

View File

@ -527,4 +527,11 @@ block_manager<BlockSize>::flush() const
boost::bind(&block_manager<BlockSize>::write_block, this, _1));
}
template <uint32_t BlockSize>
bool
block_manager<BlockSize>::is_locked(block_address b) const
{
return tracker_.is_locked(b);
}
//----------------------------------------------------------------

View File

@ -116,5 +116,12 @@ lock_tracker::check_key(uint64_t key) const
throw runtime_error("invalid key");
}
bool
lock_tracker::is_locked(uint64_t key) const
{
check_key(key);
return found(locks_.find(key));
}
//----------------------------------------------------------------

View File

@ -37,6 +37,8 @@ namespace persistent_data {
void superblock_lock(uint64_t key);
void unlock(uint64_t key);
bool is_locked(uint64_t key) const;
private:
typedef std::map<uint64_t, int> LockMap;