]> git.ipfire.org Git - thirdparty/pdns.git/blobdiff - pdns/test-lock_hh.cc
Merge pull request #9070 from rgacogne/boost-173
[thirdparty/pdns.git] / pdns / test-lock_hh.cc
index bdd3697504c735a5c8425f10df709d774e2c641d..46e844c60aa20905b8ae4258d8c9a3ce201865c1 100644 (file)
@@ -11,26 +11,20 @@ using namespace boost;
 
 BOOST_AUTO_TEST_SUITE(test_lock_hh)
 
-static std::vector<std::unique_ptr<pthread_rwlock_t> > g_locks;
+static std::vector<ReadWriteLock> g_locks(1000);
 
 static void lthread()
 {
   std::vector<ReadLock> rlocks;
   for(auto& pp : g_locks)
-    rlocks.emplace_back(&*pp);
+    rlocks.emplace_back(pp);
 }
 
 BOOST_AUTO_TEST_CASE(test_pdns_lock)
 {
-  for(unsigned int n=0; n < 1000; ++n) {
-    auto p = make_unique<pthread_rwlock_t>();
-    pthread_rwlock_init(p.get(), 0);
-    g_locks.emplace_back(std::move(p));
-  }
-
   std::vector<ReadLock> rlocks;
   for(auto& pp : g_locks)
-    rlocks.emplace_back(&*pp);
+    rlocks.emplace_back(pp);
 
   std::thread thr(lthread);
   thr.join();
@@ -38,13 +32,13 @@ BOOST_AUTO_TEST_CASE(test_pdns_lock)
 
   std::vector<WriteLock> wlocks;
   for(auto& pp : g_locks)
-    wlocks.emplace_back(&*pp);
+    wlocks.emplace_back(pp);
 
   // on macOS, this TryReadLock throws (EDEADLK) instead of simply failing
   // so we catch the exception and consider that success for this test
   bool gotit = false;
   try {
-    TryReadLock trl(&*g_locks[0]);
+    TryReadLock trl(g_locks.at(0));
     gotit = trl.gotIt();
   }
   catch(const PDNSException &e) {
@@ -55,13 +49,11 @@ BOOST_AUTO_TEST_CASE(test_pdns_lock)
   wlocks.clear();
 
   {
-    TryReadLock trl2(&*g_locks[0]);
+    TryReadLock trl2(g_locks.at(0));
     BOOST_CHECK(trl2.gotIt());
   }
 
-  for(auto& pp : g_locks) {
-    pthread_rwlock_destroy(pp.get());
-  }
+  g_locks.clear();
 }
 
 BOOST_AUTO_TEST_SUITE_END()