Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / thread / test / test_once.cpp
index 340bef7..35eaa10 100644 (file)
@@ -3,11 +3,17 @@
 // accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
+#define BOOST_THREAD_VERSION 2
+#define BOOST_THREAD_PROVIDES_INTERRUPTIONS
+
 #include <boost/test/unit_test.hpp>
 #include <boost/thread/thread.hpp>
 #include <boost/thread/mutex.hpp>
 #include <boost/thread/once.hpp>
 
+#define LOG \
+  if (false) {} else std::cout << std::endl << __FILE__ << "[" << __LINE__ << "]"
+
 boost::once_flag flag=BOOST_ONCE_INIT;
 int var_to_init=0;
 boost::mutex m;
@@ -15,7 +21,7 @@ boost::mutex m;
 void initialize_variable()
 {
     // ensure that if multiple threads get in here, they are serialized, so we can see the effect
-    boost::mutex::scoped_lock lock(m);
+    boost::unique_lock<boost::mutex> lock(m);
     ++var_to_init;
 }
 
@@ -33,12 +39,14 @@ void call_once_thread()
             break;
         }
     }
-    boost::mutex::scoped_lock lock(m);
+    boost::unique_lock<boost::mutex> lock(m);
     BOOST_CHECK_EQUAL(my_once_value, 1);
 }
 
 void test_call_once()
 {
+  LOG;
+
     unsigned const num_threads=20;
     boost::thread_group group;
 
@@ -68,10 +76,10 @@ struct increment_value
     explicit increment_value(int* value_):
         value(value_)
     {}
-    
+
     void operator()() const
     {
-        boost::mutex::scoped_lock lock(m);
+        boost::unique_lock<boost::mutex> lock(m);
         ++(*value);
     }
 };
@@ -90,12 +98,14 @@ void call_once_with_functor()
             break;
         }
     }
-    boost::mutex::scoped_lock lock(m);
+    boost::unique_lock<boost::mutex> lock(m);
     BOOST_CHECK_EQUAL(my_once_value, 1);
 }
 
 void test_call_once_arbitrary_functor()
 {
+  LOG;
+
     unsigned const num_threads=20;
     boost::thread_group group;
 
@@ -124,10 +134,10 @@ struct throw_before_third_pass
     {};
 
     static unsigned pass_counter;
-    
+
     void operator()() const
     {
-        boost::mutex::scoped_lock lock(m);
+        boost::unique_lock<boost::mutex> lock(m);
         ++pass_counter;
         if(pass_counter<3)
         {
@@ -148,13 +158,14 @@ void call_once_with_exception()
     }
     catch(throw_before_third_pass::my_exception)
     {
-        boost::mutex::scoped_lock lock(m);
+        boost::unique_lock<boost::mutex> lock(m);
         ++exception_counter;
     }
 }
 
 void test_call_once_retried_on_exception()
 {
+  LOG;
     unsigned const num_threads=20;
     boost::thread_group group;
 
@@ -189,3 +200,5 @@ boost::unit_test::test_suite* init_unit_test_suite(int, char*[])
 
     return test;
 }
+
+