]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/thread/test/sync/conditions/condition_variable/wait_for_pass.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / thread / test / sync / conditions / condition_variable / wait_for_pass.cpp
index f9b4a8351b2790ec1bc260ba3a2c9437e9833b59..bdabf79e7115e1386aaece83ea9385af0e610d3c 100644 (file)
@@ -22,6 +22,7 @@
 #include <boost/thread/mutex.hpp>
 #include <boost/thread/thread.hpp>
 #include <boost/detail/lightweight_test.hpp>
+#include <cassert>
 
 #if defined BOOST_THREAD_USES_CHRONO
 
@@ -35,33 +36,39 @@ int runs = 0;
 
 void f()
 {
-  typedef boost::chrono::steady_clock Clock;
-  typedef boost::chrono::milliseconds milliseconds;
-  boost::unique_lock<boost::mutex> lk(mut);
-  BOOST_TEST(test2 == 0);
-  test1 = 1;
-  cv.notify_one();
-  Clock::time_point t0 = Clock::now();
-  int count=0;
-  while (test2 == 0 && cv.wait_for(lk, milliseconds(250)) == boost::cv_status::no_timeout)
-    count++;
-  Clock::time_point t1 = Clock::now();
-  if (runs == 0)
-  {
-    BOOST_TEST(t1 - t0 < milliseconds(250));
-    BOOST_TEST(test2 != 0);
-  }
-  else
-  {
-    // This test is spurious as it depends on the time the thread system switches the threads
-    BOOST_TEST(t1 - t0 - milliseconds(250) < milliseconds(count*250+5+1000));
-    BOOST_TEST(test2 == 0);
+  try {
+    typedef boost::chrono::steady_clock Clock;
+    typedef boost::chrono::milliseconds milliseconds;
+    boost::unique_lock<boost::mutex> lk(mut);
+    assert(test2 == 0);
+    test1 = 1;
+    cv.notify_one();
+    Clock::time_point t0 = Clock::now();
+    int count=0;
+    while (test2 == 0 && cv.wait_for(lk, milliseconds(250)) == boost::cv_status::no_timeout)
+      count++;
+    Clock::time_point t1 = Clock::now();
+    if (runs == 0)
+    {
+      assert(t1 - t0 < milliseconds(250));
+      assert(test2 != 0);
+    }
+    else
+    {
+      // This test is spurious as it depends on the time the thread system switches the threads
+      assert(t1 - t0 - milliseconds(250) < milliseconds(count*250+5+1000));
+      assert(test2 == 0);
+    }
+    ++runs;
+  } catch(...) {
+    std::cout << "ERROR exception" << __LINE__ << std::endl;
+    assert(false);
   }
-  ++runs;
 }
 
 int main()
 {
+  try
   {
     boost::unique_lock<boost::mutex> lk(mut);
     boost::thread t(f);
@@ -73,9 +80,13 @@ int main()
     lk.unlock();
     cv.notify_one();
     t.join();
+  } catch(...) {
+      std::cout << "ERROR exception" << __LINE__ << std::endl;
+      BOOST_TEST(false);
   }
   test1 = 0;
   test2 = 0;
+  try
   {
     boost::unique_lock<boost::mutex> lk(mut);
     boost::thread t(f);
@@ -85,8 +96,10 @@ int main()
     BOOST_TEST(test1 != 0);
     lk.unlock();
     t.join();
+  } catch(...) {
+      BOOST_TEST(false);
+      std::cout << "ERROR exception" << __LINE__ << std::endl;
   }
-
   return boost::report_errors();
 }
 #else