diff options
Diffstat (limited to 'libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock')
27 files changed, 1621 insertions, 0 deletions
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/adopt_lock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/adopt_lock_pass.cpp new file mode 100755 index 0000000000..865301c108 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/copy_assign_fail.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/copy_assign_fail.cpp new file mode 100755 index 0000000000..a33c5e6b54 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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); + +} + +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/upgrade_lock/cons/copy_ctor_fail.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/copy_ctor_fail.cpp new file mode 100755 index 0000000000..1a8557a5d1 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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); +} + +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/upgrade_lock/cons/default_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/default_pass.cpp new file mode 100755 index 0000000000..bd8108fb72 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/defer_lock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/defer_lock_pass.cpp new file mode 100755 index 0000000000..33a5bf8823 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/duration_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/duration_pass.cpp new file mode 100755 index 0000000000..a62438a8f6 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/duration_pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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); + +#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN + +#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::upgrade_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::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(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_assign_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_assign_pass.cpp new file mode 100755 index 0000000000..2bea7a406b --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_assign_pass.cpp @@ -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_THREAD_MAKE_RV_REF(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_THREAD_MAKE_RV_REF(boost::upgrade_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::upgrade_lock<boost::shared_mutex> lk1; + lk1 = BOOST_THREAD_MAKE_RV_REF(boost::upgrade_lock<boost::shared_mutex>(boost::unique_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/upgrade_lock/cons/move_ctor_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_pass.cpp new file mode 100755 index 0000000000..f41c7047b1 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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_THREAD_MAKE_RV_REF(boost::upgrade_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/upgrade_lock/cons/move_ctor_shared_lock_for_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_shared_lock_for_pass.cpp new file mode 100644 index 0000000000..e2abb3944f --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_shared_lock_for_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 upgrade_lock; + +// template <class Clock, class Duration> +// upgrade_lock(shared_lock<mutex_type>&&, +// const chrono::duration<Rep, Period>&); + +#define BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS +#define BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION +#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN + +#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::upgrade_lock<boost::shared_mutex> lk(boost::move(lk0), boost::chrono::milliseconds(1)); + 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::shared_lock<boost::shared_mutex>(m), boost::chrono::milliseconds(1)); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == true); + } + { + boost::shared_lock<boost::shared_mutex> lk0(m, boost::defer_lock); + boost::upgrade_lock<boost::shared_mutex> lk(boost::move(lk0), boost::chrono::milliseconds(1)); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == false); + BOOST_TEST(lk0.mutex() == 0); + BOOST_TEST(lk0.owns_lock() == false); + } + { + boost::shared_lock<boost::shared_mutex> lk0(m, boost::defer_lock); + lk0.release(); + boost::upgrade_lock<boost::shared_mutex> lk(boost::move(lk0), boost::chrono::milliseconds(1)); + 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/upgrade_lock/cons/move_ctor_shared_lock_try_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_shared_lock_try_pass.cpp new file mode 100644 index 0000000000..9cb798051e --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_shared_lock_try_pass.cpp @@ -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/locks.hpp> + +// template <class Mutex> class upgrade_lock; + +// upgrade_lock(shared_lock&& u, try_to_lock); + +#define BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS +#define BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION +#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN + +#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::upgrade_lock<boost::shared_mutex> lk(boost::move(lk0), boost::try_to_lock ); + 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::shared_lock<boost::shared_mutex>(m), boost::try_to_lock); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == true); + } + { + boost::shared_lock<boost::shared_mutex> lk0(m, boost::defer_lock); + boost::upgrade_lock<boost::shared_mutex> lk(boost::move(lk0), boost::try_to_lock); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == false); + BOOST_TEST(lk0.mutex() == 0); + BOOST_TEST(lk0.owns_lock() == false); + } + { + boost::shared_lock<boost::shared_mutex> lk0(m, boost::defer_lock); + lk0.release(); + boost::upgrade_lock<boost::shared_mutex> lk(boost::move(lk0), boost::try_to_lock); + 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/upgrade_lock/cons/move_ctor_shared_lock_until_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_shared_lock_until_pass.cpp new file mode 100644 index 0000000000..66025c6fc4 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_shared_lock_until_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 upgrade_lock; + +// template <class Clock, class Duration> +// upgrade_lock(shared_lock<mutex_type>&&, +// const chrono::time_point<Clock, Duration>&); + +#define BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS +#define BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION +#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN + +#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::upgrade_lock<boost::shared_mutex> lk( boost::move(lk0), boost::chrono::steady_clock::now()+boost::chrono::milliseconds(1)); + 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::shared_lock<boost::shared_mutex>(m), boost::chrono::steady_clock::now()+boost::chrono::milliseconds(1)); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == true); + } + { + boost::shared_lock<boost::shared_mutex> lk0(m, boost::defer_lock); + boost::upgrade_lock<boost::shared_mutex> lk( boost::move(lk0), boost::chrono::steady_clock::now()+boost::chrono::milliseconds(1)); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == false); + BOOST_TEST(lk0.mutex() == 0); + BOOST_TEST(lk0.owns_lock() == false); + } + { + boost::shared_lock<boost::shared_mutex> lk0(m, boost::defer_lock); + lk0.release(); + boost::upgrade_lock<boost::shared_mutex> lk( boost::move(lk0), boost::chrono::steady_clock::now()+boost::chrono::milliseconds(1)); + 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/upgrade_lock/cons/move_ctor_unique_lock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_unique_lock_pass.cpp new file mode 100644 index 0000000000..8afac6372a --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_unique_lock_pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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=(unique_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::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(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/mutex_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/mutex_pass.cpp new file mode 100755 index 0000000000..104a171ed9 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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; + +#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::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 +#else + //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 +#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/upgrade_lock/cons/time_point_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/time_point_pass.cpp new file mode 100755 index 0000000000..26ad92ace2 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/time_point_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 upgrade_lock; + +// template <class Clock, class Duration> +// upgrade_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time); + +#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN + +#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::upgrade_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::upgrade_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(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/try_to_lock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/try_to_lock_pass.cpp new file mode 100755 index 0000000000..9cad5cb6ac --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/try_to_lock_pass.cpp @@ -0,0 +1,103 @@ +//===----------------------------------------------------------------------===// +// +// 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, 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::upgrade_lock<boost::shared_mutex> lk(m, boost::try_to_lock); + BOOST_TEST(lk.owns_lock() == false); + } + { + boost::upgrade_lock<boost::shared_mutex> lk(m, boost::try_to_lock); + BOOST_TEST(lk.owns_lock() == false); + } + { + boost::upgrade_lock<boost::shared_mutex> lk(m, boost::try_to_lock); + BOOST_TEST(lk.owns_lock() == false); + } + while (true) + { + boost::upgrade_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 +#else +// time_point t0 = Clock::now(); +// { +// boost::upgrade_lock<boost::shared_mutex> lk(m, boost::try_to_lock); +// BOOST_TEST(lk.owns_lock() == false); +// } +// { +// boost::upgrade_lock<boost::shared_mutex> lk(m, boost::try_to_lock); +// BOOST_TEST(lk.owns_lock() == false); +// } +// { +// boost::upgrade_lock<boost::shared_mutex> lk(m, boost::try_to_lock); +// BOOST_TEST(lk.owns_lock() == false); +// } + while (true) + { + boost::upgrade_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/upgrade_lock/locking/lock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/lock_pass.cpp new file mode 100755 index 0000000000..cf95c3725e --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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; + +#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::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); + } +#else + 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); + } +#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/upgrade_lock/locking/try_lock_for_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_for_pass.cpp new file mode 100755 index 0000000000..9298e9473b --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_pass.cpp new file mode 100755 index 0000000000..1136ae48e9 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_until_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_until_pass.cpp new file mode 100755 index 0000000000..aca6708de3 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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(); +} diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/unlock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/unlock_pass.cpp new file mode 100755 index 0000000000..2116561d66 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/member_swap_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/member_swap_pass.cpp new file mode 100755 index 0000000000..e892aa6317 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/non_member_swap_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/non_member_swap_pass.cpp new file mode 100755 index 0000000000..b7983bef34 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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(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(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/release_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/release_pass.cpp new file mode 100755 index 0000000000..b5976023c2 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/mutex_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/mutex_pass.cpp new file mode 100755 index 0000000000..a730f2c2bb --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/op_bool_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/op_bool_pass.cpp new file mode 100755 index 0000000000..dedd389994 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/owns_lock_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/owns_lock_pass.cpp new file mode 100755 index 0000000000..e6969f2cbd --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 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(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/types_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/types_pass.cpp new file mode 100755 index 0000000000..660ed5ef85 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/upgrade_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 upgrade_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::upgrade_lock<boost::upgrade_mutex>::mutex_type, + boost::upgrade_mutex>::value), ""); + + return boost::report_errors(); +} + |