Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81753 - in trunk: boost/thread boost/thread/v2 libs/thread/test libs/thread/test/sync/mutual_exclusion/locks/lock_guard libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock libs/thread/test/sync/mutual_exclusion/locks/strict_lock libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs
From: vicente.botet_at_[hidden]
Date: 2012-12-07 02:48:40


Author: viboes
Date: 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
New Revision: 81753
URL: http://svn.boost.org/trac/boost/changeset/81753

Log:
Thread: Added tests for strict_lock, nested_strict_lock
Added:
   trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/copy_assign_fail.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/copy_ctor_fail.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/default_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/make_nested_strict_lock_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/owns_lock_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/types_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/copy_assign_fail.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/copy_ctor_fail.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/default_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/make_strict_lock_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/owns_lock_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/types_pass.cpp (contents, props changed)
Text files modified:
   trunk/boost/thread/lock_concepts.hpp | 3 ++-
   trunk/boost/thread/strict_lock.hpp | 2 +-
   trunk/boost/thread/synchronized_value.hpp | 20 ++++++++++++++++----
   trunk/boost/thread/v2/thread.hpp | 4 ++--
   trunk/libs/thread/test/Jamfile.v2 | 23 +++++++++++++++++++++++
   trunk/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/make_lock_guard_pass.cpp | 4 +---
   trunk/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs/owns_lock_pass.cpp | 3 ++-
   7 files changed, 47 insertions(+), 12 deletions(-)

Modified: trunk/boost/thread/lock_concepts.hpp
==============================================================================
--- trunk/boost/thread/lock_concepts.hpp (original)
+++ trunk/boost/thread/lock_concepts.hpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -14,6 +14,7 @@
 
 #include <boost/chrono/chrono.hpp>
 #include <boost/concept_check.hpp>
+#include <boost/static_assert.hpp>
 
 namespace boost
 {
@@ -174,7 +175,7 @@
   {
     typedef typename Lk::mutex_type mutex_type;
     BOOST_CONCEPT_ASSERT(( BasicLockable<mutex_type> ));
- BOOST_STATIC_ASSERT(( is_strict_lock<Lk>::value));
+ BOOST_STATIC_ASSERT(( is_strict_lock<Lk>::value ));
 
     BOOST_CONCEPT_USAGE( StrictLock)
     {

Modified: trunk/boost/thread/strict_lock.hpp
==============================================================================
--- trunk/boost/thread/strict_lock.hpp (original)
+++ trunk/boost/thread/strict_lock.hpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -8,12 +8,12 @@
 
 #include <boost/thread/detail/delete.hpp>
 #include <boost/thread/lock_options.hpp>
-//#include <boost/thread/is_locked_by_this_thread.hpp>
 #include <boost/thread/lock_traits.hpp>
 #include <boost/thread/lockable_traits.hpp>
 #include <boost/thread/lockable_concepts.hpp>
 #include <boost/thread/lock_concepts.hpp>
 #include <boost/thread/exceptions.hpp>
+#include <boost/throw_exception.hpp>
 
 #include <boost/config/abi_prefix.hpp>
 

Modified: trunk/boost/thread/synchronized_value.hpp
==============================================================================
--- trunk/boost/thread/synchronized_value.hpp (original)
+++ trunk/boost/thread/synchronized_value.hpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -59,7 +59,7 @@
     /**
      * Move Constructor from movable value.
      *
- * Requires: T is CopyConstructible
+ * Requires: T is Movable
      */
     synchronized_value(BOOST_THREAD_RV_REF(T) other)
     : value_(boost::move(other))
@@ -303,7 +303,7 @@
     struct unique_synchronizer : unique_lock<lockable_type>
     {
     private:
- friend class synchronized_value;
+ //friend class synchronized_value;
       typedef unique_lock<lockable_type> base_type;
 
       T& value_;
@@ -315,6 +315,18 @@
       : base_type(outer.mtx_), value_(outer.value_)
       {
       }
+ unique_synchronizer(synchronized_value& outer, adopt_lock_t)
+ : base_type(outer.mtx_, adopt_lock), value_(outer.value_)
+ {
+ }
+ unique_synchronizer(synchronized_value& outer, defer_lock_t)
+ : base_type(outer.mtx_, defer_lock), value_(outer.value_)
+ {
+ }
+ unique_synchronizer(synchronized_value& outer, try_to_lock_t)
+ : base_type(outer.mtx_, try_to_lock), value_(outer.value_)
+ {
+ }
       unique_synchronizer(BOOST_THREAD_RV_REF(unique_synchronizer) other)
       : base_type(boost::move(other)),value_(BOOST_THREAD_RV(other).value_)
       {
@@ -335,9 +347,9 @@
       const T* operator->() const
       {
         if (this->owns_lock())
- return &value_;
+ return &value_;
         else
- return 0;
+ return 0;
       }
 
       T& operator*()

Modified: trunk/boost/thread/v2/thread.hpp
==============================================================================
--- trunk/boost/thread/v2/thread.hpp (original)
+++ trunk/boost/thread/v2/thread.hpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -40,7 +40,7 @@
       using namespace chrono;
       if (d > duration<Rep, Period>::zero())
       {
- duration<long double> Max = nanoseconds::max();
+ duration<long double> Max = nanoseconds::max BOOST_PREVENT_MACRO_SUBSTITUTION ();
           nanoseconds ns;
           if (d < Max)
           {
@@ -49,7 +49,7 @@
                   ++ns;
           }
           else
- ns = nanoseconds::max();
+ ns = nanoseconds:: max BOOST_PREVENT_MACRO_SUBSTITUTION ();
           sleep_for(ns);
       }
     }

Modified: trunk/libs/thread/test/Jamfile.v2
==============================================================================
--- trunk/libs/thread/test/Jamfile.v2 (original)
+++ trunk/libs/thread/test/Jamfile.v2 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -472,6 +472,29 @@
           [ thread-run2-noit ./sync/mutual_exclusion/locks/upgrade_lock/types_pass.cpp : upgrade_lock__types_p ]
     ;
 
+ #explicit ts_strict_lock ;
+ test-suite ts_strict_lock
+ :
+ [ thread-compile-fail ./sync/mutual_exclusion/locks/strict_lock/copy_assign_fail.cpp : : strict_lock__cons__copy_assign_f ]
+ [ thread-compile-fail ./sync/mutual_exclusion/locks/strict_lock/copy_ctor_fail.cpp : : strict_lock__cons__copy_ctor_f ]
+ [ thread-run2-noit ./sync/mutual_exclusion/locks/strict_lock/default_pass.cpp : strict_lock__cons__default_p ]
+ [ thread-run2-noit ./sync/mutual_exclusion/locks/strict_lock/owns_lock_pass.cpp : strict_lock__owns_lock_p ]
+ [ thread-run2-noit ./sync/mutual_exclusion/locks/strict_lock/types_pass.cpp : strict_lock__types_p ]
+ #[ thread-run2-noit ./sync/mutual_exclusion/locks/strict_lock/make_strict_lock_pass.cpp : make_strict_lock_p ]
+ ;
+
+ #explicit ts_nested_strict_lock ;
+ test-suite ts_nested_strict_lock
+ :
+ [ thread-compile-fail ./sync/mutual_exclusion/locks/nested_strict_lock/copy_assign_fail.cpp : : nested_strict_lock__cons__copy_assign_f ]
+ [ thread-compile-fail ./sync/mutual_exclusion/locks/nested_strict_lock/copy_ctor_fail.cpp : : nested_strict_lock__cons__copy_ctor_f ]
+ [ thread-run2-noit ./sync/mutual_exclusion/locks/nested_strict_lock/default_pass.cpp : nested_strict_lock__cons__default_p ]
+ [ thread-run2-noit ./sync/mutual_exclusion/locks/nested_strict_lock/owns_lock_pass.cpp : nested_strict_lock__owns_lock_p ]
+ [ thread-run2-noit ./sync/mutual_exclusion/locks/nested_strict_lock/types_pass.cpp : nested_strict_lock__types_p ]
+ #[ thread-run2-noit ./sync/mutual_exclusion/locks/nested_strict_lock/make_nested_strict_lock_pass.cpp : make_nested_strict_lock_p ]
+ ;
+
+
     #explicit ts_mutex ;
     test-suite ts_mutex
     :

Modified: trunk/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/make_lock_guard_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/make_lock_guard_pass.cpp (original)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/make_lock_guard_pass.cpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -38,7 +38,7 @@
 
 boost::mutex m;
 
-#if ! defined(BOOST_NO_CXX11_AUTO) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
+#if ! defined(BOOST_NO_CXX11_AUTO) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST && defined BOOST_THREAD_USES_CHRONO
 
 void f()
 {
@@ -63,9 +63,7 @@
   {
     m.lock();
     boost::thread t(f);
- #ifdef BOOST_THREAD_USES_CHRONO
     boost::this_thread::sleep_for(ms(250));
- #endif
     m.unlock();
     t.join();
   }

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/copy_assign_fail.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/copy_assign_fail.cpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -0,0 +1,31 @@
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// <boost/thread/locks.hpp>
+
+// template <class Mutex> class nested_strict_lock;
+
+// nested_strict_lock& operator=(nested_strict_lock const&) = delete;
+
+#include <boost/thread/lock_types.hpp>
+#include <boost/thread/strict_lock.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::mutex m0;
+boost::mutex m1;
+
+int main()
+{
+ boost::unique_lock<boost::mutex> lk0(m0);
+ boost::unique_lock<boost::mutex> lk1(m1);
+ boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlk0(lk0);
+ boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlk1(lk1);
+ lk1 = lk0;
+
+}
+
+#include "../../../../remove_error_code_unused_warning.hpp"
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/copy_ctor_fail.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/copy_ctor_fail.cpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -0,0 +1,28 @@
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// <boost/thread/locks.hpp>
+
+// template <class Mutex> class nested_strict_lock;
+
+// nested_strict_lock(nested_strict_lock const&) = delete;
+
+
+#include <boost/thread/lock_types.hpp>
+#include <boost/thread/strict_lock.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::mutex m0;
+boost::mutex m1;
+
+int main()
+{
+ boost::nested_strict_lock<boost::mutex> lk0(m0);
+ boost::nested_strict_lock<boost::mutex> lk1 = lk0;
+}
+
+#include "../../../../remove_error_code_unused_warning.hpp"
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/default_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/default_pass.cpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -0,0 +1,68 @@
+// Copyright (C) 2012 Vicente J. Botet Escriba
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// <boost/thread/locks.hpp>
+
+// template <class Mutex> class nested_strict_lock;
+
+// nested_strict_lock(Mutex &);
+
+#include <boost/thread/lock_types.hpp>
+#include <boost/thread/strict_lock.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#ifdef BOOST_THREAD_USES_CHRONO
+typedef boost::chrono::high_resolution_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef boost::chrono::milliseconds ms;
+typedef boost::chrono::nanoseconds ns;
+#endif
+
+boost::mutex m;
+
+void f()
+{
+#ifdef BOOST_THREAD_USES_CHRONO
+ time_point t0 = Clock::now();
+ time_point t1;
+ boost::unique_lock<boost::mutex> lg(m);
+ {
+ boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlg(lg);
+ t1 = Clock::now();
+ }
+ ns d = t1 - t0 - ms(250);
+ // This test is spurious as it depends on the time the thread system switches the threads
+ BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
+#else
+ //time_point t0 = Clock::now();
+ //time_point t1;
+ boost::unique_lock<boost::mutex> lg(m);
+ {
+ boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlg(lg);
+ //t1 = Clock::now();
+ }
+ //ns d = t1 - t0 - ms(250);
+ // This test is spurious as it depends on the time the thread system switches the threads
+ //BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
+#endif
+}
+
+int main()
+{
+ {
+ m.lock();
+ boost::thread t(f);
+#ifdef BOOST_THREAD_USES_CHRONO
+ boost::this_thread::sleep_for(ms(250));
+#endif
+ m.unlock();
+ t.join();
+ }
+
+ return boost::report_errors();
+}

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/make_nested_strict_lock_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/make_nested_strict_lock_pass.cpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -0,0 +1,65 @@
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// <boost/thread/strict_lock.hpp>
+
+// template <class Lockable>
+// strict_lock<Lockable> make_strict_lock(Lockable &);
+
+#define BOOST_THREAD_VERSION 4
+#define BOOST_THREAD_USES_LOG
+#define BOOST_THREAD_DONT_PROVIDE_NESTED_LOCKS
+
+#include <boost/thread/detail/log.hpp>
+#include <boost/thread/lock_types.hpp>
+#include <boost/thread/strict_lock.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread.hpp>
+
+#include <boost/detail/lightweight_test.hpp>
+
+#ifdef BOOST_THREAD_USES_CHRONO
+typedef boost::chrono::high_resolution_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef boost::chrono::milliseconds ms;
+typedef boost::chrono::nanoseconds ns;
+#endif
+
+boost::mutex m;
+
+#if ! defined(BOOST_NO_CXX11_AUTO) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST && BOOST_THREAD_USES_CHRONO
+
+void f()
+{
+ time_point t0 = Clock::now();
+ time_point t1;
+ boost::unique_lock<boost::mutex> lg(m);
+ {
+ const auto&& nlg = boost::make_strict_lock(lg); (void)nlg;
+ t1 = Clock::now();
+ BOOST_THREAD_TRACE;
+ }
+ BOOST_THREAD_TRACE;
+ ns d = t1 - t0 - ms(250);
+ // This test is spurious as it depends on the time the thread system switches the threads
+ BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
+}
+#endif
+
+int main()
+{
+
+#if ! defined(BOOST_NO_CXX11_AUTO) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
+ {
+ m.lock();
+ boost::thread t(f);
+ boost::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+ }
+#endif
+ return boost::report_errors();
+}

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/owns_lock_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/owns_lock_pass.cpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -0,0 +1,60 @@
+// Copyright (C) 2012 Vicente J. Botet Escriba
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// <boost/thread/locks.hpp>
+
+// template <class Mutex> class nested_strict_lock;
+
+// bool owns_lock(Mutex *) const;
+
+#include <boost/thread/lock_types.hpp>
+#include <boost/thread/strict_lock.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ boost::mutex m;
+ boost::mutex m2;
+ {
+ boost::unique_lock<boost::mutex> lk(m);
+ {
+ boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlk(lk);
+ BOOST_TEST(nlk.owns_lock(&m) == true);
+ BOOST_TEST(!nlk.owns_lock(&m2) == true);
+ }
+ BOOST_TEST(lk.owns_lock() == true && lk.mutex()==&m);
+ }
+ {
+ m.lock();
+ boost::unique_lock<boost::mutex> lk(m, boost::adopt_lock);
+ {
+ boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlk(lk);
+ BOOST_TEST(nlk.owns_lock(&m) == true);
+ BOOST_TEST(!nlk.owns_lock(&m2) == true);
+ }
+ BOOST_TEST(lk.owns_lock() == true && lk.mutex()==&m);
+ }
+ {
+ boost::unique_lock<boost::mutex> lk(m, boost::defer_lock);
+ {
+ boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlk(lk);
+ BOOST_TEST(nlk.owns_lock(&m) == true);
+ BOOST_TEST(!nlk.owns_lock(&m2) == true);
+ }
+ BOOST_TEST(lk.owns_lock() == true && lk.mutex()==&m);
+ }
+ {
+ boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock);
+ {
+ boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlk(lk);
+ BOOST_TEST(nlk.owns_lock(&m) == true);
+ BOOST_TEST(!nlk.owns_lock(&m2) == true);
+ }
+ BOOST_TEST(lk.owns_lock() == true && lk.mutex()==&m);
+ }
+
+ return boost::report_errors();
+}

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/types_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/types_pass.cpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -0,0 +1,35 @@
+// Copyright (C) 2012 Vicente J. Botet Escriba
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// <boost/thread/mutex.hpp>
+
+// <mutex>
+
+// template <class Lock>
+// class nested_strict_lock
+// {
+// public:
+// typedef typename Lock::mutex_type mutex_type;
+// ...
+// };
+
+
+#include <boost/thread/lock_types.hpp>
+#include <boost/thread/strict_lock.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::nested_strict_lock<boost::unique_lock<boost::mutex> >::mutex_type,
+ boost::mutex>::value), "");
+
+ BOOST_STATIC_ASSERT_MSG((boost::is_strict_lock<boost::nested_strict_lock<boost::unique_lock<boost::mutex> > >::value), "");
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/copy_assign_fail.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/copy_assign_fail.cpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -0,0 +1,28 @@
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// <boost/thread/locks.hpp>
+
+// template <class Mutex> class strict_lock;
+
+// strict_lock& operator=(strict_lock const&) = delete;
+
+#include <boost/thread/strict_lock.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::mutex m0;
+boost::mutex m1;
+
+int main()
+{
+ boost::strict_lock<boost::mutex> lk0(m0);
+ boost::strict_lock<boost::mutex> lk1(m1);
+ lk1 = lk0;
+
+}
+
+#include "../../../../remove_error_code_unused_warning.hpp"
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/copy_ctor_fail.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/copy_ctor_fail.cpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -0,0 +1,27 @@
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// <boost/thread/locks.hpp>
+
+// template <class Mutex> class strict_lock;
+
+// strict_lock(strict_lock const&) = delete;
+
+
+#include <boost/thread/strict_lock.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::mutex m0;
+boost::mutex m1;
+
+int main()
+{
+ boost::strict_lock<boost::mutex> lk0(m0);
+ boost::strict_lock<boost::mutex> lk1 = lk0;
+}
+
+#include "../../../../remove_error_code_unused_warning.hpp"
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/default_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/default_pass.cpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -0,0 +1,63 @@
+// Copyright (C) 2012 Vicente J. Botet Escriba
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// <boost/thread/locks.hpp>
+
+// template <class Mutex> class strict_lock;
+
+// strict_lock(Mutex &);
+
+#include <boost/thread/strict_lock.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#ifdef BOOST_THREAD_USES_CHRONO
+typedef boost::chrono::high_resolution_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef boost::chrono::milliseconds ms;
+typedef boost::chrono::nanoseconds ns;
+#endif
+
+boost::mutex m;
+
+void f()
+{
+#ifdef BOOST_THREAD_USES_CHRONO
+ time_point t0 = Clock::now();
+ time_point t1;
+ {
+ boost::strict_lock<boost::mutex> lg(m);
+ t1 = Clock::now();
+ }
+ ns d = t1 - t0 - ms(250);
+ // This test is spurious as it depends on the time the thread system switches the threads
+ BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
+#else
+ //time_point t0 = Clock::now();
+ //time_point t1;
+ {
+ boost::strict_lock<boost::mutex> lg(m);
+ //t1 = Clock::now();
+ }
+ //ns d = t1 - t0 - ms(250);
+ // This test is spurious as it depends on the time the thread system switches the threads
+ //BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
+#endif
+}
+
+int main()
+{
+ m.lock();
+ boost::thread t(f);
+#ifdef BOOST_THREAD_USES_CHRONO
+ boost::this_thread::sleep_for(ms(250));
+#endif
+ m.unlock();
+ t.join();
+
+ return boost::report_errors();
+}

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/make_strict_lock_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/make_strict_lock_pass.cpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -0,0 +1,63 @@
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// <boost/thread/strict_lock.hpp>
+
+// template <class Lockable>
+// strict_lock<Lockable> make_strict_lock(Lockable &);
+
+#define BOOST_THREAD_VERSION 4
+#define BOOST_THREAD_USES_LOG
+#define BOOST_THREAD_DONT_PROVIDE_NESTED_LOCKS
+
+#include <boost/thread/detail/log.hpp>
+#include <boost/thread/strict_lock.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread.hpp>
+
+#include <boost/detail/lightweight_test.hpp>
+
+#ifdef BOOST_THREAD_USES_CHRONO
+typedef boost::chrono::high_resolution_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef boost::chrono::milliseconds ms;
+typedef boost::chrono::nanoseconds ns;
+#endif
+
+boost::mutex m;
+
+#if ! defined(BOOST_NO_CXX11_AUTO) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST && BOOST_THREAD_USES_CHRONO
+
+void f()
+{
+ time_point t0 = Clock::now();
+ time_point t1;
+ {
+ const auto&& lg = boost::make_strict_lock(m); (void)lg;
+ t1 = Clock::now();
+ BOOST_THREAD_TRACE;
+ }
+ BOOST_THREAD_TRACE;
+ ns d = t1 - t0 - ms(250);
+ // This test is spurious as it depends on the time the thread system switches the threads
+ BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
+}
+#endif
+
+int main()
+{
+
+#if ! defined(BOOST_NO_CXX11_AUTO) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
+ {
+ m.lock();
+ boost::thread t(f);
+ boost::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+ }
+#endif
+ return boost::report_errors();
+}

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/owns_lock_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/owns_lock_pass.cpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -0,0 +1,34 @@
+// Copyright (C) 2012 Vicente J. Botet Escriba
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// <boost/thread/locks.hpp>
+
+// template <class Mutex> class strict_lock;
+
+// bool owns_lock(Mutex *) const;
+
+#include <boost/thread/strict_lock.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#ifdef BOOST_THREAD_USES_CHRONO
+typedef boost::chrono::high_resolution_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef boost::chrono::milliseconds ms;
+typedef boost::chrono::nanoseconds ns;
+#endif
+
+int main()
+{
+ boost::mutex m;
+ boost::mutex m2;
+
+ boost::strict_lock<boost::mutex> lk(m);
+ BOOST_TEST(lk.owns_lock(&m) == true);
+ BOOST_TEST(!lk.owns_lock(&m2) == true);
+ return boost::report_errors();
+}

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/types_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/types_pass.cpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -0,0 +1,34 @@
+// Copyright (C) 2012 Vicente J. Botet Escriba
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// <boost/thread/mutex.hpp>
+
+// <mutex>
+
+// template <class Mutex>
+// class strict_lock
+// {
+// public:
+// typedef Mutex mutex_type;
+// ...
+// };
+
+
+#include <boost/thread/strict_lock.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::strict_lock<boost::mutex>::mutex_type,
+ boost::mutex>::value), "");
+
+ BOOST_STATIC_ASSERT_MSG((boost::is_strict_lock<boost::strict_lock<boost::mutex> >::value), "");
+
+ return boost::report_errors();
+}
+

Modified: trunk/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs/owns_lock_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs/owns_lock_pass.cpp (original)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs/owns_lock_pass.cpp 2012-12-07 02:48:36 EST (Fri, 07 Dec 2012)
@@ -22,10 +22,11 @@
 #include <boost/thread/mutex.hpp>
 #include <boost/detail/lightweight_test.hpp>
 
-boost::mutex m;
 
 int main()
 {
+ boost::mutex m;
+
   boost::unique_lock<boost::mutex> lk0;
   BOOST_TEST(lk0.owns_lock() == false);
   boost::unique_lock<boost::mutex> lk1(m);


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk