Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77293 - in trunk/libs/thread/test: . sync/mutual_exclusion/locks/upgrade_lock/cons sync/mutual_exclusion/locks/upgrade_lock/locking sync/mutual_exclusion/locks/upgrade_lock/mod sync/mutual_exclusion/locks/upgrade_lock/obs
From: vicente.botet_at_[hidden]
Date: 2012-03-10 12:17:17


Author: viboes
Date: 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
New Revision: 77293
URL: http://svn.boost.org/trac/boost/changeset/77293

Log:
Thread: Added test for upgrade_lock
Added:
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/adopt_lock_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/copy_assign_fail.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/copy_ctor_fail.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/default_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/defer_lock_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/duration_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_assign_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/mutex_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/time_point_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/try_to_lock_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/lock_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_for_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_until_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/unlock_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/member_swap_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/non_member_swap_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/release_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/mutex_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/op_bool_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/owns_lock_pass.cpp (contents, props changed)
Text files modified:
   trunk/libs/thread/test/Jamfile.v2 | 42 +++++++++++++++++++++++++++++++++++----
   trunk/libs/thread/test/test_shared_mutex_timed_locks_chrono.cpp | 1
   2 files changed, 37 insertions(+), 6 deletions(-)

Modified: trunk/libs/thread/test/Jamfile.v2
==============================================================================
--- trunk/libs/thread/test/Jamfile.v2 (original)
+++ trunk/libs/thread/test/Jamfile.v2 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -78,7 +78,12 @@
           [ thread-run test_shared_mutex.cpp ]
           [ thread-run test_shared_mutex_part_2.cpp ]
           [ thread-run test_shared_mutex_timed_locks.cpp ]
+ #uncomment the following once these works on windows
           #[ thread-run test_shared_mutex_timed_locks_chrono.cpp ]
+ #uncomment the following once these works on windows
+ [ thread-run test_v2_shared_mutex.cpp ]
+ [ thread-run test_v2_shared_mutex_part_2.cpp ]
+ [ thread-run test_v2_shared_mutex_timed_locks.cpp ]
           [ thread-run test_lock_concept.cpp ]
           [ thread-run test_generic_locks.cpp ]
           [ thread-run test_futures.cpp ]
@@ -148,11 +153,6 @@
           [ thread-run2 ./sync/futures/promise/get_future_pass.cpp : futures__promise__get_future_pass ]
     ;
 
- explicit tt ;
- test-suite tt
- :
- [ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/try_to_lock_pass.cpp : xmutual_exclusion__locks__unique_lock__cons__try_to_lock_pass ]
- ;
 
     #explicit mutual_exclusion ;
     test-suite mutual_exclusion
@@ -182,6 +182,7 @@
           [ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/obs/owns_lock_pass.cpp : mutual_exclusion__locks__unique_lock__obs__owns_lock_pass ]
           [ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/types_pass.cpp : mutual_exclusion__locks__unique_lock__types_pass ]
 
+ #uncomment the following once these works on windows
           #[ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/shared_lock/cons/copy_assign_fail.cpp : : mutual_exclusion__locks__shared_lock__cons__copy_assign_fail ]
           #[ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/shared_lock/cons/copy_ctor_fail.cpp : : mutual_exclusion__locks__shared_lock__cons__copy_ctor_fail ]
           #[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/cons/adopt_lock_pass.cpp : mutual_exclusion__locks__shared_lock__cons__adopt_lock_pass ]
@@ -205,6 +206,31 @@
           #[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/obs/op_bool_pass.cpp : mutual_exclusion__locks__shared_lock__obs__op_bool_pass ]
           #[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/obs/owns_lock_pass.cpp : mutual_exclusion__locks__shared_lock__obs__owns_lock_pass ]
 
+ #uncomment the following once these works on windows
+ #[ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/copy_assign_fail.cpp : : mutual_exclusion__locks__upgrade_lock__cons__copy_assign_fail ]
+ #[ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/copy_ctor_fail.cpp : : mutual_exclusion__locks__upgrade_lock__cons__copy_ctor_fail ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/adopt_lock_pass.cpp : mutual_exclusion__locks__upgrade_lock__cons__adopt_lock_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/default_pass.cpp : mutual_exclusion__locks__upgrade_lock__cons__default_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/defer_lock_pass.cpp : mutual_exclusion__locks__upgrade_lock__cons__defer_lock_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/duration_pass.cpp : mutual_exclusion__locks__upgrade_lock__cons__duration_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/move_assign_pass.cpp : mutual_exclusion__locks__upgrade_lock__cons__move_assign_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_pass.cpp : mutual_exclusion__locks__upgrade_lock__cons__move_ctor_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/mutex_pass.cpp : mutual_exclusion__locks__upgrade_lock__cons__mutex_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/time_point_pass.cpp : mutual_exclusion__locks__upgrade_lock__cons__time_point_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/try_to_lock_pass.cpp : mutual_exclusion__locks__upgrade_lock__cons__try_to_lock_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/locking/lock_pass.cpp : mutual_exclusion__locks__upgrade_lock__locking__lock_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_for_pass.cpp : mutual_exclusion__locks__upgrade_lock__locking__try_lock_for_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_pass.cpp : mutual_exclusion__locks__upgrade_lock__locking__try_lock_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_until_pass.cpp : mutual_exclusion__locks__upgrade_lock__locking__try_lock_until_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/locking/unlock_pass.cpp : mutual_exclusion__locks__upgrade_lock__locking__unlock_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/mod/member_swap_pass.cpp : mutual_exclusion__locks__upgrade_lock__mod__member_swap_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/mod/non_member_swap_pass.cpp : mutual_exclusion__locks__upgrade_lock__mod__non_member_swap_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/mod/release_pass.cpp : mutual_exclusion__locks__upgrade_lock__mod__release_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/obs/mutex_pass.cpp : mutual_exclusion__locks__upgrade_lock__obs__mutex_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/obs/op_bool_pass.cpp : mutual_exclusion__locks__upgrade_lock__obs__op_bool_pass ]
+ #[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/obs/owns_lock_pass.cpp : mutual_exclusion__locks__upgrade_lock__obs__owns_lock_pass ]
+
+
           [ thread-compile-fail-V2 ./sync/mutual_exclusion/mutex/assign_fail.cpp : : mutual_exclusion__mutex__assign_fail ]
           [ thread-compile-fail-V2 ./sync/mutual_exclusion/mutex/copy_fail.cpp : : mutual_exclusion__mutex__copy_fail ]
           [ thread-run2 ./sync/mutual_exclusion/mutex/default_pass.cpp : mutual_exclusion__mutex__default_pass ]
@@ -277,4 +303,10 @@
           [ thread-run2 ./threads/thread/non_members/swap_pass.cpp : thread__non_members__swap_pass ]
           [ thread-run2 ./threads/thread/static/hardware_concurrency_pass.cpp : thread__static__hardware_concurrency_pass ]
     ;
+
+ #explicit ttt ;
+ #test-suite ttt
+ #:
+ #;
+
 }

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/adopt_lock_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/adopt_lock_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// upgrade_lock(mutex_type& m, adopt_lock_t);
+
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+
+int main()
+{
+ boost::shared_mutex m;
+ m.lock();
+ boost::upgrade_lock<boost::shared_mutex> lk(m, boost::adopt_lock);
+ BOOST_TEST(lk.mutex() == &m);
+ BOOST_TEST(lk.owns_lock() == true);
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/copy_assign_fail.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/copy_assign_fail.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// upgrade_lock& operator=(upgrade_lock const&) = delete;
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::shared_mutex m0;
+boost::shared_mutex m1;
+
+int main()
+{
+ boost::upgrade_lock<boost::shared_mutex> lk0(m0);
+ boost::upgrade_lock<boost::shared_mutex> lk1(m1);
+ lk1 = lk0;
+ BOOST_TEST(lk1.mutex() == &m0);
+ BOOST_TEST(lk1.owns_lock() == true);
+ BOOST_TEST(lk0.mutex() == 0);
+ BOOST_TEST(lk0.owns_lock() == false);
+
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/copy_ctor_fail.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/copy_ctor_fail.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// upgrade_lock(upgrade_lock const&) = delete;
+
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::shared_mutex m0;
+boost::shared_mutex m1;
+
+int main()
+{
+ boost::upgrade_lock<boost::shared_mutex> lk0(m0);
+ boost::upgrade_lock<boost::shared_mutex> lk1(lk0);
+ BOOST_TEST(lk1.mutex() == &m1);
+ BOOST_TEST(lk1.owns_lock() == true);
+ BOOST_TEST(lk0.mutex() == 0);
+ BOOST_TEST(lk0.owns_lock() == false);
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/default_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/default_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// upgrade_lock(upgrade_lock const&) = delete;
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ boost::upgrade_lock<boost::shared_mutex> ul;
+ BOOST_TEST(!ul.owns_lock());
+ BOOST_TEST(ul.mutex() == 0);
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/defer_lock_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/defer_lock_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// upgrade_lock(mutex_type& m, adopt_lock_t);
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ boost::shared_mutex m;
+ m.lock();
+ boost::upgrade_lock<boost::shared_mutex> lk(m, boost::defer_lock);
+ BOOST_TEST(lk.mutex() == &m);
+ BOOST_TEST(lk.owns_lock() == false);
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/duration_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/duration_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,76 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// template <class Rep, class Period>
+// upgrade_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time);
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/chrono/chrono_io.hpp>
+
+boost::shared_mutex m;
+
+typedef boost::chrono::steady_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef boost::chrono::milliseconds ms;
+typedef boost::chrono::nanoseconds ns;
+
+void f1()
+{
+ time_point t0 = Clock::now();
+ boost::upgrade_lock<boost::shared_mutex> lk(m, ms(300));
+ BOOST_TEST(lk.owns_lock() == true);
+ time_point t1 = Clock::now();
+ ns d = t1 - t0 - ms(250);
+ BOOST_TEST(d < ns(5000000)); // within 5ms
+}
+
+void f2()
+{
+ time_point t0 = Clock::now();
+ boost::upgrade_lock<boost::shared_mutex> lk(m, ms(250));
+ BOOST_TEST(lk.owns_lock() == false);
+ time_point 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(5000000)+ms(1000)); // within 5ms
+}
+
+int main()
+{
+ {
+ m.lock();
+ boost::thread t(f1);
+ boost::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+ }
+ {
+ m.lock();
+ boost::thread t(f2);
+ boost::this_thread::sleep_for(ms(300));
+ m.unlock();
+ t.join();
+ }
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_assign_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_assign_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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/shared_mutex.hpp>
+
+// template <class Mutex> class upgrade_lock;
+
+// upgrade_lock(upgrade_lock const&) = delete;
+
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::shared_mutex m0;
+boost::shared_mutex m1;
+
+int main()
+{
+ {
+ boost::upgrade_lock<boost::shared_mutex> lk0(m0);
+ boost::upgrade_lock<boost::shared_mutex> lk1(m1);
+ lk1 = boost::move(lk0);
+ BOOST_TEST(lk1.mutex() == &m0);
+ BOOST_TEST(lk1.owns_lock() == true);
+ BOOST_TEST(lk0.mutex() == 0);
+ BOOST_TEST(lk0.owns_lock() == false);
+ }
+ {
+
+ boost::upgrade_lock<boost::shared_mutex> lk1;
+ lk1 = boost::upgrade_lock<boost::shared_mutex>(m0);
+ BOOST_TEST(lk1.mutex() == &m0);
+ BOOST_TEST(lk1.owns_lock() == true);
+ }
+ {
+ boost::unique_lock<boost::shared_mutex> lk0(m0);
+ boost::upgrade_lock<boost::shared_mutex> lk1(m1);
+ lk1 = boost::move(lk0);
+ BOOST_TEST(lk1.mutex() == &m0);
+ BOOST_TEST(lk1.owns_lock() == true);
+ BOOST_TEST(lk0.mutex() == 0);
+ BOOST_TEST(lk0.owns_lock() == false);
+ }
+ {
+
+ boost::upgrade_lock<boost::shared_mutex> lk1;
+ lk1 = boost::unique_lock<boost::shared_mutex>(m0);
+ BOOST_TEST(lk1.mutex() == &m0);
+ BOOST_TEST(lk1.owns_lock() == true);
+ }
+ return boost::report_errors();
+
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,59 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// upgrade_lock& operator=(upgrade_lock&& u);
+
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::shared_mutex m;
+
+int main()
+{
+ {
+ boost::upgrade_lock<boost::shared_mutex> lk0(m);
+ boost::upgrade_lock<boost::shared_mutex> lk( (boost::move(lk0)));
+ BOOST_TEST(lk.mutex() == &m);
+ BOOST_TEST(lk.owns_lock() == true);
+ BOOST_TEST(lk0.mutex() == 0);
+ BOOST_TEST(lk0.owns_lock() == false);
+ }
+ {
+ boost::upgrade_lock<boost::shared_mutex> lk( (boost::upgrade_lock<boost::shared_mutex>(m)));
+ BOOST_TEST(lk.mutex() == &m);
+ BOOST_TEST(lk.owns_lock() == true);
+ }
+ {
+ boost::unique_lock<boost::shared_mutex> lk0(m);
+ boost::upgrade_lock<boost::shared_mutex> lk( (boost::move(lk0)));
+ BOOST_TEST(lk.mutex() == &m);
+ BOOST_TEST(lk.owns_lock() == true);
+ BOOST_TEST(lk0.mutex() == 0);
+ BOOST_TEST(lk0.owns_lock() == false);
+ }
+ {
+ boost::upgrade_lock<boost::shared_mutex> lk( (boost::unique_lock<boost::shared_mutex>(m)));
+ BOOST_TEST(lk.mutex() == &m);
+ BOOST_TEST(lk.owns_lock() == true);
+ }
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/mutex_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/mutex_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// explicit upgrade_lock(Mutex& m);
+
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::shared_mutex m;
+
+typedef boost::chrono::system_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef boost::chrono::milliseconds ms;
+typedef boost::chrono::nanoseconds ns;
+
+void f()
+{
+ time_point t0 = Clock::now();
+ time_point t1;
+ {
+ boost::upgrade_lock<boost::shared_mutex> ul(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
+}
+
+int main()
+{
+ m.lock();
+ boost::thread t(f);
+ boost::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/time_point_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/time_point_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,75 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 shared_lock;
+
+// template <class Clock, class Duration>
+// shared_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time);
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::shared_mutex m;
+
+typedef boost::chrono::steady_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef boost::chrono::milliseconds ms;
+typedef boost::chrono::nanoseconds ns;
+
+void f1()
+{
+ time_point t0 = Clock::now();
+ boost::shared_lock<boost::shared_mutex> lk(m, Clock::now() + ms(300));
+ BOOST_TEST(lk.owns_lock() == true);
+ time_point t1 = Clock::now();
+ ns d = t1 - t0 - ms(250);
+ BOOST_TEST(d < ns(50000000)); // within 50ms
+}
+
+void f2()
+{
+ time_point t0 = Clock::now();
+ boost::shared_lock<boost::shared_mutex> lk(m, Clock::now() + ms(250));
+ BOOST_TEST(lk.owns_lock() == false);
+ time_point 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(5000000)+ms(1000)); // within 5ms
+}
+
+int main()
+{
+ {
+ m.lock();
+ boost::thread t(f1);
+ boost::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+ }
+ {
+ m.lock();
+ boost::thread t(f2);
+ boost::this_thread::sleep_for(ms(300));
+ m.unlock();
+ t.join();
+ }
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/try_to_lock_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/try_to_lock_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 shared_lock;
+
+// shared_lock(mutex_type& m, try_to_lock_t);
+
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::shared_mutex m;
+
+typedef boost::chrono::system_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef boost::chrono::milliseconds ms;
+typedef boost::chrono::nanoseconds ns;
+
+void f()
+{
+ time_point t0 = Clock::now();
+ {
+ boost::shared_lock<boost::shared_mutex> lk(m, boost::try_to_lock);
+ BOOST_TEST(lk.owns_lock() == false);
+ }
+ {
+ boost::shared_lock<boost::shared_mutex> lk(m, boost::try_to_lock);
+ BOOST_TEST(lk.owns_lock() == false);
+ }
+ {
+ boost::shared_lock<boost::shared_mutex> lk(m, boost::try_to_lock);
+ BOOST_TEST(lk.owns_lock() == false);
+ }
+ while (true)
+ {
+ boost::shared_lock<boost::shared_mutex> lk(m, boost::try_to_lock);
+ if (lk.owns_lock()) break;
+ }
+ time_point t1 = Clock::now();
+ //m.unlock();
+ 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(50000000)+ms(1000)); // within 50ms
+}
+
+int main()
+{
+ m.lock();
+ boost::thread t(f);
+ boost::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/lock_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/lock_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,77 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// void lock();
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <iostream>
+
+boost::shared_mutex m;
+
+typedef boost::chrono::system_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef boost::chrono::milliseconds ms;
+typedef boost::chrono::nanoseconds ns;
+
+void f()
+{
+ boost::upgrade_lock < boost::shared_mutex > lk(m, boost::defer_lock);
+ time_point t0 = Clock::now();
+ lk.lock();
+ time_point t1 = Clock::now();
+ BOOST_TEST(lk.owns_lock() == true);
+ 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
+ try
+ {
+ lk.lock();
+ BOOST_TEST(false);
+ }
+ catch (boost::system::system_error& e)
+ {
+ BOOST_TEST(e.code().value() == boost::system::errc::resource_deadlock_would_occur);
+ }
+ lk.unlock();
+ lk.release();
+ try
+ {
+ lk.lock();
+ BOOST_TEST(false);
+ }
+ catch (boost::system::system_error& e)
+ {
+ BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted);
+ }
+}
+
+int main()
+{
+ m.lock();
+ boost::thread t(f);
+ boost::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_for_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_for_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,78 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// template <class Rep, class Period>
+// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
+
+#include <boost/thread/locks.hpp>
+//#include <boost/thread/shared_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+bool try_lock_for_called = false;
+
+typedef boost::chrono::milliseconds ms;
+
+struct shared_mutex
+{
+ template <class Rep, class Period>
+ bool try_lock_upgrade_for(const boost::chrono::duration<Rep, Period>& rel_time)
+ {
+ BOOST_TEST(rel_time == ms(5));
+ try_lock_for_called = !try_lock_for_called;
+ return try_lock_for_called;
+ }
+ void unlock_upgrade()
+ {
+ }
+};
+
+shared_mutex m;
+
+int main()
+{
+ boost::upgrade_lock<shared_mutex> lk(m, boost::defer_lock);
+ BOOST_TEST(lk.try_lock_for(ms(5)) == true);
+ BOOST_TEST(try_lock_for_called == true);
+ BOOST_TEST(lk.owns_lock() == true);
+ try
+ {
+ lk.try_lock_for(ms(5));
+ BOOST_TEST(false);
+ }
+ catch (boost::system::system_error& e)
+ {
+ BOOST_TEST(e.code().value() == boost::system::errc::resource_deadlock_would_occur);
+ }
+ lk.unlock();
+ BOOST_TEST(lk.try_lock_for(ms(5)) == false);
+ BOOST_TEST(try_lock_for_called == false);
+ BOOST_TEST(lk.owns_lock() == false);
+ lk.release();
+ try
+ {
+ lk.try_lock_for(ms(5));
+ BOOST_TEST(false);
+ }
+ catch (boost::system::system_error& e)
+ {
+ BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted);
+ }
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,74 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// template <class Rep, class Period>
+// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
+
+#include <boost/thread/locks.hpp>
+//#include <boost/thread/shared_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+bool try_lock_called = false;
+
+struct shared_mutex
+{
+ bool try_lock_upgrade()
+ {
+ try_lock_called = !try_lock_called;
+ return try_lock_called;
+ }
+ void unlock_upgrade()
+ {
+ }
+};
+
+shared_mutex m;
+
+int main()
+{
+ boost::upgrade_lock<shared_mutex> lk(m, boost::defer_lock);
+ BOOST_TEST(lk.try_lock() == true);
+ BOOST_TEST(try_lock_called == true);
+ BOOST_TEST(lk.owns_lock() == true);
+ try
+ {
+ lk.try_lock();
+ BOOST_TEST(false);
+ }
+ catch (boost::system::system_error& e)
+ {
+ BOOST_TEST(e.code().value() == boost::system::errc::resource_deadlock_would_occur);
+ }
+ lk.unlock();
+ BOOST_TEST(lk.try_lock() == false);
+ BOOST_TEST(try_lock_called == false);
+ BOOST_TEST(lk.owns_lock() == false);
+ lk.release();
+ try
+ {
+ lk.try_lock();
+ BOOST_TEST(false);
+ }
+ catch (boost::system::system_error& e)
+ {
+ BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted);
+ }
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_until_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_until_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,76 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// template <class Clock, class Duration>
+// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+bool try_lock_until_called = false;
+
+struct shared_mutex
+{
+ template <class Clock, class Duration>
+ bool try_lock_upgrade_until(const boost::chrono::time_point<Clock, Duration>& abs_time)
+ {
+ typedef boost::chrono::milliseconds ms;
+ BOOST_TEST(Clock::now() - abs_time < ms(5));
+ try_lock_until_called = !try_lock_until_called;
+ return try_lock_until_called;
+ }
+ void unlock_upgrade()
+ {
+ }
+};
+
+shared_mutex m;
+
+int main()
+{
+ typedef boost::chrono::steady_clock Clock;
+ boost::upgrade_lock<shared_mutex> lk(m, boost::defer_lock);
+ BOOST_TEST(lk.try_lock_until(Clock::now()) == true);
+ BOOST_TEST(try_lock_until_called == true);
+ BOOST_TEST(lk.owns_lock() == true);
+ try
+ {
+ lk.try_lock_until(Clock::now());
+ BOOST_TEST(false);
+ }
+ catch (boost::system::system_error& e)
+ {
+ BOOST_TEST(e.code().value() == boost::system::errc::resource_deadlock_would_occur);
+ }
+ lk.unlock();
+ BOOST_TEST(lk.try_lock_until(Clock::now()) == false);
+ BOOST_TEST(try_lock_until_called == false);
+ BOOST_TEST(lk.owns_lock() == false);
+ lk.release();
+ try
+ {
+ lk.try_lock_until(Clock::now());
+ BOOST_TEST(false);
+ }
+ catch (boost::system::system_error& e)
+ {
+ BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted);
+ }
+ return boost::report_errors();
+}

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/unlock_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/unlock_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// template <class Rep, class Period>
+// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
+
+#include <boost/thread/locks.hpp>
+//#include <boost/thread/shared_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+bool unlock_called = false;
+
+struct shared_mutex
+{
+ void lock_upgrade()
+ {
+ }
+ void unlock_upgrade()
+ {
+ unlock_called = true;
+ }
+};
+
+shared_mutex m;
+
+int main()
+{
+ boost::upgrade_lock<shared_mutex> lk(m);
+ lk.unlock();
+ BOOST_TEST(unlock_called == true);
+ BOOST_TEST(lk.owns_lock() == false);
+ try
+ {
+ lk.unlock();
+ BOOST_TEST(false);
+ }
+ catch (boost::system::system_error& e)
+ {
+ BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted);
+ }
+ lk.release();
+ try
+ {
+ lk.unlock();
+ BOOST_TEST(false);
+ }
+ catch (boost::system::system_error& e)
+ {
+ BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted);
+ }
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/member_swap_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/member_swap_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// void swap(upgrade_lock& u);
+
+#include <boost/thread/locks.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+struct shared_mutex
+{
+ void lock_upgrade()
+ {
+ }
+ void unlock_upgrade()
+ {
+ }
+};
+
+shared_mutex m;
+
+int main()
+{
+ boost::upgrade_lock<shared_mutex> lk1(m);
+ boost::upgrade_lock<shared_mutex> lk2;
+ lk1.swap(lk2);
+ BOOST_TEST(lk1.mutex() == 0);
+ BOOST_TEST(lk1.owns_lock() == false);
+ BOOST_TEST(lk2.mutex() == &m);
+ BOOST_TEST(lk2.owns_lock() == true);
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/non_member_swap_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/non_member_swap_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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>
+// void swap(upgrade_lock<Mutex>& x, upgrade_lock<Mutex>& y);
+
+#include <boost/thread/locks.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+struct shared_mutex
+{
+ void lock_upgrade()
+ {
+ }
+ void unlock_upgrade()
+ {
+ }
+};
+
+shared_mutex m;
+
+int main()
+{
+ boost::upgrade_lock<shared_mutex> lk1(m);
+ boost::upgrade_lock<shared_mutex> lk2;
+ swap(lk1, lk2);
+ BOOST_TEST(lk1.mutex() == 0);
+ BOOST_TEST(lk1.owns_lock() == false);
+ BOOST_TEST(lk2.mutex() == &m);
+ BOOST_TEST(lk2.owns_lock() == true);
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/release_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/release_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// void Mutex* release();
+
+#include <boost/thread/locks.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+struct shared_mutex
+{
+ static int lock_count;
+ static int unlock_count;
+ void lock_upgrade()
+ {
+ ++lock_count;
+ }
+ void unlock_upgrade()
+ {
+ ++unlock_count;
+ }
+};
+
+int shared_mutex::lock_count = 0;
+int shared_mutex::unlock_count = 0;
+
+shared_mutex m;
+
+int main()
+{
+ boost::upgrade_lock<shared_mutex> lk(m);
+ BOOST_TEST(lk.mutex() == &m);
+ BOOST_TEST(lk.owns_lock() == true);
+ BOOST_TEST(shared_mutex::lock_count == 1);
+ BOOST_TEST(shared_mutex::unlock_count == 0);
+ BOOST_TEST(lk.release() == &m);
+ BOOST_TEST(lk.mutex() == 0);
+ BOOST_TEST(lk.owns_lock() == false);
+ BOOST_TEST(shared_mutex::lock_count == 1);
+ BOOST_TEST(shared_mutex::unlock_count == 0);
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/mutex_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/mutex_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// Mutex *mutex() const;
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::shared_mutex m;
+
+int main()
+{
+ boost::upgrade_lock<boost::shared_mutex> lk0;
+ BOOST_TEST(lk0.mutex() == 0);
+ boost::upgrade_lock<boost::shared_mutex> lk1(m);
+ BOOST_TEST(lk1.mutex() == &m);
+ lk1.unlock();
+ BOOST_TEST(lk1.mutex() == &m);
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/op_bool_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/op_bool_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// explicit operator bool() const;
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::shared_mutex m;
+
+int main()
+{
+ boost::upgrade_lock < boost::shared_mutex > lk0;
+ BOOST_TEST(bool(lk0) == false);
+ boost::upgrade_lock < boost::shared_mutex > lk1(m);
+ BOOST_TEST(bool(lk1) == true);
+ lk1.unlock();
+ BOOST_TEST(bool(lk1) == false);
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/owns_lock_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/owns_lock_pass.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// 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 upgrade_lock;
+
+// bool owns_lock() const;
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::shared_mutex m;
+
+int main()
+{
+ boost::upgrade_lock<boost::shared_mutex> lk0;
+ BOOST_TEST(lk0.owns_lock() == false);
+ boost::upgrade_lock<boost::shared_mutex> lk1(m);
+ BOOST_TEST(lk1.owns_lock() == true);
+ lk1.unlock();
+ BOOST_TEST(lk1.owns_lock() == false);
+
+
+ return boost::report_errors();
+}
+

Modified: trunk/libs/thread/test/test_shared_mutex_timed_locks_chrono.cpp
==============================================================================
--- trunk/libs/thread/test/test_shared_mutex_timed_locks_chrono.cpp (original)
+++ trunk/libs/thread/test/test_shared_mutex_timed_locks_chrono.cpp 2012-03-10 12:17:14 EST (Sat, 10 Mar 2012)
@@ -6,7 +6,6 @@
 #include <boost/test/unit_test.hpp>
 #include <boost/thread/thread.hpp>
 #include <boost/thread/shared_mutex.hpp>
-//#include <boost/thread/xtime.hpp>
 #include "util.inl"
 #include "shared_mutex_locking_thread.hpp"
 


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