private:
Mutex* mutex_;
};
+ /// \brief If the mutex is currently locked
+ ///
+ /// This is debug aiding method only. And it might be unavailable in
+ /// non-debug build (because keeping the state might be needlesly
+ /// slow).
+ ///
+ /// \todo Disable in non-debug build
+ bool locked() const;
private:
friend class Locker;
struct Impl;
// Test a recursive mutex can be locked multiple times
TEST(MutexTest, recursiveLockMultiple) {
Mutex mutex(true);
+ EXPECT_FALSE(mutex.locked()); // Debug-only build
Mutex::Locker l1(mutex);
+ EXPECT_TRUE(mutex.locked()); // Debug-only build
Mutex::Locker l2(mutex);
Mutex::Locker l3(mutex);
Mutex::Locker l4(mutex);
// TODO: Once we support non-debug mutexes, disable the test if we compile
// with them.
Mutex mutex;
+ EXPECT_FALSE(mutex.locked()); // Debug-only build
Mutex::Locker l1(mutex);
+ EXPECT_TRUE(mutex.locked()); // Debug-only build
EXPECT_THROW({
Mutex::Locker l2(mutex); // Attempt to lock again.
}, isc::InvalidOperation);
+ EXPECT_TRUE(mutex.locked()); // Debug-only build
}
// Destroying a locked mutex is a bad idea as well