Browse Source

[2236] Don't use PTHREAD_MUTEX_ERRORCHECK in non-debug builds

Also disable tests in non-debug builds that depend on
PTHREAD_MUTEX_ERRORCHECK.
Mukund Sivaraman 12 years ago
parent
commit
2eaf01995b

+ 4 - 0
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
+
 }

+ 4 - 1
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> impl(new Impl);
     result = pthread_mutex_init(&impl->mutex, &attributes);
     switch (result) {

+ 4 - 4
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());

+ 7 - 7
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) {