summaryrefslogtreecommitdiff
path: root/libs/thread/test/sync/mutual_exclusion/locks/shared_lock
diff options
context:
space:
mode:
Diffstat (limited to 'libs/thread/test/sync/mutual_exclusion/locks/shared_lock')
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/adopt_lock_pass.cpp37
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/copy_assign_fail.cpp49
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/copy_ctor_fail.cpp48
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/default_pass.cpp33
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/defer_lock_pass.cpp35
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/duration_pass.cpp79
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_assign_pass.cpp82
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_pass.cpp47
-rw-r--r--libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_unique_lock_pass.cpp65
-rw-r--r--libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_upgrade_lock_pass.cpp64
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/mutex_pass.cpp76
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/time_point_pass.cpp77
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/try_to_lock_pass.cpp102
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/lock_pass.cpp114
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_for_pass.cpp78
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_pass.cpp74
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_until_pass.cpp76
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/unlock_pass.cpp69
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/member_swap_pass.cpp48
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/non_member_swap_pass.cpp47
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/release_pass.cpp58
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/mutex_pass.cpp38
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/op_bool_pass.cpp38
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/owns_lock_pass.cpp39
-rwxr-xr-xlibs/thread/test/sync/mutual_exclusion/locks/shared_lock/types_pass.cpp40
25 files changed, 1513 insertions, 0 deletions
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/adopt_lock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/adopt_lock_pass.cpp
new file mode 100755
index 0000000000..732ad6325a
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/adopt_lock_pass.cpp
@@ -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 shared_lock;
+
+// shared_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::shared_lock<boost::shared_mutex> lk(m, boost::adopt_lock);
+ BOOST_TEST(lk.mutex() == &m);
+ BOOST_TEST(lk.owns_lock() == true);
+
+ return boost::report_errors();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/copy_assign_fail.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/copy_assign_fail.cpp
new file mode 100755
index 0000000000..55ef440c80
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/copy_assign_fail.cpp
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// 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& operator=(shared_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::shared_lock<boost::shared_mutex> lk0(m0);
+ boost::shared_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);
+
+}
+
+void remove_unused_warning()
+{
+ //../../../boost/system/error_code.hpp:214:36: warning: Ôboost::system::posix_categoryÕ defined but not used [-Wunused-variable]
+ //../../../boost/system/error_code.hpp:215:36: warning: Ôboost::system::errno_ecatÕ defined but not used [-Wunused-variable]
+ //../../../boost/system/error_code.hpp:216:36: warning: Ôboost::system::native_ecatÕ defined but not used [-Wunused-variable]
+
+ (void)boost::system::posix_category;
+ (void)boost::system::errno_ecat;
+ (void)boost::system::native_ecat;
+}
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/copy_ctor_fail.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/copy_ctor_fail.cpp
new file mode 100755
index 0000000000..1756a63342
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/copy_ctor_fail.cpp
@@ -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 shared_lock;
+
+// shared_lock(shared_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::shared_lock<boost::shared_mutex> lk0(m0);
+ boost::shared_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);
+}
+
+void remove_unused_warning()
+{
+ //../../../boost/system/error_code.hpp:214:36: warning: Ôboost::system::posix_categoryÕ defined but not used [-Wunused-variable]
+ //../../../boost/system/error_code.hpp:215:36: warning: Ôboost::system::errno_ecatÕ defined but not used [-Wunused-variable]
+ //../../../boost/system/error_code.hpp:216:36: warning: Ôboost::system::native_ecatÕ defined but not used [-Wunused-variable]
+
+ (void)boost::system::posix_category;
+ (void)boost::system::errno_ecat;
+ (void)boost::system::native_ecat;
+}
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/default_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/default_pass.cpp
new file mode 100755
index 0000000000..e7b8127711
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/default_pass.cpp
@@ -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 shared_lock;
+
+// shared_lock(shared_lock const&) = delete;
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ boost::shared_lock<boost::shared_mutex> ul;
+ BOOST_TEST(!ul.owns_lock());
+ BOOST_TEST(ul.mutex() == 0);
+
+ return boost::report_errors();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/defer_lock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/defer_lock_pass.cpp
new file mode 100755
index 0000000000..caeec9c2db
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/defer_lock_pass.cpp
@@ -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 shared_lock;
+
+// shared_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::shared_lock<boost::shared_mutex> lk(m, boost::defer_lock);
+ BOOST_TEST(lk.mutex() == &m);
+ BOOST_TEST(lk.owns_lock() == false);
+
+ return boost::report_errors();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/duration_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/duration_pass.cpp
new file mode 100755
index 0000000000..d08304f762
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/duration_pass.cpp
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Rep, class Period>
+// shared_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();
+ // This test is spurious as it depends on the time the thread system switches the threads
+ boost::shared_lock<boost::shared_mutex> lk(m, ms(300)+ms(1000));
+ BOOST_TEST(lk.owns_lock() == true);
+ 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
+}
+
+void f2()
+{
+ time_point t0 = Clock::now();
+ boost::shared_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);
+ // This test is spurious as it depends on the time the thread system switches the threads
+ boost::this_thread::sleep_for(ms(300)+ms(1000));
+ m.unlock();
+ t.join();
+ }
+
+ return boost::report_errors();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_assign_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_assign_pass.cpp
new file mode 100755
index 0000000000..b3348f706b
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_assign_pass.cpp
@@ -0,0 +1,82 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 shared_lock;
+
+// shared_lock(shared_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::shared_lock<boost::shared_mutex> lk0(m0);
+ boost::shared_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::shared_lock<boost::shared_mutex> lk1;
+ lk1 = BOOST_THREAD_MAKE_RV_REF(boost::shared_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::shared_lock<boost::shared_mutex> lk1(m1);
+ lk1 = BOOST_THREAD_MAKE_RV_REF(boost::shared_lock<boost::shared_mutex>(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::shared_lock<boost::shared_mutex> lk1;
+ lk1 = BOOST_THREAD_MAKE_RV_REF(boost::shared_lock<boost::shared_mutex>(boost::unique_lock<boost::shared_mutex>(m0)));
+ BOOST_TEST(lk1.mutex() == &m0);
+ BOOST_TEST(lk1.owns_lock() == true);
+ }
+ {
+ boost::upgrade_lock<boost::shared_mutex> lk0(m0);
+ boost::shared_lock<boost::shared_mutex> lk1(m1);
+ lk1 = BOOST_THREAD_MAKE_RV_REF(boost::shared_lock<boost::shared_mutex>(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::shared_lock<boost::shared_mutex> lk1;
+ lk1 = BOOST_THREAD_MAKE_RV_REF(boost::shared_lock<boost::shared_mutex>(boost::upgrade_lock<boost::shared_mutex>(m0)));
+ BOOST_TEST(lk1.mutex() == &m0);
+ BOOST_TEST(lk1.owns_lock() == true);
+ }
+ return boost::report_errors();
+
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_pass.cpp
new file mode 100755
index 0000000000..173f6b5c99
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_pass.cpp
@@ -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> class shared_lock;
+
+// shared_lock& operator=(shared_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::shared_lock<boost::shared_mutex> lk0(m);
+ boost::shared_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::shared_lock<boost::shared_mutex> lk( (BOOST_THREAD_MAKE_RV_REF(boost::shared_lock<boost::shared_mutex>(m))));
+ BOOST_TEST(lk.mutex() == &m);
+ BOOST_TEST(lk.owns_lock() == true);
+ }
+
+
+ return boost::report_errors();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_unique_lock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_unique_lock_pass.cpp
new file mode 100644
index 0000000000..90325ed6ad
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_unique_lock_pass.cpp
@@ -0,0 +1,65 @@
+//===----------------------------------------------------------------------===//
+//
+// 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& operator=(shared_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::unique_lock<boost::shared_mutex> lk0(m);
+ boost::shared_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::shared_lock<boost::shared_mutex> lk( (boost::unique_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::defer_lock);
+ boost::shared_lock<boost::shared_mutex> lk( (boost::move(lk0)));
+ BOOST_TEST(lk.mutex() == &m);
+ BOOST_TEST(lk.owns_lock() == false);
+ BOOST_TEST(lk0.mutex() == 0);
+ BOOST_TEST(lk0.owns_lock() == false);
+ }
+ {
+ boost::unique_lock<boost::shared_mutex> lk0(m, boost::defer_lock);
+ lk0.release();
+ boost::shared_lock<boost::shared_mutex> lk( (boost::move(lk0)));
+ BOOST_TEST(lk.mutex() == 0);
+ BOOST_TEST(lk.owns_lock() == false);
+ BOOST_TEST(lk0.mutex() == 0);
+ BOOST_TEST(lk0.owns_lock() == false);
+ }
+
+
+ return boost::report_errors();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_upgrade_lock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_upgrade_lock_pass.cpp
new file mode 100644
index 0000000000..b98183e233
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_upgrade_lock_pass.cpp
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+//
+// 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& operator=(shared_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::shared_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::shared_lock<boost::shared_mutex> lk( (boost::upgrade_lock<boost::shared_mutex>(m)));
+ BOOST_TEST(lk.mutex() == &m);
+ BOOST_TEST(lk.owns_lock() == true);
+ }
+ {
+ boost::upgrade_lock<boost::shared_mutex> lk0(m, boost::defer_lock);
+ boost::shared_lock<boost::shared_mutex> lk( (boost::move(lk0)));
+ BOOST_TEST(lk.mutex() == &m);
+ BOOST_TEST(lk.owns_lock() == false);
+ BOOST_TEST(lk0.mutex() == 0);
+ BOOST_TEST(lk0.owns_lock() == false);
+ }
+ {
+ boost::upgrade_lock<boost::shared_mutex> lk0(m, boost::defer_lock);
+ lk0.release();
+ boost::shared_lock<boost::shared_mutex> lk( (boost::move(lk0)));
+ BOOST_TEST(lk.mutex() == 0);
+ BOOST_TEST(lk.owns_lock() == false);
+ BOOST_TEST(lk0.mutex() == 0);
+ BOOST_TEST(lk0.owns_lock() == false);
+ }
+
+ return boost::report_errors();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/mutex_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/mutex_pass.cpp
new file mode 100755
index 0000000000..0a0d191a82
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/mutex_pass.cpp
@@ -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 shared_lock;
+
+// explicit shared_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;
+
+#if defined BOOST_THREAD_USES_CHRONO
+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;
+#else
+#endif
+
+void f()
+{
+#if defined BOOST_THREAD_USES_CHRONO
+ time_point t0 = Clock::now();
+ time_point t1;
+ {
+ boost::shared_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(2000)); // within 2.5ms
+#else
+ //time_point t0 = Clock::now();
+ //time_point t1;
+ {
+ boost::shared_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
+#endif
+}
+
+int main()
+{
+ m.lock();
+ boost::thread t(f);
+#if defined BOOST_THREAD_USES_CHRONO
+ boost::this_thread::sleep_for(ms(250));
+#else
+#endif
+ m.unlock();
+ t.join();
+
+ return boost::report_errors();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/time_point_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/time_point_pass.cpp
new file mode 100755
index 0000000000..9308b8550c
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/time_point_pass.cpp
@@ -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 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();
+ // This test is spurious as it depends on the time the thread system switches the threads
+ boost::shared_lock<boost::shared_mutex> lk(m, Clock::now() + ms(300)+ms(1000));
+ BOOST_TEST(lk.owns_lock() == true);
+ 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(50000000)+ms(1000)); // 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)+ms(1000));
+ m.unlock();
+ t.join();
+ }
+
+ return boost::report_errors();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/try_to_lock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/try_to_lock_pass.cpp
new file mode 100755
index 0000000000..9f4251e9b6
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/try_to_lock_pass.cpp
@@ -0,0 +1,102 @@
+//===----------------------------------------------------------------------===//
+//
+// 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;
+
+#if defined BOOST_THREAD_USES_CHRONO
+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;
+#else
+#endif
+
+void f()
+{
+#if defined BOOST_THREAD_USES_CHRONO
+ 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();
+ 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
+#else
+// 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();
+ //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
+#endif
+}
+
+int main()
+{
+ m.lock();
+ boost::thread t(f);
+#if defined BOOST_THREAD_USES_CHRONO
+ boost::this_thread::sleep_for(ms(250));
+#else
+#endif
+ m.unlock();
+ t.join();
+
+ return boost::report_errors();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/lock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/lock_pass.cpp
new file mode 100755
index 0000000000..3ef6f7c2c1
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/lock_pass.cpp
@@ -0,0 +1,114 @@
+//===----------------------------------------------------------------------===//
+//
+// 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;
+
+// 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;
+
+#if defined BOOST_THREAD_USES_CHRONO
+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;
+#else
+#endif
+
+void f()
+{
+#if defined BOOST_THREAD_USES_CHRONO
+ boost::shared_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);
+ }
+#else
+ boost::shared_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);
+ }
+#endif
+}
+
+int main()
+{
+ m.lock();
+ boost::thread t(f);
+#if defined BOOST_THREAD_USES_CHRONO
+ boost::this_thread::sleep_for(ms(250));
+#else
+#endif
+ m.unlock();
+ t.join();
+
+ return boost::report_errors();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_for_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_for_pass.cpp
new file mode 100755
index 0000000000..027cf64d0a
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_for_pass.cpp
@@ -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 shared_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_shared_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_shared()
+ {
+ }
+};
+
+shared_mutex m;
+
+int main()
+{
+ boost::shared_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();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_pass.cpp
new file mode 100755
index 0000000000..5ba50cc3e5
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_pass.cpp
@@ -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 shared_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_shared()
+ {
+ try_lock_called = !try_lock_called;
+ return try_lock_called;
+ }
+ void unlock_shared()
+ {
+ }
+};
+
+shared_mutex m;
+
+int main()
+{
+ boost::shared_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();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_until_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_until_pass.cpp
new file mode 100755
index 0000000000..77dd7dc8cc
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_until_pass.cpp
@@ -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 shared_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_shared_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_shared()
+ {
+ }
+};
+
+shared_mutex m;
+
+int main()
+{
+ typedef boost::chrono::steady_clock Clock;
+ boost::shared_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();
+}
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/unlock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/unlock_pass.cpp
new file mode 100755
index 0000000000..1eaba78c93
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/unlock_pass.cpp
@@ -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 shared_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_shared()
+ {
+ }
+ void unlock_shared()
+ {
+ unlock_called = true;
+ }
+};
+
+shared_mutex m;
+
+int main()
+{
+ boost::shared_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();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/member_swap_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/member_swap_pass.cpp
new file mode 100755
index 0000000000..949166f58b
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/member_swap_pass.cpp
@@ -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 shared_lock;
+
+// void swap(shared_lock& u);
+
+#include <boost/thread/locks.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+struct shared_mutex
+{
+ void lock_shared()
+ {
+ }
+ void unlock_shared()
+ {
+ }
+};
+
+shared_mutex m;
+
+int main()
+{
+ boost::shared_lock<shared_mutex> lk1(m);
+ boost::shared_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();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/non_member_swap_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/non_member_swap_pass.cpp
new file mode 100755
index 0000000000..766d63ec31
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/non_member_swap_pass.cpp
@@ -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(shared_lock<Mutex>& x, shared_lock<Mutex>& y);
+
+#include <boost/thread/locks.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+struct shared_mutex
+{
+ void lock_shared()
+ {
+ }
+ void unlock_shared()
+ {
+ }
+};
+
+shared_mutex m;
+
+int main()
+{
+ boost::shared_lock<shared_mutex> lk1(m);
+ boost::shared_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();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/release_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/release_pass.cpp
new file mode 100755
index 0000000000..5a88c1f296
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/release_pass.cpp
@@ -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 shared_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_shared()
+ {
+ ++lock_count;
+ }
+ void unlock_shared()
+ {
+ ++unlock_count;
+ }
+};
+
+int shared_mutex::lock_count = 0;
+int shared_mutex::unlock_count = 0;
+
+shared_mutex m;
+
+int main()
+{
+ boost::shared_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();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/mutex_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/mutex_pass.cpp
new file mode 100755
index 0000000000..49c051be92
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/mutex_pass.cpp
@@ -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 shared_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::shared_lock<boost::shared_mutex> lk0;
+ BOOST_TEST(lk0.mutex() == 0);
+ boost::shared_lock<boost::shared_mutex> lk1(m);
+ BOOST_TEST(lk1.mutex() == &m);
+ lk1.unlock();
+ BOOST_TEST(lk1.mutex() == &m);
+
+ return boost::report_errors();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/op_bool_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/op_bool_pass.cpp
new file mode 100755
index 0000000000..71712feef5
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/op_bool_pass.cpp
@@ -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 shared_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::shared_lock < boost::shared_mutex > lk0;
+ BOOST_TEST(bool(lk0) == false);
+ boost::shared_lock < boost::shared_mutex > lk1(m);
+ BOOST_TEST(bool(lk1) == true);
+ lk1.unlock();
+ BOOST_TEST(bool(lk1) == false);
+
+ return boost::report_errors();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/owns_lock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/owns_lock_pass.cpp
new file mode 100755
index 0000000000..900300b6fa
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/owns_lock_pass.cpp
@@ -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 shared_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::shared_lock<boost::shared_mutex> lk0;
+ BOOST_TEST(lk0.owns_lock() == false);
+ boost::shared_lock<boost::shared_mutex> lk1(m);
+ BOOST_TEST(lk1.owns_lock() == true);
+ lk1.unlock();
+ BOOST_TEST(lk1.owns_lock() == false);
+
+
+ return boost::report_errors();
+}
+
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/types_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/types_pass.cpp
new file mode 100755
index 0000000000..f919586dff
--- /dev/null
+++ b/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/types_pass.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// 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/mutex.hpp>
+
+// <mutex>
+
+// template <class Mutex>
+// class shared_lock
+// {
+// public:
+// typedef Mutex mutex_type;
+// ...
+// };
+
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::shared_lock<boost::shared_mutex>::mutex_type,
+ boost::shared_mutex>::value), "");
+
+ return boost::report_errors();
+}
+