From: Mukund Sivaraman Date: Tue, 23 Oct 2012 04:06:26 +0000 (+0530) Subject: [2236] Don't use PTHREAD_MUTEX_ERRORCHECK in non-debug builds X-Git-Tag: trac2487_base~18^2~33^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2eaf01995b4c0d6c007afd51c94b8453cbb797ca;p=thirdparty%2Fkea.git [2236] Don't use PTHREAD_MUTEX_ERRORCHECK in non-debug builds Also disable tests in non-debug builds that depend on PTHREAD_MUTEX_ERRORCHECK. --- diff --git a/src/bin/auth/tests/auth_srv_unittest.cc b/src/bin/auth/tests/auth_srv_unittest.cc index 396b247491..cde4c8169b 100644 --- a/src/bin/auth/tests/auth_srv_unittest.cc +++ b/src/bin/auth/tests/auth_srv_unittest.cc @@ -1824,6 +1824,8 @@ TEST_F(AuthSrvTest, clientList) { EXPECT_FALSE(server.getDataSrcClientList(RRClass::CH())); } +#ifdef ENABLE_DEBUG + // We just test the mutex can be locked (exactly once). TEST_F(AuthSrvTest, mutex) { isc::util::thread::Mutex::Locker l1(server.getDataSrcClientListMutex()); @@ -1837,4 +1839,6 @@ TEST_F(AuthSrvTest, mutex) { }, isc::InvalidOperation); } +#endif // ENABLE_DEBUG + } diff --git a/src/lib/util/threads/sync.cc b/src/lib/util/threads/sync.cc index c2f4fed48c..ca467b63d4 100644 --- a/src/lib/util/threads/sync.cc +++ b/src/lib/util/threads/sync.cc @@ -76,12 +76,15 @@ Mutex::Mutex() : isc_throw(isc::InvalidOperation, std::strerror(result)); } Deinitializer deinitializer(attributes); + +#ifdef ENABLE_DEBUG // TODO: Distinguish if debug mode is enabled in compilation. - // If so, it should be PTHREAD_MUTEX_NORMAL or NULL result = pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_ERRORCHECK); if (result != 0) { isc_throw(isc::InvalidOperation, std::strerror(result)); } +#endif // ENABLE_DEBUG + auto_ptr impl(new Impl); result = pthread_mutex_init(&impl->mutex, &attributes); switch (result) { diff --git a/src/lib/util/threads/tests/condvar_unittest.cc b/src/lib/util/threads/tests/condvar_unittest.cc index 6cec0dc9b8..8b1fe5445e 100644 --- a/src/lib/util/threads/tests/condvar_unittest.cc +++ b/src/lib/util/threads/tests/condvar_unittest.cc @@ -149,15 +149,15 @@ TEST_F(CondVarTest, DISABLED_destroyWhileWait) { }, ""); } +#ifdef ENABLE_DEBUG + TEST_F(CondVarTest, badWait) { // In our implementation, wait() requires acquiring the lock beforehand. -#ifdef ENABLE_DEBUG EXPECT_THROW(condvar_.wait(mutex_), isc::InvalidOperation); -#else - EXPECT_THROW(condvar_.wait(mutex_), isc::BadValue); -#endif // ENABLE_DEBUG } +#endif // ENABLE_DEBUG + TEST_F(CondVarTest, emptySignal) { // It's okay to call signal when no one waits. EXPECT_NO_THROW(condvar_.signal()); diff --git a/src/lib/util/threads/tests/lock_unittest.cc b/src/lib/util/threads/tests/lock_unittest.cc index abd0f607d8..40af7eee6c 100644 --- a/src/lib/util/threads/tests/lock_unittest.cc +++ b/src/lib/util/threads/tests/lock_unittest.cc @@ -26,28 +26,28 @@ using namespace isc::util::thread; namespace { -// If we try to lock the debug mutex multiple times, it should throw. +#ifdef ENABLE_DEBUG + +// If we try to lock the debug mutex multiple times, it should +// throw. This test will complete properly only when pthread debugging +// facilities are enabled by configuring the code for debug build. TEST(MutexTest, lockMultiple) { // TODO: Once we support non-debug mutexes, disable the test if we compile // with them. Mutex mutex; -#ifdef ENABLE_DEBUG EXPECT_FALSE(mutex.locked()); // Debug-only build -#endif // ENABLE_DEBUG Mutex::Locker l1(mutex); -#ifdef ENABLE_DEBUG EXPECT_TRUE(mutex.locked()); // Debug-only build -#endif // ENABLE_DEBUG EXPECT_THROW({ Mutex::Locker l2(mutex); // Attempt to lock again. }, isc::InvalidOperation); -#ifdef ENABLE_DEBUG EXPECT_TRUE(mutex.locked()); // Debug-only build -#endif // ENABLE_DEBUG } +#endif // ENABLE_DEBUG + // Destroying a locked mutex is a bad idea as well #ifdef EXPECT_DEATH TEST(MutexTest, destroyLocked) {