diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/thread/test/sync/mutual_exclusion | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/thread/test/sync/mutual_exclusion')
197 files changed, 14892 insertions, 0 deletions
diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/deque_views/single_thread_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/deque_views/single_thread_pass.cpp new file mode 100644 index 000000000..bd9ff152f --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/deque_views/single_thread_pass.cpp @@ -0,0 +1,468 @@ +// Copyright (C) 2014 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/sync_deque.hpp> + +// class sync_deque<T> + +// sync_deque(); + +#define BOOST_THREAD_VERSION 4 +//#define BOOST_THREAD_QUEUE_DEPRECATE_OLD + +#include <boost/thread/concurrent_queues/sync_deque.hpp> +#include <boost/thread/concurrent_queues/deque_adaptor.hpp> +#include <boost/thread/concurrent_queues/deque_views.hpp> + +#include <boost/detail/lightweight_test.hpp> +#include <boost/static_assert.hpp> + +class non_copyable +{ + int val; +public: + BOOST_THREAD_MOVABLE_ONLY(non_copyable) + non_copyable(int v) : val(v){} + non_copyable(BOOST_RV_REF(non_copyable) x): val(x.val) {} + non_copyable& operator=(BOOST_RV_REF(non_copyable) x) { val=x.val; return *this; } + bool operator==(non_copyable const& x) const {return val==x.val;} + template <typename OSTREAM> + friend OSTREAM& operator <<(OSTREAM& os, non_copyable const&x ) + { + os << x.val; + return os; + } + +}; + +#if defined BOOST_NO_CXX11_RVALUE_REFERENCES +BOOST_STATIC_ASSERT( ! boost::is_copy_constructible<non_copyable>::value ); +BOOST_STATIC_ASSERT( boost::has_move_emulation_enabled<non_copyable>::value ); +#endif + +int main() +{ + + { + // default queue invariants + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_back<int> q(sq); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // default queue invariants + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_front<int> q(sq); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + + + { + // empty queue try_pull fails + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_front<int> q(sq); + int i; + BOOST_TEST( boost::queue_op_status::empty == q.try_pull(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push rvalue/copyable succeeds + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_back<int> q(sq); + q.push(1); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push lvalue/copyable succeeds + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_back<int> q(sq); + int i; + q.push(i); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + + +#if 0 + { + // empty queue push rvalue/non_copyable succeeds + boost::deque_adaptor<boost::sync_deque<non_copyable> > sq; + boost::deque_back<non_copyable> q(sq); + q.push(non_copyable(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) + { + // empty queue push rvalue/non_copyable succeeds + boost::deque_adaptor<boost::sync_deque<non_copyable> > q; + //boost::sync_deque<non_copyable> q; + //boost::deque_back<non_copyable> q(sq); + non_copyable nc(1); + q.push_back(boost::move(nc)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + { + // empty queue push rvalue succeeds + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_back<int> q(sq); + q.push(1); + q.push(2); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 2u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push lvalue succeeds + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_back<int> q(sq); + int i; + q.push(i); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue/copyable succeeds + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_back<int> q(sq); + BOOST_TEST(boost::queue_op_status::success == q.try_push(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue/copyable succeeds + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_back<int> q(sq); + BOOST_TEST(boost::queue_op_status::success == q.try_push(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + +#if 0 + { + // empty queue try_push rvalue/non-copyable succeeds + boost::deque_adaptor<boost::sync_deque<non_copyable> > sq; + boost::deque_back<non_copyable> q(sq); + non_copyable nc(1); + BOOST_TEST(boost::queue_op_status::success == q.try_push(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + + { + // empty queue try_push lvalue succeeds + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_back<int> q(sq); + int i=0; + BOOST_TEST(boost::queue_op_status::success == q.try_push(i)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue succeeds + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_back<int> q(sq); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + + +#if 0 + { + // empty queue nonblocking_push_back rvalue/non-copyable succeeds + boost::deque_adaptor<boost::sync_deque<non_copyable> > sq; + boost::deque_back<non_copyable> q(sq); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(non_copyable(1))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) + { + // empty queue nonblocking_push_back rvalue/non-copyable succeeds + boost::deque_adaptor<boost::sync_deque<non_copyable> > sq; + boost::deque_back<non_copyable> q(sq); + non_copyable nc(1); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + { + // 1-element queue pull_front succeed + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_front<int> q(sq); + sq.push_back(1); + int i; + q.pull(i); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) + { + // 1-element queue pull_front succeed + boost::deque_adaptor<boost::sync_deque<non_copyable> > sq; + boost::deque_front<non_copyable> q(sq); + non_copyable nc1(1); + sq.push_back(boost::move(nc1)); + non_copyable nc2(2); + q.pull(nc2); + BOOST_TEST_EQ(nc1, nc2); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#endif + { + // 1-element queue pull_front succeed + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_front<int> q(sq); + sq.push_back(1); + int i = q.pull(); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) + { + // 1-element queue pull_front succeed + boost::deque_adaptor<boost::sync_deque<non_copyable> > sq; + boost::deque_front<non_copyable> q(sq); + non_copyable nc1(1); + sq.push_back(boost::move(nc1)); + non_copyable nc = q.pull(); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#endif + { + // 1-element queue try_pull_front succeed + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_front<int> q(sq); + sq.push_back(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.try_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) + { + // 1-element queue try_pull_front succeed + boost::deque_adaptor<boost::sync_deque<non_copyable> > sq; + boost::deque_front<non_copyable> q(sq); + non_copyable nc1(1); + sq.push_back(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.try_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#endif + + { + // 1-element queue nonblocking_pull_front succeed + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_front<int> q(sq); + sq.push_back(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) + { + // 1-element queue nonblocking_pull_front succeed + boost::deque_adaptor<boost::sync_deque<non_copyable> > sq; + boost::deque_front<non_copyable> q(sq); + non_copyable nc1(1); + sq.push_back(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue wait_pull_front succeed + boost::deque_adaptor<boost::sync_deque<non_copyable> > sq; + boost::deque_front<non_copyable> q(sq); + non_copyable nc1(1); + sq.push_back(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#endif + { + // 1-element queue wait_pull_front succeed + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_front<int> q(sq); + sq.push_back(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) + { + // 1-element queue wait_pull_front succeed + boost::deque_adaptor<boost::sync_deque<non_copyable> > sq; + boost::deque_front<non_copyable> q(sq); + non_copyable nc1(1); + sq.push_back(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#endif + { + // closed invariants + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_back<int> q(sq); + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed invariants + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_front<int> q(sq); + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed queue push fails + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_back<int> q(sq); + q.close(); + try { + q.push(1); + BOOST_TEST(false); + } catch (...) { + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + } + { + // 1-element closed queue pull succeed + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_front<int> q(sq); + sq.push_back(1); + q.close(); + int i; + q.pull(i); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // 1-element closed queue wait_pull_front succeed + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_front<int> q(sq); + sq.push_back(1); + q.close(); + int i; + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed empty queue wait_pull_front fails + boost::deque_adaptor<boost::sync_deque<int> > sq; + boost::deque_front<int> q(sq); + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + int i; + BOOST_TEST(boost::queue_op_status::closed == q.wait_pull(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + } + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/adopt_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/adopt_lock_pass.cpp new file mode 100644 index 000000000..b6039c556 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/adopt_lock_pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// 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) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/locks.hpp> + +// template <class Mutex> class lock_guard; + +// lock_guard(mutex_type& m, adopt_lock_t); + +#include <boost/thread/lock_guard.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../timming.hpp" + +#ifdef BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#endif +boost::mutex m; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#ifdef BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + { + m.lock(); + boost::lock_guard<boost::mutex> lg(m, boost::adopt_lock); + t1 = Clock::now(); + } +#else + //time_point t0 = Clock::now(); + //time_point t1; + { + m.lock(); + boost::lock_guard<boost::mutex> lg(m, boost::adopt_lock); + //t1 = Clock::now(); + } + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#ifdef BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/copy_assign_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/copy_assign_fail.cpp new file mode 100644 index 000000000..a3957c750 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/copy_assign_fail.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 lock_guard; + +// lock_guard& operator=(lock_guard const&) = delete; + +#include <boost/thread/lock_guard.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m0; +boost::mutex m1; + +int main() +{ + boost::lock_guard<boost::mutex> lk0(m0); + boost::lock_guard<boost::mutex> lk1(m1); + lk1 = lk0; + +} + +#include "../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/copy_ctor_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/copy_ctor_fail.cpp new file mode 100644 index 000000000..5c1b3a1c2 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/copy_ctor_fail.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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 lock_guard; + +// lock_guard(lock_guard const&) = delete; + + +#include <boost/thread/lock_guard.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m0; +boost::mutex m1; + +int main() +{ + boost::lock_guard<boost::mutex> lk0(m0); + boost::lock_guard<boost::mutex> lk1 = lk0; +} + +#include "../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/default_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/default_pass.cpp new file mode 100644 index 000000000..4fcc26a9b --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/default_pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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 lock_guard; + +// lock_guard(Mutex &); + +#include <boost/thread/lock_guard.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../timming.hpp" + +#ifdef BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#endif + +boost::mutex m; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#ifdef BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + { + boost::lock_guard<boost::mutex> lg(m); + t1 = Clock::now(); + } +#else + //time_point t0 = Clock::now(); + //time_point t1; + { + boost::lock_guard<boost::mutex> lg(m); + //t1 = Clock::now(); + } + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#ifdef BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/lock_guard_adopt_lock_compile_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/lock_guard_adopt_lock_compile_fail.cpp new file mode 100644 index 000000000..9aab78ddd --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/lock_guard_adopt_lock_compile_fail.cpp @@ -0,0 +1,21 @@ +// Copyright (C) 2018 Tom Hughes +// +// 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/lock_guard.hpp> + +// template <class Mutex> class lock_guard; + +// lock_guard(Mutex& m_, adopt_lock_t) + +#include <boost/thread/lock_guard.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m; + +void fail() +{ + boost::lock_guard<boost::mutex> lk(m, boost::adopt_lock); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/lock_guard_adopt_lock_compile_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/lock_guard_adopt_lock_compile_pass.cpp new file mode 100644 index 000000000..a158677ad --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/lock_guard_adopt_lock_compile_pass.cpp @@ -0,0 +1,22 @@ +// Copyright (C) 2018 Tom Hughes +// +// 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/lock_guard.hpp> + +// template <class Mutex> class lock_guard; + +// lock_guard(Mutex& m_, adopt_lock_t) + +#include <boost/thread/lock_guard.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m; + +void pass() +{ + m.lock(); + boost::lock_guard<boost::mutex> lk(m, boost::adopt_lock); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/lock_guard_compile_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/lock_guard_compile_fail.cpp new file mode 100644 index 000000000..eead4501c --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/lock_guard_compile_fail.cpp @@ -0,0 +1,22 @@ +// Copyright (C) 2018 Tom Hughes +// +// 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/lock_guard.hpp> + +// template <class Mutex> class lock_guard; + +// lock_guard(Mutex& m_) + +#include <boost/thread/lock_guard.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m; + +void fail() +{ + boost::lock_guard<boost::mutex> lk0(m); + boost::lock_guard<boost::mutex> lk1(m); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/lock_guard_compile_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/lock_guard_compile_pass.cpp new file mode 100644 index 000000000..aee2e40e4 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/lock_guard_compile_pass.cpp @@ -0,0 +1,24 @@ +// Copyright (C) 2018 Tom Hughes +// +// 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/lock_guard.hpp> + +// template <class Mutex> class lock_guard; + +// lock_guard(Mutex& m_) + +#include <boost/thread/lock_guard.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m; + +void pass() +{ + { + boost::lock_guard<boost::mutex> lk0(m); + } + boost::lock_guard<boost::mutex> lk1(m); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/make_lock_guard_adopt_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/make_lock_guard_adopt_lock_pass.cpp new file mode 100644 index 000000000..cecdc84ce --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/make_lock_guard_adopt_lock_pass.cpp @@ -0,0 +1,93 @@ +//===----------------------------------------------------------------------===// +// +// 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) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/lock_guard.hpp> + +// template <class Lockable> +// lock_guard<Lockable> make_lock_guard(Lockable &, adopt_lock_t); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/lock_guard.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../timming.hpp" + + +#ifdef BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#endif +boost::mutex m; + +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_LOCK_GUARD + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#ifdef BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + { + m.lock(); + auto&& lg = boost::make_lock_guard(m, boost::adopt_lock); (void)lg; + + t1 = Clock::now(); + } +#else + //time_point t0 = Clock::now(); + //time_point t1; + { + m.lock(); + auto&& lg = boost::make_lock_guard(m, boost::adopt_lock); (void)lg; + //t1 = Clock::now(); + } + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} +#endif + +int main() +{ +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_LOCK_GUARD + m.lock(); + boost::thread t(f); +#ifdef BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + +#endif + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/make_lock_guard_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/make_lock_guard_pass.cpp new file mode 100644 index 000000000..853fae743 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/make_lock_guard_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/lock_guard.hpp> + +// template <class Lockable> +// lock_guard<Lockable> make_lock_guard(Lockable &); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/lock_guard.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> + +#include <boost/detail/lightweight_test.hpp> +#include "../../../../timming.hpp" + +#ifdef BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#endif + +boost::mutex m; + +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_LOCK_GUARD && defined BOOST_THREAD_USES_CHRONO + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ + t0 = Clock::now(); + { + const auto&& lg = boost::make_lock_guard(m); (void)lg; + t1 = Clock::now(); + } +} +#endif + +int main() +{ + +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_LOCK_GUARD && defined BOOST_THREAD_USES_CHRONO + { + m.lock(); + boost::thread t(f); + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); + m.unlock(); + t.join(); + + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); + } +#endif + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/types_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/types_pass.cpp new file mode 100644 index 000000000..7c2d39375 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/lock_guard/types_pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/mutex.hpp> + +// <mutex> + +// template <class Mutex> +// class lock_guard +// { +// public: +// typedef Mutex mutex_type; +// ... +// }; + + +#include <boost/thread/lock_guard.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/static_assert.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::lock_guard<boost::mutex>::mutex_type, + boost::mutex>::value), ""); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/copy_assign_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/copy_assign_fail.cpp new file mode 100644 index 000000000..c5d9a39b5 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/copy_assign_fail.cpp @@ -0,0 +1,31 @@ +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/locks.hpp> + +// template <class Mutex> class nested_strict_lock; + +// nested_strict_lock& operator=(nested_strict_lock const&) = delete; + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/strict_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m0; +boost::mutex m1; + +int main() +{ + boost::unique_lock<boost::mutex> lk0(m0); + boost::unique_lock<boost::mutex> lk1(m1); + boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlk0(lk0); + boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlk1(lk1); + lk1 = lk0; + +} + +#include "../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/copy_ctor_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/copy_ctor_fail.cpp new file mode 100644 index 000000000..1c0abf94a --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/copy_ctor_fail.cpp @@ -0,0 +1,28 @@ +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/locks.hpp> + +// template <class Mutex> class nested_strict_lock; + +// nested_strict_lock(nested_strict_lock const&) = delete; + + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/strict_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m0; +boost::mutex m1; + +int main() +{ + boost::nested_strict_lock<boost::unique_lock<boost::mutex> > lk0(m0); + boost::nested_strict_lock<boost::unique_lock<boost::mutex> > lk1 = lk0; +} + +#include "../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/default_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/default_pass.cpp new file mode 100644 index 000000000..0182bdd95 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/default_pass.cpp @@ -0,0 +1,79 @@ +// Copyright (C) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/locks.hpp> + +// template <class Mutex> class nested_strict_lock; + +// nested_strict_lock(Mutex &); + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/strict_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../timming.hpp" + +#ifdef BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#endif + +boost::mutex m; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#ifdef BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + boost::unique_lock<boost::mutex> lg(m); + { + boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlg(lg); + t1 = Clock::now(); + } +#else + //time_point t0 = Clock::now(); + //time_point t1; + boost::unique_lock<boost::mutex> lg(m); + { + boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlg(lg); + //t1 = Clock::now(); + } + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + { + m.lock(); + boost::thread t(f); +#ifdef BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/make_nested_strict_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/make_nested_strict_lock_pass.cpp new file mode 100644 index 000000000..5a10728cb --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/make_nested_strict_lock_pass.cpp @@ -0,0 +1,70 @@ +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/strict_lock.hpp> + +// template <class Lockable> +// strict_lock<Lockable> make_strict_lock(Lockable &); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/strict_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> + +#include <boost/detail/lightweight_test.hpp> +#include "../../../../timming.hpp" + +#ifdef BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#endif + +boost::mutex m; + +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_NESTED_STRICT_LOCK && defined BOOST_THREAD_USES_CHRONO + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ + t0 = Clock::now(); + boost::unique_lock<boost::mutex> lg(m); + { + const auto&& nlg = boost::make_nested_strict_lock(lg); (void)nlg; + t1 = Clock::now(); + } +} +#endif + +int main() +{ + +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_NESTED_STRICT_LOCK && defined BOOST_THREAD_USES_CHRONO + { + m.lock(); + boost::thread t(f); + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); + m.unlock(); + t.join(); + + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); + } +#endif + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/owns_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/owns_lock_pass.cpp new file mode 100644 index 000000000..be06b6a06 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/owns_lock_pass.cpp @@ -0,0 +1,60 @@ +// Copyright (C) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/locks.hpp> + +// template <class Mutex> class nested_strict_lock; + +// bool owns_lock(Mutex *) const; + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/strict_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::mutex m; + boost::mutex m2; + { + boost::unique_lock<boost::mutex> lk(m); + { + boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlk(lk); + BOOST_TEST(nlk.owns_lock(&m) == true); + BOOST_TEST(!nlk.owns_lock(&m2) == true); + } + BOOST_TEST(lk.owns_lock() == true && lk.mutex()==&m); + } + { + m.lock(); + boost::unique_lock<boost::mutex> lk(m, boost::adopt_lock); + { + boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlk(lk); + BOOST_TEST(nlk.owns_lock(&m) == true); + BOOST_TEST(!nlk.owns_lock(&m2) == true); + } + BOOST_TEST(lk.owns_lock() == true && lk.mutex()==&m); + } + { + boost::unique_lock<boost::mutex> lk(m, boost::defer_lock); + { + boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlk(lk); + BOOST_TEST(nlk.owns_lock(&m) == true); + BOOST_TEST(!nlk.owns_lock(&m2) == true); + } + BOOST_TEST(lk.owns_lock() == true && lk.mutex()==&m); + } + { + boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock); + { + boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlk(lk); + BOOST_TEST(nlk.owns_lock(&m) == true); + BOOST_TEST(!nlk.owns_lock(&m2) == true); + } + BOOST_TEST(lk.owns_lock() == true && lk.mutex()==&m); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/types_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/types_pass.cpp new file mode 100644 index 000000000..5a7c690e4 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/types_pass.cpp @@ -0,0 +1,35 @@ +// Copyright (C) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/mutex.hpp> + +// <mutex> + +// template <class Lock> +// class nested_strict_lock +// { +// public: +// typedef typename Lock::mutex_type mutex_type; +// ... +// }; + + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/strict_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/static_assert.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::nested_strict_lock<boost::unique_lock<boost::mutex> >::mutex_type, + boost::mutex>::value), ""); + + BOOST_STATIC_ASSERT_MSG((boost::is_strict_lock<boost::nested_strict_lock<boost::unique_lock<boost::mutex> > >::value), ""); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp new file mode 100644 index 000000000..408e0f267 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp @@ -0,0 +1,33 @@ +// Copyright (C) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/locks.hpp> + +// template <class Mutex> class reverse_lock; + +// reverse_lock& operator=(reverse_lock const&) = delete; + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/reverse_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/lock_types.hpp> + + +int main() +{ + boost::mutex m0; + boost::mutex m1; + boost::unique_lock<boost::mutex> lk0(m0); + boost::unique_lock<boost::mutex> lk1(m1); + { + boost::reverse_lock<boost::unique_lock<boost::mutex> > lg0(lk0); + boost::reverse_lock<boost::unique_lock<boost::mutex> > lg1(lk1); + lg1 = lg0; + } + +} + +#include "../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_ctor_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_ctor_fail.cpp new file mode 100644 index 000000000..c936c11b8 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_ctor_fail.cpp @@ -0,0 +1,32 @@ +// Copyright (C) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/locks.hpp> + +// template <class Mutex> class reverse_lock; + +// reverse_lock(reverse_lock const&) = delete; + + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/reverse_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/lock_types.hpp> + +boost::mutex m0; +boost::mutex m1; + +int main() +{ + boost::mutex m0; + boost::unique_lock<boost::mutex> lk0(m0); + { + boost::reverse_lock<boost::unique_lock<boost::mutex> > lg0(lk0); + boost::reverse_lock<boost::unique_lock<boost::mutex> > lg1(lg0); + } +} + +#include "../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp new file mode 100644 index 000000000..13a17fd3a --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp @@ -0,0 +1,34 @@ +// Copyright (C) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/mutex.hpp> + +// <mutex> + +// template <class Mutex> +// class unlock_guard +// { +// public: +// typedef Mutex mutex_type; +// ... +// }; + + +#include <boost/thread/mutex.hpp> +#include <boost/thread/reverse_lock.hpp> +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/static_assert.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::reverse_lock<boost::unique_lock<boost::mutex> >::mutex_type, + boost::mutex>::value), ""); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/unique_lock_ctor_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/unique_lock_ctor_pass.cpp new file mode 100644 index 000000000..57a1f1e01 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/unique_lock_ctor_pass.cpp @@ -0,0 +1,52 @@ +// Copyright (C) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/locks.hpp> + +// template <class Mutex> class unlock_guard; + +// unlock_guard(unlock_guard const&) = delete; + +#include <boost/thread/reverse_lock.hpp> +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> + + +int main() +{ + { + boost::mutex m; + boost::unique_lock<boost::mutex> lk(m); + BOOST_TEST(lk.owns_lock()); + BOOST_TEST(lk.mutex()==&m); + + { + boost::reverse_lock<boost::unique_lock<boost::mutex> > lg(lk); + BOOST_TEST(!lk.owns_lock()); + BOOST_TEST(lk.mutex()==0); + } + BOOST_TEST(lk.owns_lock()); + BOOST_TEST(lk.mutex()==&m); + } + + { + boost::mutex m; + boost::unique_lock<boost::mutex> lk(m, boost::defer_lock); + BOOST_TEST(! lk.owns_lock()); + BOOST_TEST(lk.mutex()==&m); + { + boost::reverse_lock<boost::unique_lock<boost::mutex> > lg(lk); + BOOST_TEST(!lk.owns_lock()); + BOOST_TEST(lk.mutex()==0); + } + BOOST_TEST(lk.owns_lock()); + BOOST_TEST(lk.mutex()==&m); + } + + + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/adopt_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/adopt_lock_pass.cpp new file mode 100644 index 000000000..f9089e7a8 --- /dev/null +++ b/src/boost/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/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + + +int main() +{ + boost::shared_mutex m; + m.lock_shared(); + 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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/copy_assign_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/copy_assign_fail.cpp new file mode 100644 index 000000000..2bc99f34b --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/copy_assign_fail.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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/lock_types.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); + +} + +#include "../../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/copy_ctor_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/copy_ctor_fail.cpp new file mode 100644 index 000000000..43fddebe8 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/copy_ctor_fail.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/locks.hpp> + +// template <class Mutex> class shared_lock; + +// shared_lock(shared_lock const&) = delete; + + +#include <boost/thread/lock_types.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); +} + +#include "../../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/default_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/default_pass.cpp new file mode 100644 index 000000000..9ccae93b7 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/defer_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/defer_lock_pass.cpp new file mode 100644 index 000000000..84388aca4 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/duration_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/duration_pass.cpp new file mode 100644 index 000000000..45037c224 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/duration_pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// 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/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/chrono/chrono_io.hpp> +#include "../../../../../timming.hpp" + +boost::shared_mutex m; + +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f1() +{ + t0 = Clock::now(); + boost::shared_lock<boost::shared_mutex> lk(m, ms(750)); + BOOST_TEST(lk.owns_lock() == true); + t1 = Clock::now(); +} + +void f2() +{ + t0 = Clock::now(); + boost::shared_lock<boost::shared_mutex> lk(m, ms(250)); + BOOST_TEST(lk.owns_lock() == false); + t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); + m.unlock(); + t.join(); + + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(750)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_assign_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_assign_pass.cpp new file mode 100644 index 000000000..ef54e229f --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_pass.cpp new file mode 100644 index 000000000..307c76142 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_unique_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_unique_lock_pass.cpp new file mode 100644 index 000000000..38f6e7d7d --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_upgrade_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_upgrade_lock_pass.cpp new file mode 100644 index 000000000..36ecb6a5a --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/mutex_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/mutex_pass.cpp new file mode 100644 index 000000000..f50aa6199 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/mutex_pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// 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/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../../timming.hpp" + +boost::shared_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + { + boost::shared_lock<boost::shared_mutex> ul(m); + t1 = Clock::now(); + } +#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); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/time_point_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/time_point_pass.cpp new file mode 100644 index 000000000..41d9cd8f9 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/time_point_pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// 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/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../../timming.hpp" + +boost::shared_mutex m; + +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f1() +{ + t0 = Clock::now(); + boost::shared_lock<boost::shared_mutex> lk(m, Clock::now() + ms(750)); + BOOST_TEST(lk.owns_lock() == true); + t1 = Clock::now(); +} + +void f2() +{ + t0 = Clock::now(); + boost::shared_lock<boost::shared_mutex> lk(m, Clock::now() + ms(250)); + BOOST_TEST(lk.owns_lock() == false); + t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); + m.unlock(); + t.join(); + + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(750)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/try_to_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/try_to_lock_pass.cpp new file mode 100644 index 000000000..5f3036c0c --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/try_to_lock_pass.cpp @@ -0,0 +1,115 @@ +//===----------------------------------------------------------------------===// +// +// 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/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../../timming.hpp" + +boost::shared_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + 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); + } + for (;;) + { + boost::shared_lock<boost::shared_mutex> lk(m, boost::try_to_lock); + if (lk.owns_lock()) { + t1 = Clock::now(); + break; + } + } +#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); +// } + for (;;) + { + 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); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/lock_pass.cpp new file mode 100644 index 000000000..456c26dfd --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/lock_pass.cpp @@ -0,0 +1,126 @@ +//===----------------------------------------------------------------------===// +// +// 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/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <iostream> +#include "../../../../../timming.hpp" + +boost::shared_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + boost::shared_lock < boost::shared_mutex > lk(m, boost::defer_lock); + t0 = Clock::now(); + lk.lock(); + t1 = Clock::now(); + BOOST_TEST(lk.owns_lock() == true); + 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); + //BOOST_TEST(d < max_diff); + 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 + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_for_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_for_pass.cpp new file mode 100644 index 000000000..07d32df39 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_pass.cpp new file mode 100644 index 000000000..6a1997238 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_until_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/try_lock_until_pass.cpp new file mode 100644 index 000000000..cdfd0e161 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/unlock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/locking/unlock_pass.cpp new file mode 100644 index 000000000..e8ed7c74c --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/member_swap_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/member_swap_pass.cpp new file mode 100644 index 000000000..11f366bd6 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/non_member_swap_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/non_member_swap_pass.cpp new file mode 100644 index 000000000..c0ccb8b9d --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/release_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/mod/release_pass.cpp new file mode 100644 index 000000000..c39ca50aa --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/mutex_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/mutex_pass.cpp new file mode 100644 index 000000000..2012186ae --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/op_bool_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/op_bool_pass.cpp new file mode 100644 index 000000000..407bfcc6f --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/owns_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/obs/owns_lock_pass.cpp new file mode 100644 index 000000000..dce14d3e9 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/types_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/types_pass.cpp new file mode 100644 index 000000000..2f83ef98f --- /dev/null +++ b/src/boost/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/lock_types.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(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/adopt_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/adopt_lock_pass.cpp new file mode 100644 index 000000000..fe125e8a0 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/adopt_lock_pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/shared_lock_guard.hpp> + +// template <class Mutex> class shared_lock_guard; + +// shared_lock_guard(mutex_type& m, adopt_lock_t); + +#include <boost/thread/shared_lock_guard.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../timming.hpp" + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +boost::shared_mutex m; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + { + m.lock_shared(); + boost::shared_lock_guard<boost::shared_mutex> lg(m, boost::adopt_lock); + t1 = Clock::now(); + } +#else + //time_point t0 = Clock::now(); + //time_point t1; + { + m.lock_shared(); + boost::shared_lock_guard<boost::shared_mutex> lg(m, boost::adopt_lock); + //t1 = Clock::now(); + } + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_assign_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_assign_fail.cpp new file mode 100644 index 000000000..43607ac26 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_assign_fail.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/shared_lock_guard.hpp> + +// template <class Mutex> class shared_lock_guard; + +// shared_lock_guard& operator=(shared_lock_guard const&) = delete; + +#include <boost/thread/shared_lock_guard.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_guard<boost::shared_mutex> lk0(m0); + boost::shared_lock_guard<boost::shared_mutex> lk1(m1); + lk1 = lk0; + +} + +#include "../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_ctor_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_ctor_fail.cpp new file mode 100644 index 000000000..a7d4f006d --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_ctor_fail.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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_lock_guard.hpp> + +// template <class Mutex> class shared_lock_guard; + +// shared_lock_guard(shared_lock_guard const&) = delete; + + +#include <boost/thread/shared_lock_guard.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_guard<boost::shared_mutex> lk0(m0); + boost::shared_lock_guard<boost::shared_mutex> lk1 = lk0; +} + +#include "../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/default_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/default_pass.cpp new file mode 100644 index 000000000..694ba4a14 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/default_pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// 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_lock_guard.hpp> + +// template <class Mutex> class shared_lock_guard; + +// shared_lock_guard(shared_lock_guard const&) = delete; + +#include <boost/thread/shared_lock_guard.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <iostream> +#include "../../../../timming.hpp" + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +boost::shared_mutex m; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + { + boost::shared_lock_guard<boost::shared_mutex> lg(m); + t1 = Clock::now(); + } +#else + //time_point t0 = Clock::now(); + //time_point t1; + { + boost::shared_lock_guard<boost::shared_mutex> lg(m); + //t1 = Clock::now(); + } + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/types_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/types_pass.cpp new file mode 100644 index 000000000..57a2116d1 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/types_pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/shared_lock_guard.hpp> + +// <mutex> + +// template <class Mutex> +// class shared_lock_guard +// { +// public: +// typedef Mutex mutex_type; +// ... +// }; + + +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/shared_lock_guard.hpp> +#include <boost/static_assert.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::shared_lock_guard<boost::shared_mutex>::mutex_type, + boost::shared_mutex>::value), ""); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/copy_assign_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/copy_assign_fail.cpp new file mode 100644 index 000000000..1852224bb --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/copy_assign_fail.cpp @@ -0,0 +1,28 @@ +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/locks.hpp> + +// template <class Mutex> class strict_lock; + +// strict_lock& operator=(strict_lock const&) = delete; + +#include <boost/thread/strict_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m0; +boost::mutex m1; + +int main() +{ + boost::strict_lock<boost::mutex> lk0(m0); + boost::strict_lock<boost::mutex> lk1(m1); + lk1 = lk0; + +} + +#include "../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/copy_ctor_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/copy_ctor_fail.cpp new file mode 100644 index 000000000..331610cb1 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/copy_ctor_fail.cpp @@ -0,0 +1,27 @@ +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/locks.hpp> + +// template <class Mutex> class strict_lock; + +// strict_lock(strict_lock const&) = delete; + + +#include <boost/thread/strict_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m0; +boost::mutex m1; + +int main() +{ + boost::strict_lock<boost::mutex> lk0(m0); + boost::strict_lock<boost::mutex> lk1 = lk0; +} + +#include "../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/default_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/default_pass.cpp new file mode 100644 index 000000000..aa2fb0071 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/default_pass.cpp @@ -0,0 +1,74 @@ +// Copyright (C) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/locks.hpp> + +// template <class Mutex> class strict_lock; + +// strict_lock(Mutex &); + +#include <boost/thread/strict_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../timming.hpp" + +#ifdef BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#endif + +boost::mutex m; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#ifdef BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + { + boost::strict_lock<boost::mutex> lg(m); + t1 = Clock::now(); + } +#else + //time_point t0 = Clock::now(); + //time_point t1; + { + boost::strict_lock<boost::mutex> lg(m); + //t1 = Clock::now(); + } + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#ifdef BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/make_strict_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/make_strict_lock_pass.cpp new file mode 100644 index 000000000..c5a3069f0 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/make_strict_lock_pass.cpp @@ -0,0 +1,70 @@ +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/strict_lock.hpp> + +// template <class Lockable> +// strict_lock<Lockable> make_strict_lock(Lockable &); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/strict_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> + +#include <boost/detail/lightweight_test.hpp> +#include "../../../../timming.hpp" + +#ifdef BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#endif + +boost::mutex m; + +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_STRICT_LOCK && defined BOOST_THREAD_USES_CHRONO + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ + t0 = Clock::now(); + { + const auto&& lg = boost::make_strict_lock(m); (void)lg; + t1 = Clock::now(); + } + ns d = t1 - t0 - ms(250); + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +} +#endif + +int main() +{ + +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_STRICT_LOCK && defined BOOST_THREAD_USES_CHRONO + { + m.lock(); + boost::thread t(f); + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); + m.unlock(); + t.join(); + + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); + } +#endif + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/owns_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/owns_lock_pass.cpp new file mode 100644 index 000000000..c0c2ec861 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/owns_lock_pass.cpp @@ -0,0 +1,34 @@ +// Copyright (C) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/locks.hpp> + +// template <class Mutex> class strict_lock; + +// bool owns_lock(Mutex *) const; + +#include <boost/thread/strict_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> + +#ifdef BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +#endif + +int main() +{ + boost::mutex m; + boost::mutex m2; + + boost::strict_lock<boost::mutex> lk(m); + BOOST_TEST(lk.owns_lock(&m) == true); + BOOST_TEST(!lk.owns_lock(&m2) == true); + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/types_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/types_pass.cpp new file mode 100644 index 000000000..f813e5ca8 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/strict_lock/types_pass.cpp @@ -0,0 +1,34 @@ +// Copyright (C) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/mutex.hpp> + +// <mutex> + +// template <class Mutex> +// class strict_lock +// { +// public: +// typedef Mutex mutex_type; +// ... +// }; + + +#include <boost/thread/strict_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/static_assert.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::strict_lock<boost::mutex>::mutex_type, + boost::mutex>::value), ""); + + BOOST_STATIC_ASSERT_MSG((boost::is_strict_lock<boost::strict_lock<boost::mutex> >::value), ""); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/adopt_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/adopt_lock_pass.cpp new file mode 100644 index 000000000..42d33378e --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/adopt_lock_pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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 unique_lock; + +// unique_lock(mutex_type& m, adopt_lock_t); + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + + +int main() +{ + boost::mutex m; + m.lock(); + boost::unique_lock<boost::mutex> lk(m, boost::adopt_lock); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == true); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/copy_assign_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/copy_assign_fail.cpp new file mode 100644 index 000000000..d69a1eec7 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/copy_assign_fail.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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 unique_lock; + +// unique_lock& operator=(unique_lock const&) = delete; + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m0; +boost::mutex m1; + +int main() +{ + boost::unique_lock<boost::mutex> lk0(m0); + boost::unique_lock<boost::mutex> lk1(m1); + lk1 = lk0; + BOOST_TEST(lk1.mutex() == &m0); + BOOST_TEST(lk1.owns_lock() == true); + BOOST_TEST(lk0.mutex() == 0); + BOOST_TEST(lk0.owns_lock() == false); + +} + +#include "../../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/copy_ctor_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/copy_ctor_fail.cpp new file mode 100644 index 000000000..08fc3c344 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/copy_ctor_fail.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/locks.hpp> + +// template <class Mutex> class unique_lock; + +// unique_lock(unique_lock const&) = delete; + + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m0; +boost::mutex m1; + +int main() +{ + boost::unique_lock<boost::mutex> lk0(m0); + boost::unique_lock<boost::mutex> lk1 = lk0; + BOOST_TEST(lk1.mutex() == &m1); + BOOST_TEST(lk1.owns_lock() == true); + BOOST_TEST(lk0.mutex() == 0); + BOOST_TEST(lk0.owns_lock() == false); +} + +#include "../../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/default_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/default_pass.cpp new file mode 100644 index 000000000..7989b8173 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_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 unique_lock; + +// unique_lock(unique_lock const&) = delete; + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::unique_lock<boost::mutex> ul; + BOOST_TEST(!ul.owns_lock()); + BOOST_TEST(ul.mutex() == 0); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/defer_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/defer_lock_pass.cpp new file mode 100644 index 000000000..5045af26e --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/defer_lock_pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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 unique_lock; + +// unique_lock(mutex_type& m, adopt_lock_t); + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::mutex m; + boost::unique_lock<boost::mutex> lk(m, boost::defer_lock); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == false); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/duration_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/duration_pass.cpp new file mode 100644 index 000000000..19aa0575f --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/duration_pass.cpp @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// 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 unique_lock; + +// template <class Rep, class Period> +// unique_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time); + +#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/chrono/chrono_io.hpp> +#include "../../../../../timming.hpp" + +#if defined BOOST_THREAD_USES_CHRONO + +boost::timed_mutex m; + +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f1() +{ + t0 = Clock::now(); + boost::unique_lock<boost::timed_mutex> lk(m, ms(750)); + BOOST_TEST(lk.owns_lock() == true); + t1 = Clock::now(); +} + +void f2() +{ + t0 = Clock::now(); + boost::unique_lock<boost::timed_mutex> lk(m, ms(250)); + BOOST_TEST(lk.owns_lock() == false); + t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); + m.unlock(); + t.join(); + + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(750)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + +#else +#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported" +#endif diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_adopt_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_adopt_lock_pass.cpp new file mode 100644 index 000000000..2f385ec87 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_adopt_lock_pass.cpp @@ -0,0 +1,31 @@ +// Copyright (C) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/lock_factories.hpp> + +// template <class Mutex> class unique_lock; +// unique_lock<Mutex> make_unique_lock(Mutex&, adopt_lock_t); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/lock_factories.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::mutex m; + m.lock(); +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) + auto +#else + boost::unique_lock<boost::mutex> +#endif + lk = boost::make_unique_lock(m, boost::adopt_lock); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == true); + + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_defer_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_defer_lock_pass.cpp new file mode 100644 index 000000000..e32fad168 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_defer_lock_pass.cpp @@ -0,0 +1,32 @@ +// Copyright (C) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/lock_factories.hpp> + +// template <class Mutex> class unique_lock; +// unique_lock<Mutex> make_unique_lock(Mutex&, defer_lock_t); + +// unique_lock(mutex_type& m, adopt_lock_t); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/lock_factories.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::mutex m; +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) + auto +#else + boost::unique_lock<boost::mutex> +#endif + lk = boost::make_unique_lock(m, boost::defer_lock); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == false); + + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_mutex_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_mutex_pass.cpp new file mode 100644 index 000000000..97b625564 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_mutex_pass.cpp @@ -0,0 +1,100 @@ +// Copyright (C) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/lock_factories.hpp> + +// template <class Mutex> +// unique_lock<Mutex> make_unique_lock(Mutex&); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/detail/config.hpp> +#include <boost/thread/lock_factories.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../../timming.hpp" + +//#if ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +boost::mutex m; + +#if defined BOOST_THREAD_USES_CHRONO + +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + { +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) + auto +#else + boost::unique_lock<boost::mutex> +#endif + //&& + _ = boost::make_unique_lock(m); (void)_; + t1 = Clock::now(); + } +#else + //time_point t0 = Clock::now(); + //time_point t1; + { +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) + auto +#else + boost::unique_lock<boost::mutex> +#endif + //&& + _ = boost::make_unique_lock(m); (void)_; + //t1 = Clock::now(); + } + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} +//#else +//int main() +//{ +// return boost::report_errors(); +//} +//#endif + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_try_to_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_try_to_lock_pass.cpp new file mode 100644 index 000000000..d0149d906 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_try_to_lock_pass.cpp @@ -0,0 +1,146 @@ +// Copyright (C) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/locks.hpp> + +// template <class Mutex> class unique_lock; +// unique_lock<Mutex> make_unique_lock(Mutex&, try_to_lock_t); + +#define BOOST_THREAD_VERSION 4 + + +#include <boost/thread/lock_factories.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../../timming.hpp" + +boost::mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + { + t0 = Clock::now(); +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) + auto +#else + boost::unique_lock<boost::mutex> +#endif + lk = boost::make_unique_lock(m, boost::try_to_lock); + BOOST_TEST(lk.owns_lock() == false); + t1 = Clock::now(); + ns d = t1 - t0; + BOOST_THREAD_TEST_IT(d, ns(max_diff)); + } + { + t0 = Clock::now(); +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) + auto +#else + boost::unique_lock<boost::mutex> +#endif + lk = boost::make_unique_lock(m, boost::try_to_lock); + BOOST_TEST(lk.owns_lock() == false); + t1 = Clock::now(); + ns d = t1 - t0; + BOOST_THREAD_TEST_IT(d, ns(max_diff)); + } + { + t0 = Clock::now(); +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) + auto +#else + boost::unique_lock<boost::mutex> +#endif + lk = boost::make_unique_lock(m, boost::try_to_lock); + BOOST_TEST(lk.owns_lock() == false); + t1 = Clock::now(); + ns d = t1 - t0; + BOOST_THREAD_TEST_IT(d, ns(max_diff)); + } + { + t0 = Clock::now(); + for (;;) + { +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) + auto +#else + boost::unique_lock<boost::mutex> +#endif + lk = boost::make_unique_lock(m, boost::try_to_lock); + if (lk.owns_lock()) { + t1 = Clock::now(); + break; + } + } + } +#else +// time_point t0 = Clock::now(); +// { +// boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock); +// BOOST_TEST(lk.owns_lock() == false); +// } +// { +// boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock); +// BOOST_TEST(lk.owns_lock() == false); +// } +// { +// boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock); +// BOOST_TEST(lk.owns_lock() == false); +// } + for (;;) + { +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) + auto +#else + boost::unique_lock<boost::mutex> +#endif + lk = boost::make_unique_lock(m, boost::try_to_lock); + if (lk.owns_lock()) break; + } + //time_point t1 = Clock::now(); + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_locks_mutex_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_locks_mutex_pass.cpp new file mode 100644 index 000000000..72c574b20 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_locks_mutex_pass.cpp @@ -0,0 +1,94 @@ +// Copyright (C) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/lock_factories.hpp> + +// template <class Mutex> +// unique_lock<Mutex> make_unique_lock(Mutex&); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/lock_factories.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../../timming.hpp" + +#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined BOOST_THREAD_NO_MAKE_UNIQUE_LOCKS && ! defined BOOST_NO_CXX11_RVALUE_REFERENCES + +boost::mutex m1; +boost::mutex m2; +boost::mutex m3; + + +#if defined BOOST_THREAD_USES_CHRONO + +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + { + auto&& _ = boost::make_unique_locks(m1,m2,m3); (void)_; + t1 = Clock::now(); + } +#else + //time_point t0 = Clock::now(); + //time_point t1; + { + auto&& _ = boost::make_unique_locks(m1,m2,m3); (void)_; + //t1 = Clock::now(); + } + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m1.lock(); + m2.lock(); + m3.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m1.unlock(); + m2.unlock(); + m3.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} +#else +int main() +{ + return boost::report_errors(); +} +#endif + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_assign_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_assign_pass.cpp new file mode 100644 index 000000000..7c84d1520 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_assign_pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// template <class Mutex> class unique_lock; + +// unique_lock(unique_lock const&) = delete; + + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m0; +boost::mutex m1; + +int main() +{ + { + boost::unique_lock<boost::mutex> lk0(m0); + boost::unique_lock<boost::mutex> lk1(m1); + 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::unique_lock<boost::mutex> lk1; + lk1 = BOOST_THREAD_MAKE_RV_REF(boost::unique_lock<boost::mutex>(m0)); + BOOST_TEST(lk1.mutex() == &m0); + BOOST_TEST(lk1.owns_lock() == true); + } + return boost::report_errors(); + +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_pass.cpp new file mode 100644 index 000000000..cf682fbd4 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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 unique_lock; + +// unique_lock(unique_lock&& u); + + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m; + +int main() +{ + { + boost::unique_lock<boost::mutex> lk0(m); + boost::unique_lock<boost::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::unique_lock<boost::mutex> lk( (BOOST_THREAD_MAKE_RV_REF(boost::unique_lock<boost::mutex>(m)))); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == true); + } + { + boost::unique_lock<boost::mutex> lk0(m, boost::defer_lock); + boost::unique_lock<boost::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::mutex> lk0(m, boost::defer_lock); + lk0.release(); + boost::unique_lock<boost::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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_shared_lock_for_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_shared_lock_for_pass.cpp new file mode 100644 index 000000000..0e61cb1a7 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_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 unique_lock; + +// template <class Rep, class Period> +// unique_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/lock_types.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::unique_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::unique_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::unique_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::unique_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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_shared_lock_try_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_shared_lock_try_pass.cpp new file mode 100644 index 000000000..3068866f0 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_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 unique_lock; + +// unique_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/lock_types.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::unique_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::unique_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::unique_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::unique_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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_shared_lock_until_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_shared_lock_until_pass.cpp new file mode 100644 index 000000000..f1e54cf45 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_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 unique_lock; + +// template <class Clock, class Duration> +// unique_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/lock_types.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::unique_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::unique_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::unique_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::unique_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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_for_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_for_pass.cpp new file mode 100644 index 000000000..7437ee0e7 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_for_pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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 unique_lock; + +// template <class Clock, class Duration> +// unique_lock(shared_lock<mutex_type>&&, +// const chrono::duration<Rep, Period>&); + +#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::upgrade_mutex m; + +int main() +{ + { + boost::upgrade_lock<boost::upgrade_mutex> lk0(m); + boost::unique_lock<boost::upgrade_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::unique_lock<boost::upgrade_mutex> + lk(boost::upgrade_lock<boost::upgrade_mutex>(m), boost::chrono::milliseconds(1)); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == true); + } + { + boost::upgrade_lock<boost::upgrade_mutex> lk0(m, boost::defer_lock); + boost::unique_lock<boost::upgrade_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::upgrade_lock<boost::upgrade_mutex> lk0(m, boost::defer_lock); + lk0.release(); + boost::unique_lock<boost::upgrade_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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_pass.cpp new file mode 100644 index 000000000..c72067ae9 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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 unique_lock; + +// unique_lock(upgrade_lock&& u); + + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::upgrade_mutex m; + +int main() +{ + { + boost::upgrade_lock<boost::upgrade_mutex> lk0(m); + boost::unique_lock<boost::upgrade_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::unique_lock<boost::upgrade_mutex> lk( (BOOST_THREAD_MAKE_RV_REF(boost::upgrade_lock<boost::upgrade_mutex>(m)))); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == true); + } + { + boost::upgrade_lock<boost::upgrade_mutex> lk0(m, boost::defer_lock); + boost::unique_lock<boost::upgrade_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::upgrade_mutex> lk0(m, boost::defer_lock); + lk0.release(); + boost::unique_lock<boost::upgrade_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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_try_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_try_pass.cpp new file mode 100644 index 000000000..fdbdf2165 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_try_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 unique_lock; + +// unique_lock(upgrade_lock&& u, try_to_lock); + +#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::upgrade_mutex m; + +int main() +{ + { + boost::upgrade_lock<boost::upgrade_mutex> lk0(m); + boost::unique_lock<boost::upgrade_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::unique_lock<boost::upgrade_mutex> lk(boost::upgrade_lock<boost::upgrade_mutex>(m), boost::try_to_lock); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == true); + } + { + boost::upgrade_lock<boost::upgrade_mutex> lk0(m, boost::defer_lock); + boost::unique_lock<boost::upgrade_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::upgrade_lock<boost::upgrade_mutex> lk0(m, boost::defer_lock); + lk0.release(); + boost::unique_lock<boost::upgrade_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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_until_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_until_pass.cpp new file mode 100644 index 000000000..cd33f709c --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_until_pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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 unique_lock; + +// template <class Clock, class Duration> +// unique_lock(shared_lock<mutex_type>&&, +// const chrono::time_point<Clock, Duration>&); + +#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::upgrade_mutex m; + +int main() +{ + { + boost::upgrade_lock<boost::upgrade_mutex> lk0(m); + boost::unique_lock<boost::upgrade_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::unique_lock<boost::upgrade_mutex> + lk( boost::upgrade_lock<boost::upgrade_mutex>(m), boost::chrono::steady_clock::now()+boost::chrono::milliseconds(1)); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == true); + } + { + boost::upgrade_lock<boost::upgrade_mutex> lk0(m, boost::defer_lock); + boost::unique_lock<boost::upgrade_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::upgrade_lock<boost::upgrade_mutex> lk0(m, boost::defer_lock); + lk0.release(); + boost::unique_lock<boost::upgrade_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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/mutex_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/mutex_pass.cpp new file mode 100644 index 000000000..d5b7ca295 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/mutex_pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// 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 unique_lock; + +// explicit unique_lock(Mutex& m); + + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <iostream> +#include "../../../../../timming.hpp" + + +boost::mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + { + boost::unique_lock<boost::mutex> ul(m); + t1 = Clock::now(); + } +#else + //time_point t0 = Clock::now(); + //time_point t1; + { + boost::unique_lock<boost::mutex> ul(m); + //t1 = Clock::now(); + } + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/time_point_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/time_point_pass.cpp new file mode 100644 index 000000000..53358de6e --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/time_point_pass.cpp @@ -0,0 +1,93 @@ +//===----------------------------------------------------------------------===// +// +// 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 unique_lock; + +// template <class Clock, class Duration> +// unique_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time); + +#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../../timming.hpp" + +#if defined BOOST_THREAD_USES_CHRONO + +boost::timed_mutex m; + +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f1() +{ + t0 = Clock::now(); + boost::unique_lock<boost::timed_mutex> lk(m, Clock::now() + ms(750)); + BOOST_TEST(lk.owns_lock() == true); + t1 = Clock::now(); +} + +void f2() +{ + t0 = Clock::now(); + boost::unique_lock<boost::timed_mutex> lk(m, Clock::now() + ms(250)); + BOOST_TEST(lk.owns_lock() == false); + t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < max_diff); +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); + m.unlock(); + t.join(); + + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(750)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + +#else +#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported" +#endif diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/try_to_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/try_to_lock_pass.cpp new file mode 100644 index 000000000..0f0c8ded4 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/try_to_lock_pass.cpp @@ -0,0 +1,120 @@ +//===----------------------------------------------------------------------===// +// +// 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 unique_lock; + +// unique_lock(mutex_type& m, try_to_lock_t); + + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../../timming.hpp" + + +boost::mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + { + boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock); + BOOST_TEST(lk.owns_lock() == false); + } + { + boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock); + BOOST_TEST(lk.owns_lock() == false); + } + { + boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock); + BOOST_TEST(lk.owns_lock() == false); + } + for (;;) + { + boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock); + if (lk.owns_lock()) { + t1 = Clock::now(); + break; + } + } + //m.unlock(); +#else +// time_point t0 = Clock::now(); +// { +// boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock); +// BOOST_TEST(lk.owns_lock() == false); +// } +// { +// boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock); +// BOOST_TEST(lk.owns_lock() == false); +// } +// { +// boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock); +// BOOST_TEST(lk.owns_lock() == false); +// } + for (;;) + { + boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock); + if (lk.owns_lock()) break; + } + //time_point t1 = Clock::now(); + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + std::cout << "d_ns: " << d_ns.count() << std::endl; + std::cout << "d_ms: " << d_ms.count() << std::endl; + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/locking/lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/locking/lock_pass.cpp new file mode 100644 index 000000000..94edb4342 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/locking/lock_pass.cpp @@ -0,0 +1,127 @@ +//===----------------------------------------------------------------------===// +// +// 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 unique_lock; + +// void lock(); + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <iostream> +#include "../../../../../timming.hpp" + +boost::mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + boost::unique_lock < boost::mutex > lk(m, boost::defer_lock); + t0 = Clock::now(); + lk.lock(); + t1 = Clock::now(); + BOOST_TEST(lk.owns_lock() == true); + 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::unique_lock < boost::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); + //BOOST_TEST(d < max_diff); + 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 + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_for_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_for_pass.cpp new file mode 100644 index 000000000..2be8416eb --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_for_pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// 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 unique_lock; + +// template <class Rep, class Period> +// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time); + +#include <boost/thread/lock_types.hpp> +//#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +#if defined BOOST_THREAD_USES_CHRONO + + +bool try_lock_for_called = false; + +typedef boost::chrono::milliseconds ms; + +struct mutex +{ + template <class Rep, class Period> + bool try_lock_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() + { + } +}; + +mutex m; + +int main() +{ + boost::unique_lock<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(); +} + +#else +#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported" +#endif + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_pass.cpp new file mode 100644 index 000000000..8553c1c0b --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// 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 unique_lock; + +// template <class Rep, class Period> +// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time); + +#include <boost/thread/lock_types.hpp> +//#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +bool try_lock_called = false; + +struct mutex +{ + bool try_lock() + { + try_lock_called = !try_lock_called; + return try_lock_called; + } + void unlock() + { + } +}; + +mutex m; + +int main() +{ + boost::unique_lock<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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_until_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_until_pass.cpp new file mode 100644 index 000000000..df6e7369e --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_until_pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// 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 unique_lock; + +// template <class Clock, class Duration> +// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time); + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +#if defined BOOST_THREAD_USES_CHRONO + + +bool try_lock_until_called = false; + +struct mutex +{ + template <class Clock, class Duration> + bool try_lock_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() + { + } +}; + +mutex m; + +int main() +{ + typedef boost::chrono::steady_clock Clock; + boost::unique_lock<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(); +} + +#else +#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported" +#endif + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/locking/unlock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/locking/unlock_pass.cpp new file mode 100644 index 000000000..4ad954f24 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_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 unique_lock; + +// bool unlock(); + +#include <boost/thread/lock_types.hpp> +//#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + + +bool unlock_called = false; + +struct mutex +{ + void lock() + { + } + void unlock() + { + unlock_called = true; + } +}; + +mutex m; + +int main() +{ + boost::unique_lock<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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/mod/member_swap_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/mod/member_swap_pass.cpp new file mode 100644 index 000000000..617682fe3 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_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 unique_lock; + +// void swap(unique_lock& u); + +#include <boost/thread/lock_types.hpp> +#include <boost/detail/lightweight_test.hpp> + +struct mutex +{ + void lock() + { + } + void unlock() + { + } +}; + +mutex m; + +int main() +{ + boost::unique_lock<mutex> lk1(m); + boost::unique_lock<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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/mod/non_member_swap_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/mod/non_member_swap_pass.cpp new file mode 100644 index 000000000..74ba5ff3f --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_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(unique_lock<Mutex>& x, unique_lock<Mutex>& y); + +#include <boost/thread/lock_types.hpp> +#include <boost/detail/lightweight_test.hpp> + +struct mutex +{ + void lock() + { + } + void unlock() + { + } +}; + +mutex m; + +int main() +{ + boost::unique_lock<mutex> lk1(m); + boost::unique_lock<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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/mod/release_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/mod/release_pass.cpp new file mode 100644 index 000000000..63c3831e5 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_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 unique_lock; + +// void Mutex* release(); + +#include <boost/thread/lock_types.hpp> +#include <boost/detail/lightweight_test.hpp> + +struct mutex +{ + static int lock_count; + static int unlock_count; + void lock() + { + ++lock_count; + } + void unlock() + { + ++unlock_count; + } +}; + +int mutex::lock_count = 0; +int mutex::unlock_count = 0; + +mutex m; + +int main() +{ + boost::unique_lock<mutex> lk(m); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == true); + BOOST_TEST(mutex::lock_count == 1); + BOOST_TEST(mutex::unlock_count == 0); + BOOST_TEST(lk.release() == &m); + BOOST_TEST(lk.mutex() == 0); + BOOST_TEST(lk.owns_lock() == false); + BOOST_TEST(mutex::lock_count == 1); + BOOST_TEST(mutex::unlock_count == 0); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs/mutex_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs/mutex_pass.cpp new file mode 100644 index 000000000..68f1bbb6d --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_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 unique_lock; + +// Mutex *mutex() const; + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m; + +int main() +{ + boost::unique_lock<boost::mutex> lk0; + BOOST_TEST(lk0.mutex() == 0); + boost::unique_lock<boost::mutex> lk1(m); + BOOST_TEST(lk1.mutex() == &m); + lk1.unlock(); + BOOST_TEST(lk1.mutex() == &m); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs/op_bool_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs/op_bool_pass.cpp new file mode 100644 index 000000000..3fa18225a --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs/op_bool_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 unique_lock; + +// explicit operator bool() const; + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m; + +int main() +{ + { + boost::unique_lock<boost::mutex> lk0; + BOOST_TEST(bool(lk0) == false); + boost::unique_lock<boost::mutex> lk1(m); + BOOST_TEST(bool(lk1) == true); + lk1.unlock(); + BOOST_TEST(bool(lk1) == false); + } + + { + boost::unique_lock<boost::mutex> lk0; + if (lk0) BOOST_TEST(false); + boost::unique_lock<boost::mutex> lk1(m); + if (!lk1) BOOST_TEST(false); + lk1.unlock(); + if (lk1) BOOST_TEST(false); + } + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs/op_int_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs/op_int_fail.cpp new file mode 100644 index 000000000..92fe0ffcb --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs/op_int_fail.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 unique_lock; + +// explicit operator bool() const; + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m; + +int main() +{ + { + boost::unique_lock<boost::mutex> lk0; + int i = int(lk0); + BOOST_TEST(i == 0); + } + + return boost::report_errors(); +} + +#include "../../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs/owns_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs/owns_lock_pass.cpp new file mode 100644 index 000000000..6a9f019aa --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/obs/owns_lock_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/locks.hpp> + +// template <class Mutex> class unique_lock; + +// bool owns_lock() const; + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + + +int main() +{ + boost::mutex m; + + boost::unique_lock<boost::mutex> lk0; + BOOST_TEST(lk0.owns_lock() == false); + boost::unique_lock<boost::mutex> lk1(m); + BOOST_TEST(lk1.owns_lock() == true); + lk1.unlock(); + BOOST_TEST(lk1.owns_lock() == false); + + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/types_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/types_pass.cpp new file mode 100644 index 000000000..69b963a6f --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_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 unique_lock +// { +// public: +// typedef Mutex mutex_type; +// ... +// }; + + +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/static_assert.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::unique_lock<boost::mutex>::mutex_type, + boost::mutex>::value), ""); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/adopt_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/adopt_lock_pass.cpp new file mode 100644 index 000000000..1822fe0b6 --- /dev/null +++ b/src/boost/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/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + + +int main() +{ + boost::shared_mutex m; + m.lock_upgrade(); + 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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/copy_assign_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/copy_assign_fail.cpp new file mode 100644 index 000000000..521304d81 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/copy_assign_fail.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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/lock_types.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); + +} + +#include "../../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/copy_ctor_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/copy_ctor_fail.cpp new file mode 100644 index 000000000..8e20196b1 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/copy_ctor_fail.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/locks.hpp> + +// template <class Mutex> class upgrade_lock; + +// upgrade_lock(upgrade_lock const&) = delete; + + +#include <boost/thread/lock_types.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); +} + +#include "../../../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/default_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/default_pass.cpp new file mode 100644 index 000000000..59ea2a9a2 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/defer_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/defer_lock_pass.cpp new file mode 100644 index 000000000..ececb845c --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/duration_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/duration_pass.cpp new file mode 100644 index 000000000..b6506b9b3 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/duration_pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// 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/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/chrono/chrono_io.hpp> +#include "../../../../../timming.hpp" + +boost::shared_mutex m; + +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f1() +{ + t0 = Clock::now(); + boost::upgrade_lock<boost::shared_mutex> lk(m, ms(750)); + BOOST_TEST(lk.owns_lock() == true); + t1 = Clock::now(); +} + +void f2() +{ + t0 = Clock::now(); + boost::upgrade_lock<boost::shared_mutex> lk(m, ms(250)); + BOOST_TEST(lk.owns_lock() == false); + t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); + m.unlock(); + t.join(); + + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(750)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_assign_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_assign_pass.cpp new file mode 100644 index 000000000..42ef355c9 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_pass.cpp new file mode 100644 index 000000000..5d5c0a948 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_shared_lock_for_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_shared_lock_for_pass.cpp new file mode 100644 index 000000000..ccad7b1ac --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_shared_lock_try_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_shared_lock_try_pass.cpp new file mode 100644 index 000000000..93deda8c3 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_shared_lock_until_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_shared_lock_until_pass.cpp new file mode 100644 index 000000000..3d2c2871b --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_unique_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_unique_lock_pass.cpp new file mode 100644 index 000000000..3d591d176 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/mutex_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/mutex_pass.cpp new file mode 100644 index 000000000..1e634807d --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/mutex_pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <iostream> +#include "../../../../../timming.hpp" + +boost::shared_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + { + boost::upgrade_lock<boost::shared_mutex> ul(m); + t1 = Clock::now(); + } +#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); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/time_point_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/time_point_pass.cpp new file mode 100644 index 000000000..4cf71476b --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/time_point_pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../../timming.hpp" + +boost::shared_mutex m; + +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f1() +{ + t0 = Clock::now(); + boost::upgrade_lock<boost::shared_mutex> lk(m, Clock::now() + ms(750)); + BOOST_TEST(lk.owns_lock() == true); + t1 = Clock::now(); +} + +void f2() +{ + t0 = Clock::now(); + boost::upgrade_lock<boost::shared_mutex> lk(m, Clock::now() + ms(250)); + BOOST_TEST(lk.owns_lock() == false); + t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); + m.unlock(); + t.join(); + + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(750)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/try_to_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/try_to_lock_pass.cpp new file mode 100644 index 000000000..9a7fe26bf --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/try_to_lock_pass.cpp @@ -0,0 +1,117 @@ +//===----------------------------------------------------------------------===// +// +// 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/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../../../timming.hpp" + +boost::shared_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + 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); + } + for (;;) + { + boost::upgrade_lock<boost::shared_mutex> lk(m, boost::try_to_lock); + if (lk.owns_lock()) { + t1 = Clock::now(); + break; + } + } + //m.unlock(); +#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); +// } + for (;;) + { + 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); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/lock_pass.cpp new file mode 100644 index 000000000..2ff49ac96 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/lock_pass.cpp @@ -0,0 +1,126 @@ +//===----------------------------------------------------------------------===// +// +// 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/lock_types.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <iostream> +#include "../../../../../timming.hpp" + +boost::shared_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + boost::upgrade_lock < boost::shared_mutex > lk(m, boost::defer_lock); + t0 = Clock::now(); + lk.lock(); + t1 = Clock::now(); + BOOST_TEST(lk.owns_lock() == true); + 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); + //BOOST_TEST(d < max_diff); + 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 + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_for_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_for_pass.cpp new file mode 100644 index 000000000..5f8f4f5fe --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_pass.cpp new file mode 100644 index 000000000..820fd71a3 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_until_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_until_pass.cpp new file mode 100644 index 000000000..1c53d6a5b --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/unlock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/unlock_pass.cpp new file mode 100644 index 000000000..bc49a0433 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/member_swap_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/member_swap_pass.cpp new file mode 100644 index 000000000..4b0752ef5 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/non_member_swap_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/non_member_swap_pass.cpp new file mode 100644 index 000000000..c7ebaa271 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/release_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/mod/release_pass.cpp new file mode 100644 index 000000000..226819446 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/mutex_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/mutex_pass.cpp new file mode 100644 index 000000000..276cd0a93 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/op_bool_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/op_bool_pass.cpp new file mode 100644 index 000000000..4e722d174 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/owns_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/obs/owns_lock_pass.cpp new file mode 100644 index 000000000..9d8b80d69 --- /dev/null +++ b/src/boost/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/lock_types.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/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/types_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/types_pass.cpp new file mode 100644 index 000000000..876428e46 --- /dev/null +++ b/src/boost/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/lock_types.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(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/assign_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/assign_fail.cpp new file mode 100644 index 000000000..fa1aff9b5 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/assign_fail.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class mutex; + +// mutex& operator=(const mutex&) = delete; + +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::mutex m0; + boost::mutex m1(m0); +} + +#include "../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/copy_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/copy_fail.cpp new file mode 100644 index 000000000..e6f6d6b88 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/copy_fail.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class mutex; + +// mutex(const mutex&) = delete; + +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::mutex m0; + boost::mutex m1(m0); +} + +#include "../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/default_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/default_pass.cpp new file mode 100644 index 000000000..a911eefcf --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/default_pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class mutex; + +// mutex(); + +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::mutex m0; + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/lock_compile_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/lock_compile_fail.cpp new file mode 100644 index 000000000..f6bf74b56 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/lock_compile_fail.cpp @@ -0,0 +1,19 @@ +// Copyright (C) 2017 Tom Hughes +// +// 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> + +// class mutex; + +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +void fail() +{ + boost::mutex m0; + m0.lock(); + m0.lock(); + m0.unlock(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/lock_compile_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/lock_compile_pass.cpp new file mode 100644 index 000000000..9da22a59d --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/lock_compile_pass.cpp @@ -0,0 +1,18 @@ +// Copyright (C) 2017 Tom Hughes +// +// 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> + +// class mutex; + +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +void pass() +{ + boost::mutex m0; + m0.lock(); + m0.unlock(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/lock_pass.cpp new file mode 100644 index 000000000..94818fbad --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/lock_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/mutex.hpp> + +// class mutex; + +// void lock(); + +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + +boost::mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + m.lock(); + t1 = Clock::now(); + m.unlock(); +#else + //time_point t0 = Clock::now(); + m.lock(); + //time_point t1 = Clock::now(); + m.unlock(); + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/native_handle_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/native_handle_pass.cpp new file mode 100644 index 000000000..489ec375d --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/native_handle_pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class mutex; + +// typedef pthread_mutex_t* native_handle_type; +// native_handle_type native_handle(); + +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ +#if defined BOOST_THREAD_DEFINES_MUTEX_NATIVE_HANDLE + boost::mutex m; + boost::mutex::native_handle_type h = m.native_handle(); + BOOST_TEST(h); +#else +#error "Test not applicable: BOOST_THREAD_DEFINES_MUTEX_NATIVE_HANDLE not defined for this platform as not supported" +#endif + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/try_lock_compile_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/try_lock_compile_fail.cpp new file mode 100644 index 000000000..05c2016cb --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/try_lock_compile_fail.cpp @@ -0,0 +1,19 @@ +// Copyright (C) 2017 Tom Hughes +// +// 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> + +// class mutex; + +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +void fail() +{ + boost::mutex m0; + if (!m0.try_lock()) { + m0.unlock(); + } +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/try_lock_compile_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/try_lock_compile_pass.cpp new file mode 100644 index 000000000..e4cec906a --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/try_lock_compile_pass.cpp @@ -0,0 +1,19 @@ +// Copyright (C) 2017 Tom Hughes +// +// 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> + +// class mutex; + +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +void pass() +{ + boost::mutex m0; + if (m0.try_lock()) { + m0.unlock(); + } +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/try_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/try_lock_pass.cpp new file mode 100644 index 000000000..b973c1b23 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/mutex/try_lock_pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class mutex; + +// bool try_lock(); + +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + + +boost::mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + while (!m.try_lock()) + ; + t1 = Clock::now(); + m.unlock(); +#else + //time_point t0 = Clock::now(); + //BOOST_TEST(!m.try_lock()); + //BOOST_TEST(!m.try_lock()); + //BOOST_TEST(!m.try_lock()); + while (!m.try_lock()) + ; + //time_point t1 = Clock::now(); + m.unlock(); + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif + +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/assign_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/assign_fail.cpp new file mode 100644 index 000000000..e8b440abd --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/assign_fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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/null_mutex.hpp> + +// class null_mutex; + +// null_mutex& operator=(const null_mutex&) = delete; + +#include <boost/thread/null_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::null_mutex m0; + boost::null_mutex m1(m0); +} + +#include "../../../remove_error_code_unused_warning.hpp" diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/copy_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/copy_fail.cpp new file mode 100644 index 000000000..66668f5e0 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/copy_fail.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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/null_mutex.hpp> + +// class null_mutex; + +// null_mutex(const null_mutex&) = delete; + +#include <boost/thread/null_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::null_mutex m0; + boost::null_mutex m1(m0); +} + +#include "../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/default_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/default_pass.cpp new file mode 100644 index 000000000..343431a9e --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/default_pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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/null_mutex.hpp> + +// class null_mutex; + +// null_mutex(); + +#include <boost/thread/null_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::null_mutex m0; + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/lock_pass.cpp new file mode 100644 index 000000000..3c91e25f6 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/lock_pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/null_mutex.hpp> + +// class null_mutex; + +// void lock(); + +#include <boost/thread/null_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + +boost::null_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + time_point t0 = Clock::now(); + m.lock(); + time_point t1 = Clock::now(); + m.lock(); + m.unlock(); + m.unlock(); + ns d = t1 - t0 ; + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +#else + //time_point t0 = Clock::now(); + m.lock(); + //time_point t1 = Clock::now(); + m.lock(); + m.unlock(); + m.unlock(); + //ns d = t1 - t0 ; + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); + m.unlock(); + t.join(); + + return boost::report_errors(); +} + + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_for_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_for_pass.cpp new file mode 100644 index 000000000..1f5f5e9fc --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_for_pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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/null_mutex.hpp> + +// class null_mutex; + +// template <class Rep, class Period> +// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time); + +#include <boost/thread/null_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + +#if defined BOOST_THREAD_USES_CHRONO + + +boost::null_mutex m; + +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f1() +{ + time_point t0 = Clock::now(); + BOOST_TEST(m.try_lock_for(ms(250)) == true); + time_point t1 = Clock::now(); + BOOST_TEST(m.try_lock()); + m.unlock(); + m.unlock(); + ns d = t1 - t0 ; + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + +#else +#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported" +#endif + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_pass.cpp new file mode 100644 index 000000000..cc51928bb --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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/null_mutex.hpp> + +// class null_mutex; + +// bool try_lock(); + +#include <boost/thread/null_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + + + +boost::null_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + time_point t0 = Clock::now(); + BOOST_TEST(m.try_lock()); + time_point t1 = Clock::now(); + BOOST_TEST(m.try_lock()); + m.unlock(); + m.unlock(); + ns d = t1 - t0; + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +#else + BOOST_TEST(m.try_lock()); + BOOST_TEST(m.try_lock()); + m.unlock(); + m.unlock(); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); + m.unlock(); + t.join(); + + return boost::report_errors(); +} + + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_until_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_until_pass.cpp new file mode 100644 index 000000000..8a6985165 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_until_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/null_mutex> + +// class null_mutex; + +// template <class Clock, class Duration> +// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time); + +#include <boost/thread/null_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + +#if defined BOOST_THREAD_USES_CHRONO + +boost::null_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; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f1() +{ + time_point t0 = Clock::now(); + BOOST_TEST(m.try_lock_until(Clock::now() + ms(250)) == true); + time_point t1 = Clock::now(); + m.unlock(); + ns d = t1 - t0 ; + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +} + + +int main() +{ + { + m.lock(); + boost::thread t(f1); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + +#else +#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported" +#endif + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/once/call_once/call_once_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/once/call_once/call_once_pass.cpp new file mode 100644 index 000000000..ac7b80769 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/once/call_once/call_once_pass.cpp @@ -0,0 +1,297 @@ +//===----------------------------------------------------------------------===// +// +// 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) 2013 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/once.hpp> + +// struct once_flag; + +// template<class Callable, class ...Args> +// void call_once(once_flag& flag, Callable&& func, Args&&... args); + +//#define BOOST_THREAD_VERSION 4 +#define BOOST_THREAD_USES_MOVE +#define BOOST_THREAD_PROVIDES_ONCE_CXX11 + +#include <boost/thread/once.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> + +#ifdef BOOST_THREAD_PROVIDES_ONCE_CXX11 +#define BOOST_INIT_ONCE_INIT +#else +#define BOOST_INIT_ONCE_INIT =BOOST_ONCE_INIT +#endif + +typedef boost::chrono::milliseconds ms; + +boost::once_flag flg0 BOOST_INIT_ONCE_INIT; + +int init0_called = 0; + +void init0() +{ + boost::this_thread::sleep_for(ms(250)); + ++init0_called; +} + +void f0() +{ + boost::call_once(flg0, init0); +} + +boost::once_flag flg3 BOOST_INIT_ONCE_INIT; + +int init3_called = 0; +int init3_completed = 0; + +void init3() +{ + ++init3_called; + boost::this_thread::sleep_for(ms(250)); + if (init3_called == 1) + throw 1; + ++init3_completed; +} + +void f3() +{ + try + { + boost::call_once(flg3, init3); + } + catch (...) + { + } +} + +struct init1 +{ + static int called; + typedef void result_type; + + void operator()(int i) {called += i;} + void operator()(int i) const {called += i;} +}; + +int init1::called = 0; + +boost::once_flag flg1 BOOST_INIT_ONCE_INIT; + +void f1() +{ + boost::call_once(flg1, init1(), 1); +} + +boost::once_flag flg1_member BOOST_INIT_ONCE_INIT; + +struct init1_member +{ + static int called; + typedef void result_type; + void call(int i) { + called += i; + } +}; +int init1_member::called = 0; + +void f1_member_l() +{ + init1_member o; + int i=1; + boost::call_once(flg1_member, &init1_member::call, o, i); +} +void f1_member_r() +{ + init1_member o; + boost::call_once(flg1_member, &init1_member::call, o, 1); +} +struct init2 +{ + static int called; + typedef void result_type; + + void operator()(int i, int j) {called += i + j;} + void operator()(int i, int j) const {called += i + j;} +}; + +int init2::called = 0; + +boost::once_flag flg2 BOOST_INIT_ONCE_INIT; + +void f2() +{ + boost::call_once(flg2, init2(), 2, 3); + boost::call_once(flg2, init2(), 4, 5); +} + +boost::once_flag flg41 BOOST_INIT_ONCE_INIT; +boost::once_flag flg42 BOOST_INIT_ONCE_INIT; + +int init41_called = 0; +int init42_called = 0; + +void init42(); + +void init41() +{ + boost::this_thread::sleep_for(ms(250)); + ++init41_called; +} + +void init42() +{ + boost::this_thread::sleep_for(ms(250)); + ++init42_called; +} + +void f41() +{ + boost::call_once(flg41, init41); + boost::call_once(flg42, init42); +} + +void f42() +{ + boost::call_once(flg42, init42); + boost::call_once(flg41, init41); +} + +class MoveOnly +{ +public: + typedef void result_type; + + BOOST_THREAD_MOVABLE_ONLY(MoveOnly) + MoveOnly() + { + } + MoveOnly(BOOST_THREAD_RV_REF(MoveOnly)) + {} + + void operator()(BOOST_THREAD_RV_REF(MoveOnly)) + { + } + void operator()(int) + { + } + void operator()() + { + } +}; + + +struct id_string +{ + static boost::once_flag flag; + static void do_init(id_string & ) + {} + void operator()() + { + boost::call_once(flag, &id_string::do_init, boost::ref(*this)); + } +// void operator()(int,int) +// { +// // This should fail but works with gcc-4.6.3 +// //std::bind(&id_string::do_init, *this)(); +// std::bind(&id_string::do_init, std::ref(*this))(); +// } +// void operator()(int) const +// { +// //std::bind(&id_string::do_init, *this)(); +// } +}; + + +boost::once_flag id_string::flag BOOST_INIT_ONCE_INIT; + +int main() +{ + + // + { + id_string id; + id(); + //id(1,1); + } + // check basic functionality + { + boost::thread t0(f0); + boost::thread t1(f0); + t0.join(); + t1.join(); + BOOST_TEST(init0_called == 1); + } + // check basic exception safety + { + boost::thread t0(f3); + boost::thread t1(f3); + t0.join(); + t1.join(); + BOOST_TEST(init3_called == 2); + BOOST_TEST(init3_completed == 1); + } + // check deadlock avoidance + { + boost::thread t0(f41); + boost::thread t1(f42); + t0.join(); + t1.join(); + BOOST_TEST(init41_called == 1); + BOOST_TEST(init42_called == 1); + } + // check functors with 1 arg + { + boost::thread t0(f1); + boost::thread t1(f1); + t0.join(); + t1.join(); + BOOST_TEST(init1::called == 1); + } + // check functors with 2 args + { + boost::thread t0(f2); + boost::thread t1(f2); + t0.join(); + t1.join(); + BOOST_TEST(init2::called == 5); + } + + // check member function with 1 arg + { + boost::thread t0(f1_member_l); + boost::thread t1(f1_member_r); + t0.join(); + t1.join(); + BOOST_TEST(init1_member::called == 1); + } +#if defined BOOST_THREAD_PLATFORM_PTHREAD || (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__ > 40600) + { + boost::once_flag f BOOST_INIT_ONCE_INIT; + boost::call_once(f, MoveOnly()); + } +#endif +#if defined BOOST_THREAD_PROVIDES_INVOKE + { + boost::once_flag f BOOST_INIT_ONCE_INIT; + boost::call_once(f, MoveOnly(), 1); + } + { + boost::once_flag f BOOST_INIT_ONCE_INIT; + boost::call_once(f, MoveOnly(), MoveOnly()); + } +#endif // BOOST_THREAD_PLATFORM_PTHREAD + return boost::report_errors(); +} + + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/queue_views/single_thread_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/queue_views/single_thread_pass.cpp new file mode 100644 index 000000000..05a628230 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/queue_views/single_thread_pass.cpp @@ -0,0 +1,468 @@ +// Copyright (C) 2014 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/sync_queue.hpp> + +// class sync_queue<T> + +// sync_queue(); + +#define BOOST_THREAD_VERSION 4 +//#define BOOST_THREAD_QUEUE_DEPRECATE_OLD + +#include <boost/thread/concurrent_queues/sync_queue.hpp> +#include <boost/thread/concurrent_queues/queue_adaptor.hpp> +#include <boost/thread/concurrent_queues/queue_views.hpp> + +#include <boost/detail/lightweight_test.hpp> +#include <boost/static_assert.hpp> + +class non_copyable +{ + int val; +public: + BOOST_THREAD_MOVABLE_ONLY(non_copyable) + non_copyable(int v) : val(v){} + non_copyable(BOOST_RV_REF(non_copyable) x): val(x.val) {} + non_copyable& operator=(BOOST_RV_REF(non_copyable) x) { val=x.val; return *this; } + bool operator==(non_copyable const& x) const {return val==x.val;} + template <typename OSTREAM> + friend OSTREAM& operator <<(OSTREAM& os, non_copyable const&x ) + { + os << x.val; + return os; + } + +}; + +#if defined BOOST_NO_CXX11_RVALUE_REFERENCES +BOOST_STATIC_ASSERT( ! boost::is_copy_constructible<non_copyable>::value ); +BOOST_STATIC_ASSERT( boost::has_move_emulation_enabled<non_copyable>::value ); +#endif + +int main() +{ + + { + // default queue invariants + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_back<int> q(sq); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // default queue invariants + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_front<int> q(sq); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + + + { + // empty queue try_pull fails + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_front<int> q(sq); + int i; + BOOST_TEST( boost::queue_op_status::empty == q.try_pull(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push rvalue/copyable succeeds + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_back<int> q(sq); + q.push(1); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push lvalue/copyable succeeds + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_back<int> q(sq); + int i; + q.push(i); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + + +#if 0 + { + // empty queue push rvalue/non_copyable succeeds + boost::queue_adaptor<boost::sync_queue<non_copyable> > sq; + boost::queue_back<non_copyable> q(sq); + q.push(non_copyable(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) + { + // empty queue push rvalue/non_copyable succeeds + boost::queue_adaptor<boost::sync_queue<non_copyable> > q; + //boost::sync_queue<non_copyable> q; + //boost::queue_back<non_copyable> q(sq); + non_copyable nc(1); + q.push(boost::move(nc)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + + { + // empty queue push rvalue succeeds + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_back<int> q(sq); + q.push(1); + q.push(2); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 2u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push lvalue succeeds + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_back<int> q(sq); + int i; + q.push(i); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue/copyable succeeds + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_back<int> q(sq); + BOOST_TEST(boost::queue_op_status::success == q.try_push(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue/copyable succeeds + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_back<int> q(sq); + BOOST_TEST(boost::queue_op_status::success == q.try_push(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + +#if 0 + { + // empty queue try_push rvalue/non-copyable succeeds + boost::queue_adaptor<boost::sync_queue<non_copyable> > sq; + boost::queue_back<non_copyable> q(sq); + non_copyable nc(1); + BOOST_TEST(boost::queue_op_status::success == q.try_push(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + + { + // empty queue try_push lvalue succeeds + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_back<int> q(sq); + int i=0; + BOOST_TEST(boost::queue_op_status::success == q.try_push(i)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue succeeds + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_back<int> q(sq); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + + +#if 0 + { + // empty queue nonblocking_push rvalue/non-copyable succeeds + boost::queue_adaptor<boost::sync_queue<non_copyable> > sq; + boost::queue_back<non_copyable> q(sq); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(non_copyable(1))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) + { + // empty queue nonblocking_push rvalue/non-copyable succeeds + boost::queue_adaptor<boost::sync_queue<non_copyable> > sq; + boost::queue_back<non_copyable> q(sq); + non_copyable nc(1); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + { + // 1-element queue pull succeed + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_front<int> q(sq); + sq.push(1); + int i; + q.pull(i); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) + { + // 1-element queue pull succeed + boost::queue_adaptor<boost::sync_queue<non_copyable> > sq; + boost::queue_front<non_copyable> q(sq); + non_copyable nc1(1); + sq.push(boost::move(nc1)); + non_copyable nc2(2); + q.pull(nc2); + BOOST_TEST_EQ(nc1, nc2); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#endif + { + // 1-element queue pull succeed + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_front<int> q(sq); + sq.push(1); + int i = q.pull(); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) + { + // 1-element queue pull succeed + boost::queue_adaptor<boost::sync_queue<non_copyable> > sq; + boost::queue_front<non_copyable> q(sq); + non_copyable nc1(1); + sq.push(boost::move(nc1)); + non_copyable nc = q.pull(); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#endif + { + // 1-element queue try_pull succeed + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_front<int> q(sq); + sq.push(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.try_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) + { + // 1-element queue try_pull succeed + boost::queue_adaptor<boost::sync_queue<non_copyable> > sq; + boost::queue_front<non_copyable> q(sq); + non_copyable nc1(1); + sq.push(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.try_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#endif + { + // 1-element queue nonblocking_pull succeed + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_front<int> q(sq); + sq.push(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) + { + // 1-element queue nonblocking_pull succeed + boost::queue_adaptor<boost::sync_queue<non_copyable> > sq; + boost::queue_front<non_copyable> q(sq); + non_copyable nc1(1); + sq.push(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue wait_pull succeed + boost::queue_adaptor<boost::sync_queue<non_copyable> > sq; + boost::queue_front<non_copyable> q(sq); + non_copyable nc1(1); + sq.push(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#endif + { + // 1-element queue wait_pull succeed + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_front<int> q(sq); + sq.push(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) + { + // 1-element queue wait_pull succeed + boost::queue_adaptor<boost::sync_queue<non_copyable> > sq; + boost::queue_front<non_copyable> q(sq); + non_copyable nc1(1); + sq.push(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#endif + { + // closed invariants + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_back<int> q(sq); + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed invariants + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_front<int> q(sq); + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed queue push fails + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_back<int> q(sq); + q.close(); + try { + q.push(1); + BOOST_TEST(false); + } catch (...) { + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + } + { + // 1-element closed queue pull succeed + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_front<int> q(sq); + sq.push(1); + q.close(); + int i; + q.pull(i); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // 1-element closed queue wait_pull succeed + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_front<int> q(sq); + sq.push(1); + q.close(); + int i; + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed empty queue wait_pull fails + boost::queue_adaptor<boost::sync_queue<int> > sq; + boost::queue_front<int> q(sq); + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + int i; + BOOST_TEST(boost::queue_op_status::closed == q.wait_pull(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + } + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/assign_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/assign_fail.cpp new file mode 100644 index 000000000..041102e91 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/assign_fail.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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/recursive_mutex.hpp> + +// class recursive_mutex; + +// recursive_mutex& operator=(const recursive_mutex&) = delete; + +#include <boost/thread/recursive_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::recursive_mutex m0; + boost::recursive_mutex m1(m0); +} + +#include "../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/copy_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/copy_fail.cpp new file mode 100644 index 000000000..932422d15 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/copy_fail.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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/recursive_mutex.hpp> + +// class recursive_mutex; + +// recursive_mutex(const recursive_mutex&) = delete; + +#include <boost/thread/recursive_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::recursive_mutex m0; + boost::recursive_mutex m1(m0); +} + +#include "../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/default_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/default_pass.cpp new file mode 100644 index 000000000..6b6199720 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/default_pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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/recursive_mutex.hpp> + +// class recursive_mutex; + +// recursive_mutex(); + +#include <boost/thread/recursive_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::recursive_mutex m0; + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/lock_pass.cpp new file mode 100644 index 000000000..a5410d25e --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/lock_pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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/recursive_mutex.hpp> + +// class recursive_mutex; + +// void lock(); + +#include <boost/thread/recursive_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + + +boost::recursive_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + m.lock(); + t1 = Clock::now(); + m.lock(); + m.unlock(); + m.unlock(); +#else + //time_point t0 = Clock::now(); + m.lock(); + //time_point t1 = Clock::now(); + m.lock(); + m.unlock(); + m.unlock(); + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/native_handle_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/native_handle_pass.cpp new file mode 100644 index 000000000..b784f24e5 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/native_handle_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/recursive_mutex.hpp> + +// class recursive_mutex; + +// typedef pthread_recursive_mutex_t* native_handle_type; +// native_handle_type native_handle(); + +#include <boost/thread/recursive_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ +#if defined BOOST_THREAD_DEFINES_RECURSIVE_MUTEX_NATIVE_HANDLE + boost::recursive_mutex m; + boost::recursive_mutex::native_handle_type h = m.native_handle(); + BOOST_TEST(h); +#else +#error "Test not applicable: BOOST_THREAD_DEFINES_RECURSIVE_MUTEX_NATIVE_HANDLE not defined for this platform as not supported" +#endif + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/try_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/try_lock_pass.cpp new file mode 100644 index 000000000..0f8fe822a --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_mutex/try_lock_pass.cpp @@ -0,0 +1,96 @@ +//===----------------------------------------------------------------------===// +// +// 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/recursive_mutex.hpp> + +// class recursive_mutex; + +// bool try_lock(); + +#include <boost/thread/recursive_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <iostream> +#include "../../../timming.hpp" + +boost::recursive_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); +// BOOST_TEST(!m.try_lock()); +// BOOST_TEST(!m.try_lock()); +// BOOST_TEST(!m.try_lock()); + while (!m.try_lock()) + ; + t1 = Clock::now(); + BOOST_TEST(m.try_lock()); + m.unlock(); + m.unlock(); +#else + //time_point t0 = Clock::now(); + //BOOST_TEST(!m.try_lock()); + //BOOST_TEST(!m.try_lock()); + //BOOST_TEST(!m.try_lock()); + while (!m.try_lock()) + ; + //time_point t1 = Clock::now(); + BOOST_TEST(m.try_lock()); + m.unlock(); + m.unlock(); + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/assign_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/assign_fail.cpp new file mode 100644 index 000000000..48b9cc47d --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/assign_fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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/recursive_mutex.hpp> + +// class recursive_timed_mutex; + +// recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete; + +#include <boost/thread/recursive_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::recursive_timed_mutex m0; + boost::recursive_timed_mutex m1(m0); +} + +#include "../../../remove_error_code_unused_warning.hpp" diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/copy_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/copy_fail.cpp new file mode 100644 index 000000000..b4e96c7ac --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/copy_fail.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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/recursive_mutex.hpp> + +// class recursive_timed_mutex; + +// recursive_timed_mutex(const recursive_timed_mutex&) = delete; + +#include <boost/thread/recursive_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::recursive_timed_mutex m0; + boost::recursive_timed_mutex m1(m0); +} + +#include "../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/default_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/default_pass.cpp new file mode 100644 index 000000000..1e75b7b04 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/default_pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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/recursive_mutex.hpp> + +// class recursive_timed_mutex; + +// recursive_timed_mutex(); + +#include <boost/thread/recursive_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::recursive_timed_mutex m0; + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/lock_pass.cpp new file mode 100644 index 000000000..bd0646f64 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/lock_pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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/recursive_mutex.hpp> + +// class recursive_timed_mutex; + +// void lock(); + +#include <boost/thread/recursive_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <iostream> +#include "../../../timming.hpp" + +boost::recursive_timed_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + m.lock(); + t1 = Clock::now(); + m.lock(); + m.unlock(); + m.unlock(); +#else + //time_point t0 = Clock::now(); + m.lock(); + //time_point t1 = Clock::now(); + m.lock(); + m.unlock(); + m.unlock(); + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/native_handle_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/native_handle_pass.cpp new file mode 100644 index 000000000..bcd375e53 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/native_handle_pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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/recursive_mutex.hpp> + +// class recursive_timed_mutex; + +// typedef pthread_recursive_mutex_t* native_handle_type; +// native_handle_type native_handle(); + +#include <boost/thread/recursive_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ +#if defined BOOST_THREAD_DEFINES_RECURSIVE_TIMED_MUTEX_NATIVE_HANDLE + boost::recursive_timed_mutex m; + boost::recursive_timed_mutex::native_handle_type h = m.native_handle(); + BOOST_TEST(h); +#else +#error "Test not applicable: BOOST_THREAD_DEFINES_RECURSIVE_TIMED_MUTEX_NATIVE_HANDLE not defined for this platform as not supported" +#endif + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_for_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_for_pass.cpp new file mode 100644 index 000000000..c7f6d2b0b --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_for_pass.cpp @@ -0,0 +1,92 @@ +//===----------------------------------------------------------------------===// +// +// 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/recursive_mutex.hpp> + +// class recursive_timed_mutex; + +// template <class Rep, class Period> +// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time); + +#include <boost/thread/recursive_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + +#if defined BOOST_THREAD_USES_CHRONO + +boost::recursive_timed_mutex m; + +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f1() +{ + t0 = Clock::now(); + BOOST_TEST(m.try_lock_for(ms(750)) == true); + t1 = Clock::now(); + BOOST_TEST(m.try_lock()); + m.unlock(); + m.unlock(); +} + +void f2() +{ + time_point t0 = Clock::now(); + BOOST_TEST(m.try_lock_for(ms(250)) == false); + time_point t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); + m.unlock(); + t.join(); + + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(750)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + +#else +#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported" +#endif + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_pass.cpp new file mode 100644 index 000000000..3874d6853 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_pass.cpp @@ -0,0 +1,95 @@ +//===----------------------------------------------------------------------===// +// +// 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/recursive_mutex.hpp> + +// class recursive_timed_mutex; + +// bool try_lock(); + +#include <boost/thread/recursive_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + +boost::recursive_timed_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + while (!m.try_lock()) + ; + t1 = Clock::now(); + BOOST_TEST(m.try_lock()); + m.unlock(); + m.unlock(); +#else + //time_point t0 = Clock::now(); + //BOOST_TEST(!m.try_lock()); + //BOOST_TEST(!m.try_lock()); + //BOOST_TEST(!m.try_lock()); + while (!m.try_lock()) + ; + //time_point t1 = Clock::now(); + BOOST_TEST(m.try_lock()); + m.unlock(); + m.unlock(); + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_until_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_until_pass.cpp new file mode 100644 index 000000000..238467204 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_until_pass.cpp @@ -0,0 +1,92 @@ +//===----------------------------------------------------------------------===// +// +// 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/recursive_mutex> + +// class recursive_timed_mutex; + +// template <class Clock, class Duration> +// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time); + +#include <boost/thread/recursive_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + +#if defined BOOST_THREAD_USES_CHRONO + +boost::recursive_timed_mutex m; + +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f1() +{ + t0 = Clock::now(); + BOOST_TEST(m.try_lock_until(Clock::now() + ms(750)) == true); + t1 = Clock::now(); + m.unlock(); +} + +void f2() +{ + t0 = Clock::now(); + BOOST_TEST(m.try_lock_until(Clock::now() + ms(250)) == false); + t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(750)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + +#else +#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported" +#endif + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/assign_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/assign_fail.cpp new file mode 100644 index 000000000..ee6446d7e --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/assign_fail.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/shared_mutex.hpp> + +// class shared_mutex; + +// shared_mutex& operator=(const shared_mutex&) = delete; + +#include <boost/thread/shared_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::shared_mutex m0; + boost::shared_mutex m1(m0); +} + +#include "../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/copy_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/copy_fail.cpp new file mode 100644 index 000000000..9627f9f66 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/copy_fail.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/shared_mutex.hpp> + +// class shared_mutex; + +// shared_mutex(const shared_mutex&) = delete; + +#include <boost/thread/shared_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::shared_mutex m0; + boost::shared_mutex m1(m0); +} + +#include "../../../remove_error_code_unused_warning.hpp" + + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/default_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/default_pass.cpp new file mode 100644 index 000000000..730c9cafc --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/default_pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/timed_mutex.hpp> + +// class shared_mutex; + +// shared_mutex(); + +#include <boost/thread/shared_mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::shared_mutex m0; + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/lock_pass.cpp new file mode 100644 index 000000000..0b53fb275 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/lock_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) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/shared_mutex.hpp> + +// class shared_mutex; + +// void lock(); + +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + +boost::shared_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + m.lock(); + t1 = Clock::now(); + m.unlock(); +#else + //time_point t0 = Clock::now(); + m.lock(); + //time_point t1 = Clock::now(); + m.unlock(); + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/try_lock_for_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/try_lock_for_pass.cpp new file mode 100644 index 000000000..bc06576ec --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/try_lock_for_pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// 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) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/shared_mutex.hpp> + +// class shared_mutex; + +// template <class Rep, class Period> +// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time); + +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + +boost::shared_mutex m; + +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f1() +{ + t0 = Clock::now(); + BOOST_TEST(m.try_lock_for(ms(750)) == true); + t1 = Clock::now(); + m.unlock(); +} + +void f2() +{ + t0 = Clock::now(); + BOOST_TEST(m.try_lock_for(ms(250)) == false); + t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(750)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/try_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/try_lock_pass.cpp new file mode 100644 index 000000000..515589a6f --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/try_lock_pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// 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) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/shared_mutex.hpp> + +// class shared_mutex; + +// bool try_lock(); + +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + +boost::shared_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + while (!m.try_lock()) + ; + t1 = Clock::now(); + m.unlock(); +#else + //time_point t0 = Clock::now(); + //BOOST_TEST(!m.try_lock()); + //BOOST_TEST(!m.try_lock()); + //BOOST_TEST(!m.try_lock()); + while (!m.try_lock()) + ; + //time_point t1 = Clock::now(); + m.unlock(); + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/try_lock_until_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/try_lock_until_pass.cpp new file mode 100644 index 000000000..dd8a1a816 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/shared_mutex/try_lock_until_pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// 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) 2012 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/shared_mutex.hpp> + +// class shared_mutex; + +// template <class Clock, class Duration> +// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time); + +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + +boost::shared_mutex m; + +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f1() +{ + t0 = Clock::now(); + BOOST_TEST(m.try_lock_until(Clock::now() + ms(750)) == true); + t1 = Clock::now(); + m.unlock(); +} + +void f2() +{ + t0 = Clock::now(); + BOOST_TEST(m.try_lock_until(Clock::now() + ms(250)) == false); + t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); + m.unlock(); + t.join(); + + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(750)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/sync_bounded_queue/multi_thread_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_bounded_queue/multi_thread_pass.cpp new file mode 100644 index 000000000..9975a995a --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_bounded_queue/multi_thread_pass.cpp @@ -0,0 +1,252 @@ +// Copyright (C) 2013 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/sync_bounded_queue.hpp> + +// class sync_queue<T> + +// push || pull; + +#include <boost/config.hpp> +#if ! defined BOOST_NO_CXX11_DECLTYPE +#define BOOST_RESULT_OF_USE_DECLTYPE +#endif + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/sync_bounded_queue.hpp> +#include <boost/thread/future.hpp> +#include <boost/thread/barrier.hpp> + +#include <boost/detail/lightweight_test.hpp> + +struct call_push +{ + boost::sync_bounded_queue<int> &q_; + boost::barrier& go_; + + call_push(boost::sync_bounded_queue<int> &q, boost::barrier &go) : + q_(q), go_(go) + { + } + typedef void result_type; + void operator()() + { + go_.count_down_and_wait(); + q_.push(42); + + } +}; + +struct call_push_2 +{ + boost::sync_bounded_queue<int> &q_; + boost::barrier& go_; + boost::barrier& end_; + + call_push_2(boost::sync_bounded_queue<int> &q, boost::barrier &go, boost::barrier &end) : + q_(q), go_(go), end_(end) + { + } + typedef void result_type; + void operator()() + { + go_.count_down_and_wait(); + q_.push(42); + end_.count_down_and_wait(); + + } +}; + +struct call_pull +{ + boost::sync_bounded_queue<int> &q_; + boost::barrier& go_; + + call_pull(boost::sync_bounded_queue<int> &q, boost::barrier &go) : + q_(q), go_(go) + { + } + typedef int result_type; + int operator()() + { + go_.count_down_and_wait(); + return q_.pull(); + } +}; + +void test_concurrent_push_and_pull_on_empty_queue() +{ + boost::sync_bounded_queue<int> q(4); + + boost::barrier go(2); + + boost::future<void> push_done; + boost::future<int> pull_done; + + try + { + push_done=boost::async(boost::launch::async, +#if ! defined BOOST_NO_CXX11_LAMBDAS + [&q,&go]() + { + go.wait(); + q.push(42); + } +#else + call_push(q,go) +#endif + ); + pull_done=boost::async(boost::launch::async, +#if ! defined BOOST_NO_CXX11_LAMBDAS + [&q,&go]() -> int + { + go.wait(); + return q.pull(); + } +#else + call_pull(q,go) +#endif + ); + + push_done.get(); + BOOST_TEST_EQ(pull_done.get(), 42); + BOOST_TEST(q.empty()); + } + catch (...) + { + BOOST_TEST(false); + } +} + +void test_concurrent_push_on_empty_queue() +{ + boost::sync_bounded_queue<int> q(4); + const unsigned int n = 3; + boost::barrier go(n); + boost::future<void> push_done[n]; + + try + { + for (unsigned int i =0; i< n; ++i) + push_done[i]=boost::async(boost::launch::async, +#if ! defined BOOST_NO_CXX11_LAMBDAS + [&q,&go]() + { + go.wait(); + q.push(42); + } +#else + call_push(q,go) +#endif + ); + + for (unsigned int i = 0; i < n; ++i) + push_done[i].get(); + + BOOST_TEST(!q.empty()); + for (unsigned int i =0; i< n; ++i) + BOOST_TEST_EQ(q.pull(), 42); + BOOST_TEST(q.empty()); + + } + catch (...) + { + BOOST_TEST(false); + } +} + +void test_concurrent_push_on_full_queue() +{ + const unsigned int size = 2; + boost::sync_bounded_queue<int> q(size); + const unsigned int n = 2*size; + boost::barrier go(n); + boost::barrier end(size+1); + boost::future<void> push_done[n]; + + try + { + for (unsigned int i =0; i< n; ++i) + push_done[i]=boost::async(boost::launch::async, +#if ! defined BOOST_NO_CXX11_LAMBDAS + [&q,&go,&end]() + { + go.wait(); + q.push(42); + end.wait(); + } +#else + call_push_2(q,go,end) +#endif + ); + + end.wait(); + BOOST_TEST(!q.empty()); + BOOST_TEST(q.full()); + for (unsigned int i =0; i< size; ++i) + BOOST_TEST_EQ(q.pull(), 42); + end.wait(); + + for (unsigned int i = 0; i < n; ++i) + push_done[i].get(); + + BOOST_TEST(!q.empty()); + for (unsigned int i =0; i< size; ++i) + BOOST_TEST_EQ(q.pull(), 42); + BOOST_TEST(q.empty()); + + } + catch (...) + { + BOOST_TEST(false); + } +} +void test_concurrent_pull_on_queue() +{ + boost::sync_bounded_queue<int> q(4); + const unsigned int n = 3; + boost::barrier go(n); + + boost::future<int> pull_done[n]; + + try + { + for (unsigned int i =0; i< n; ++i) + q.push(42); + + for (unsigned int i =0; i< n; ++i) + pull_done[i]=boost::async(boost::launch::async, +#if ! defined BOOST_NO_CXX11_LAMBDAS + [&q,&go]() -> int + { + go.wait(); + return q.pull(); + } +#else + call_pull(q,go) +#endif + ); + + for (unsigned int i = 0; i < n; ++i) + BOOST_TEST_EQ(pull_done[i].get(), 42); + BOOST_TEST(q.empty()); + } + catch (...) + { + BOOST_TEST(false); + } +} + +int main() +{ + test_concurrent_push_and_pull_on_empty_queue(); + test_concurrent_push_on_empty_queue(); + test_concurrent_push_on_full_queue(); + test_concurrent_pull_on_queue(); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/sync_bounded_queue/single_thread_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_bounded_queue/single_thread_pass.cpp new file mode 100644 index 000000000..201e0bc13 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_bounded_queue/single_thread_pass.cpp @@ -0,0 +1,600 @@ +// Copyright (C) 2013 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/sync_bounded_queue.hpp> + +// class sync_bounded_queue<T> + +// sync_bounded_queue(); + +#define BOOST_THREAD_VERSION 4 +//#define BOOST_THREAD_QUEUE_DEPRECATE_OLD + +#include <boost/thread/sync_bounded_queue.hpp> + +#include <boost/detail/lightweight_test.hpp> + +class non_copyable +{ + BOOST_THREAD_MOVABLE_ONLY(non_copyable) + int val; +public: + non_copyable() {} + non_copyable(int v) : val(v){} + non_copyable(BOOST_RV_REF(non_copyable) x): val(x.val) {} + non_copyable& operator=(BOOST_RV_REF(non_copyable) x) { val=x.val; return *this; } + bool operator==(non_copyable const& x) const {return val==x.val;} + template <typename OSTREAM> + friend OSTREAM& operator <<(OSTREAM& os, non_copyable const&x ) + { + os << x.val; + return os; + } + +}; + + +int main() +{ + + { + // default queue invariants + boost::sync_bounded_queue<int> q(2); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST_EQ(q.capacity(), 2u); + BOOST_TEST(! q.closed()); + } +#ifndef BOOST_THREAD_QUEUE_DEPRECATE_OLD + { + // empty queue try_pull fails + boost::sync_bounded_queue<int> q(2); + int i; + BOOST_TEST(! q.try_pull(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_pull fails + boost::sync_bounded_queue<int> q(2); + BOOST_TEST(! q.try_pull()); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push rvalue succeeds + boost::sync_bounded_queue<int> q(2); + q.push(1); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push rvalue succeeds + boost::sync_bounded_queue<non_copyable> q(2); + non_copyable nc(1); + q.push(boost::move(nc)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push rvalue succeeds + boost::sync_bounded_queue<int> q(3); + q.push(1); + BOOST_TEST_EQ(q.size(), 1u); + q.push(2); + BOOST_TEST_EQ(q.size(), 2u); + q.push(2); + BOOST_TEST_EQ(q.size(), 3u); + BOOST_TEST(! q.empty()); + BOOST_TEST( q.full()); + BOOST_TEST(! q.closed()); + } + { + // empty queue push value succeeds + boost::sync_bounded_queue<int> q(2); + int i; + q.push(i); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue succeeds + boost::sync_bounded_queue<int> q(2); + BOOST_TEST(q.try_push(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue succeeds + boost::sync_bounded_queue<non_copyable> q(2); + non_copyable nc(1); + BOOST_TEST(q.try_push(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push value succeeds + boost::sync_bounded_queue<int> q(2); + int i=1; + BOOST_TEST(q.try_push(i)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue succeeds + boost::sync_bounded_queue<int> q(2); + BOOST_TEST(q.try_push(boost::no_block, 1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue succeeds + boost::sync_bounded_queue<non_copyable> q(2); + non_copyable nc(1); + BOOST_TEST(q.try_push(boost::no_block, boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull succeed + boost::sync_bounded_queue<int> q(2); + q.push(1); + int i; + q.pull(i); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull succeed + boost::sync_bounded_queue<non_copyable> q(2); + non_copyable nc(1); + q.push(boost::move(nc)); + non_copyable nc2(2); + q.pull(nc2); + BOOST_TEST_EQ(nc, nc2); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull succeed + boost::sync_bounded_queue<int> q(2); + q.push(1); + int i = q.pull(); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue try_pull succeed + boost::sync_bounded_queue<int> q(2); + q.push(1); + int i; + BOOST_TEST(q.try_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue try_pull succeed + boost::sync_bounded_queue<int> q(2); + q.push(1); + int i; + BOOST_TEST(q.try_pull(boost::no_block, i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue try_pull succeed + boost::sync_bounded_queue<int> q(2); + q.push(1); + boost::shared_ptr<int> i = q.try_pull(); + BOOST_TEST_EQ(*i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // full queue try_push rvalue fails + boost::sync_bounded_queue<int> q(2); + q.push(1); + q.push(2); + BOOST_TEST(! q.try_push(3)); + BOOST_TEST(! q.empty()); + BOOST_TEST( q.full()); + BOOST_TEST_EQ(q.size(), 2u); + BOOST_TEST(! q.closed()); + } + { + // full queue try_push succeeds + boost::sync_bounded_queue<int> q(2); + q.push(1); + q.push(2); + BOOST_TEST(q.try_pull()); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + + { + // closed invariants + boost::sync_bounded_queue<int> q(2); + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed queue push fails + boost::sync_bounded_queue<int> q(2); + q.close(); + try { + q.push(1); + BOOST_TEST(false); + } catch (...) { + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + } + { + // 1-element closed queue pull succeed + boost::sync_bounded_queue<int> q(2); + q.push(1); + q.close(); + int i; + q.pull(i); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } +#endif + { + // empty queue try_pull fails + boost::sync_bounded_queue<int> q(2); + int i; + BOOST_TEST( boost::queue_op_status::empty == q.try_pull_front(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push rvalue succeeds + boost::sync_bounded_queue<int> q(2); + q.push_back(1); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push rvalue succeeds + boost::sync_bounded_queue<non_copyable> q(2); + non_copyable nc(1); + q.push_back(boost::move(nc)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push rvalue succeeds + boost::sync_bounded_queue<int> q(3); + q.push_back(1); + BOOST_TEST_EQ(q.size(), 1u); + q.push_back(2); + BOOST_TEST_EQ(q.size(), 2u); + q.push_back(3); + BOOST_TEST_EQ(q.size(), 3u); + BOOST_TEST(! q.empty()); + BOOST_TEST( q.full()); + BOOST_TEST(! q.closed()); + } + { + // empty queue push value succeeds + boost::sync_bounded_queue<int> q(2); + int i; + q.push_back(i); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue succeeds + boost::sync_bounded_queue<int> q(2); + BOOST_TEST(boost::queue_op_status::success == q.try_push_back(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue succeeds + boost::sync_bounded_queue<non_copyable> q(2); + non_copyable nc(1); + BOOST_TEST(boost::queue_op_status::success == q.try_push_back(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push value succeeds + boost::sync_bounded_queue<int> q(2); + int i=1; + BOOST_TEST(boost::queue_op_status::success == q.try_push_back(i)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue succeeds + boost::sync_bounded_queue<int> q(2); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push_back( 1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue succeeds + boost::sync_bounded_queue<non_copyable> q(2); + non_copyable nc(1); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push_back(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue wait_push rvalue succeeds + boost::sync_bounded_queue<int> q(2); + BOOST_TEST(boost::queue_op_status::success == q.wait_push_back(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue wait_push rvalue succeeds + boost::sync_bounded_queue<non_copyable> q(2); + non_copyable nc(1); + BOOST_TEST(boost::queue_op_status::success == q.wait_push_back(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue wait_push value succeeds + boost::sync_bounded_queue<int> q(2); + int i; + BOOST_TEST(boost::queue_op_status::success == q.wait_push_back(i)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull succeed + boost::sync_bounded_queue<int> q(2); + q.push_back(1); + int i; + q.pull_front(i); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull succeed + boost::sync_bounded_queue<non_copyable> q(2); + non_copyable nc(1); + q.push_back(boost::move(nc)); + non_copyable nc2(2); + q.pull_front(nc2); + BOOST_TEST_EQ(nc, nc2); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull succeed + boost::sync_bounded_queue<int> q(2); + q.push_back(1); + int i = q.pull_front(); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue try_pull succeed + boost::sync_bounded_queue<int> q(2); + q.push_back(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.try_pull_front(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue nonblocking_pull_front succeed + boost::sync_bounded_queue<int> q(2); + q.push_back(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull_front(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue wait_pull_front succeed + boost::sync_bounded_queue<int> q(2); + q.push_back(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.wait_pull_front(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // full queue try_push rvalue fails + boost::sync_bounded_queue<int> q(2); + q.push_back(1); + q.push_back(2); + BOOST_TEST(boost::queue_op_status::full == q.try_push_back(3)); + BOOST_TEST(! q.empty()); + BOOST_TEST( q.full()); + BOOST_TEST_EQ(q.size(), 2u); + BOOST_TEST(! q.closed()); + } + + { + // closed invariants + boost::sync_bounded_queue<int> q(2); + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed queue push fails + boost::sync_bounded_queue<int> q(2); + q.close(); + try { + q.push_back(1); + BOOST_TEST(false); + } catch (...) { + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + } + { + // closed empty queue try_pull_front closed + boost::sync_bounded_queue<int> q(2); + q.close(); + int i; + BOOST_TEST(boost::queue_op_status::closed == q.try_pull_front(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed empty queue nonblocking_pull_front closed + boost::sync_bounded_queue<int> q(2); + q.close(); + int i; + BOOST_TEST(boost::queue_op_status::closed == q.nonblocking_pull_front(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // 1-element closed queue pull_front succeed + boost::sync_bounded_queue<int> q(2); + q.push_back(1); + q.close(); + int i; + q.pull_front(i); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // 1-element closed queue wait_pull_front succeed + boost::sync_bounded_queue<int> q(2); + q.push_back(1); + q.close(); + int i; + BOOST_TEST(boost::queue_op_status::success == q.wait_pull_front(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed empty queue wait_pull_front closed + boost::sync_bounded_queue<int> q(2); + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + int i; + BOOST_TEST(boost::queue_op_status::closed == q.wait_pull_front(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + } + { + // closed queue wait_push_back fails + boost::sync_bounded_queue<int> q(2); + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + int i; + BOOST_TEST(boost::queue_op_status::closed == q.wait_push_back(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + } + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/sync_deque/multi_thread_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_deque/multi_thread_pass.cpp new file mode 100644 index 000000000..703c54f40 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_deque/multi_thread_pass.cpp @@ -0,0 +1,256 @@ +// Copyright (C) 2013 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/concurrent_queues/sync_deque.hpp> + +// class sync_deque<T> + +// push || pull; + +#include <boost/config.hpp> +#if ! defined BOOST_NO_CXX11_DECLTYPE +#define BOOST_RESULT_OF_USE_DECLTYPE +#endif + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/concurrent_queues/sync_deque.hpp> +#include <boost/thread/future.hpp> +#include <boost/thread/barrier.hpp> + +#include <boost/detail/lightweight_test.hpp> + +template <typename ValueType> +struct call_push_back +{ + boost::sync_deque<ValueType> *q_; + boost::barrier *go_; + + call_push_back(boost::sync_deque<ValueType> *q, boost::barrier *go) : + q_(q), go_(go) + { + } + typedef void result_type; + void operator()() + { + go_->count_down_and_wait(); + q_->push_back(42); + } +}; + +template <typename ValueType> +struct call_pull_front +{ + boost::sync_deque<ValueType> *q_; + boost::barrier *go_; + + call_pull_front(boost::sync_deque<ValueType> *q, boost::barrier *go) : + q_(q), go_(go) + { + } + typedef ValueType result_type; + ValueType operator()() + { + go_->count_down_and_wait(); + return q_->pull_front(); + } +}; + +template <typename ValueType> +struct call_wait_pull_front +{ + boost::sync_deque<ValueType> *q_; + boost::barrier *go_; + + call_wait_pull_front(boost::sync_deque<ValueType> *q, boost::barrier *go) : + q_(q), go_(go) + { + } + typedef boost::queue_op_status result_type; + boost::queue_op_status operator()(ValueType& v) + { + go_->wait(); + return q_->wait_pull_front(v); + } +}; + +void test_concurrent_push_back_and_pull_front_on_empty_queue() +{ + boost::sync_deque<int> q; + + boost::barrier go(2); + + boost::future<void> push_done; + boost::future<int> pull_done; + + try + { + push_done=boost::async(boost::launch::async, + call_push_back<int>(&q,&go)); + pull_done=boost::async(boost::launch::async, + call_pull_front<int>(&q,&go)); + + push_done.get(); + BOOST_TEST_EQ(pull_done.get(), 42); + BOOST_TEST(q.empty()); + } + catch (...) + { + BOOST_TEST(false); + } +} + +#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) +void test_concurrent_push_back_and_wait_pull_front_on_empty_queue() +{ + boost::sync_deque<int> q; + const unsigned int n = 3; + boost::barrier go(n); + + boost::future<boost::queue_op_status> pull_done[n]; + int results[n]; + + try + { + for (unsigned int i =0; i< n; ++i) + pull_done[i]=boost::async(boost::launch::async, + call_wait_pull_front<int>(&q,&go), + boost::ref(results[i])); + + for (unsigned int i =0; i< n; ++i) + q.push_back(42); + + for (unsigned int i = 0; i < n; ++i) { + BOOST_TEST(pull_done[i].get() == boost::queue_op_status::success); + BOOST_TEST_EQ(results[i], 42); + } + BOOST_TEST(q.empty()); + } + catch (...) + { + BOOST_TEST(false); + } +} + +void test_concurrent_wait_pull_front_and_close_on_empty_queue() +{ + boost::sync_deque<int> q; + const unsigned int n = 3; + boost::barrier go(n); + + boost::future<boost::queue_op_status> pull_done[n]; + int results[n]; + + try + { + for (unsigned int i =0; i< n; ++i) + pull_done[i]=boost::async(boost::launch::async, + call_wait_pull_front<int>(&q,&go), + boost::ref(results[i])); + + q.close(); + + for (unsigned int i = 0; i < n; ++i) { + BOOST_TEST(pull_done[i].get() == boost::queue_op_status::closed); + } + BOOST_TEST(q.empty()); + } + catch (...) + { + BOOST_TEST(false); + } +} +#endif + +void test_concurrent_push_back_on_empty_queue() +{ + boost::sync_deque<int> q; + const unsigned int n = 3; + boost::barrier go(n); + boost::future<void> push_done[n]; + + try + { + for (unsigned int i =0; i< n; ++i) + push_done[i]=boost::async(boost::launch::async, + call_push_back<int>(&q,&go)); + + } + catch (...) + { + BOOST_TEST(false); + } + try + { + for (unsigned int i = 0; i < n; ++i) + push_done[i].get(); + + } + catch (...) + { + BOOST_TEST(false); + } + try + { + BOOST_TEST(!q.empty()); + for (unsigned int i =0; i< n; ++i) + BOOST_TEST_EQ(q.pull_front(), 42); + BOOST_TEST(q.empty()); + + } + catch (...) + { + BOOST_TEST(false); + } +} + +void test_concurrent_pull_front_on_queue() +{ + boost::sync_deque<int> q; + const unsigned int n = 3; + boost::barrier go(n); + + boost::future<int> pull_done[n]; + + try + { + for (unsigned int i =0; i< n; ++i) + q.push_back(42); + + for (unsigned int i =0; i< n; ++i) + pull_done[i]=boost::async(boost::launch::async, +#if ! defined BOOST_NO_CXX11_LAMBDAS + [&q,&go]() -> int + { + go.wait(); + return q.pull_front(); + } +#else + call_pull_front<int>(&q,&go) +#endif + ); + + for (unsigned int i = 0; i < n; ++i) + BOOST_TEST_EQ(pull_done[i].get(), 42); + BOOST_TEST(q.empty()); + } + catch (...) + { + BOOST_TEST(false); + } +} + +int main() +{ + test_concurrent_push_back_and_pull_front_on_empty_queue(); +#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) + test_concurrent_push_back_and_wait_pull_front_on_empty_queue(); + test_concurrent_wait_pull_front_and_close_on_empty_queue(); +#endif + test_concurrent_push_back_on_empty_queue(); + test_concurrent_pull_front_on_queue(); + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/sync_deque/single_thread_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_deque/single_thread_pass.cpp new file mode 100644 index 000000000..5170bcf61 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_deque/single_thread_pass.cpp @@ -0,0 +1,403 @@ +// Copyright (C) 2013,2015 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/concurrent_queues/sync_deque.hpp> + +// class sync_deque<T> + +// sync_deque(); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/concurrent_queues/sync_deque.hpp> + +#include <boost/detail/lightweight_test.hpp> + +class non_copyable +{ + BOOST_THREAD_MOVABLE_ONLY(non_copyable) + int val; +public: + non_copyable(int v) : val(v){} + non_copyable(BOOST_RV_REF(non_copyable) x): val(x.val) {} + non_copyable& operator=(BOOST_RV_REF(non_copyable) x) { val=x.val; return *this; } + bool operator==(non_copyable const& x) const {return val==x.val;} + template <typename OSTREAM> + friend OSTREAM& operator <<(OSTREAM& os, non_copyable const&x ) + { + os << x.val; + return os; + } + +}; + + + +int main() +{ + + { + // default queue invariants + boost::sync_deque<int> q; + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_pull fails + boost::sync_deque<int> q; + int i; + BOOST_TEST( boost::queue_op_status::empty == q.try_pull_front(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push rvalue/copyable succeeds + boost::sync_deque<int> q; + q.push_back(1); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push lvalue/copyable succeeds + boost::sync_deque<int> q; + int i; + q.push_back(i); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + { + // empty queue push rvalue/non_copyable succeeds + boost::sync_deque<non_copyable> q; + q.push_back(non_copyable(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + { + // empty queue push rvalue/non_copyable succeeds + boost::sync_deque<non_copyable> q; + non_copyable nc(1); + q.push_back(boost::move(nc)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + + { + // empty queue push rvalue succeeds + boost::sync_deque<int> q; + q.push_back(1); + q.push_back(2); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 2u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push lvalue succeeds + boost::sync_deque<int> q; + int i; + q.push_back(i); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue/copyable succeeds + boost::sync_deque<int> q; + BOOST_TEST(boost::queue_op_status::success == q.try_push_back(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue/copyable succeeds + boost::sync_deque<int> q; + BOOST_TEST(boost::queue_op_status::success == q.try_push_back(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + { + // empty queue try_push rvalue/non-copyable succeeds + boost::sync_deque<non_copyable> q; + BOOST_TEST(boost::queue_op_status::success ==q.try_push_back(non_copyable(1))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + { + // empty queue try_push rvalue/non-copyable succeeds + boost::sync_deque<non_copyable> q; + non_copyable nc(1); + BOOST_TEST(boost::queue_op_status::success == q.try_push_back(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + + { + // empty queue try_push lvalue succeeds + boost::sync_deque<int> q; + int i=1; + BOOST_TEST(boost::queue_op_status::success == q.try_push_back(i)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue succeeds + boost::sync_deque<int> q; + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push_back(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + { + // empty queue nonblocking_push_back rvalue/non-copyable succeeds + boost::sync_deque<non_copyable> q; + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push_back(non_copyable(1))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + { + // empty queue nonblocking_push_back rvalue/non-copyable succeeds + boost::sync_deque<non_copyable> q; + non_copyable nc(1); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push_back(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull_front succeed + boost::sync_deque<int> q; + q.push_back(1); + int i; + q.pull_front(i); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull_front succeed + boost::sync_deque<non_copyable> q; + non_copyable nc1(1); + q.push_back(boost::move(nc1)); + non_copyable nc2(2); + q.pull_front(nc2); + BOOST_TEST_EQ(nc1, nc2); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull_front succeed + boost::sync_deque<int> q; + q.push_back(1); + int i = q.pull_front(); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull_front succeed + boost::sync_deque<non_copyable> q; + non_copyable nc1(1); + q.push_back(boost::move(nc1)); + non_copyable nc = q.pull_front(); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue try_pull_front succeed + boost::sync_deque<int> q; + q.push_back(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.try_pull_front(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue try_pull_front succeed + boost::sync_deque<non_copyable> q; + non_copyable nc1(1); + q.push_back(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.try_pull_front(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue nonblocking_pull_front succeed + boost::sync_deque<int> q; + q.push_back(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull_front(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue nonblocking_pull_front succeed + boost::sync_deque<non_copyable> q; + non_copyable nc1(1); + q.push_back(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull_front(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue wait_pull_front succeed + boost::sync_deque<non_copyable> q; + non_copyable nc1(1); + q.push_back(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.wait_pull_front(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue wait_pull_front succeed + boost::sync_deque<int> q; + q.push_back(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.wait_pull_front(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue wait_pull_front succeed + boost::sync_deque<non_copyable> q; + non_copyable nc1(1); + q.push_back(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.wait_pull_front(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + + { + // closed invariants + boost::sync_deque<int> q; + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed queue push fails + boost::sync_deque<int> q; + q.close(); + try { + q.push_back(1); + BOOST_TEST(false); + } catch (...) { + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + } + { + // 1-element closed queue pull succeed + boost::sync_deque<int> q; + q.push_back(1); + q.close(); + int i; + q.pull_front(i); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // 1-element closed queue wait_pull_front succeed + boost::sync_deque<int> q; + q.push_back(1); + q.close(); + int i; + BOOST_TEST(boost::queue_op_status::success == q.wait_pull_front(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed empty queue wait_pull_front fails + boost::sync_deque<int> q; + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + int i; + BOOST_TEST(boost::queue_op_status::closed == q.wait_pull_front(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/sync_pq/pq_multi_thread_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_pq/pq_multi_thread_pass.cpp new file mode 100644 index 000000000..92e183079 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_pq/pq_multi_thread_pass.cpp @@ -0,0 +1,219 @@ +// Copyright (C) 2014 Ian Forbed +// Copyright (C) 2014 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) +// + +#include <boost/config.hpp> +#if ! defined BOOST_NO_CXX11_DECLTYPE +#define BOOST_RESULT_OF_USE_DECLTYPE +#endif + +#define BOOST_THREAD_VERSION 4 +#define BOOST_THREAD_PROVIDES_EXECUTORS + +#include <exception> + +#include <boost/thread/thread.hpp> +#include <boost/thread/barrier.hpp> +#include <boost/thread/concurrent_queues/sync_priority_queue.hpp> + +#include <boost/core/lightweight_test.hpp> + +#ifdef BOOST_MSVC +#pragma warning(disable: 4127) // conditional expression is constant +#endif + +typedef boost::concurrent::sync_priority_queue<int> sync_pq; + +int call_pull(sync_pq* q, boost::barrier* go) +{ + go->wait(); + return q->pull(); + +} + +void call_push(sync_pq* q, boost::barrier* go, int val) +{ + go->wait(); + q->push(val); +} + +void test_pull(const int n) +{ + sync_pq pq; + BOOST_TEST(pq.empty()); + for(int i = 0; i < n; i++) + { + pq.push(i); + } + BOOST_TEST(!pq.empty()); + BOOST_TEST_EQ(pq.size(), std::size_t(n)); + pq.close(); + BOOST_TEST(pq.closed()); + boost::barrier b(n); + boost::thread_group tg; + for(int i = 0; i < n; i++) + { + tg.create_thread(boost::bind(call_pull, &pq, &b)); + } + tg.join_all(); + BOOST_TEST(pq.empty()); +} + +void test_push(const int n) +{ + sync_pq pq; + BOOST_TEST(pq.empty()); + + boost::barrier b(n); + boost::thread_group tg; + for(int i = 0; i < n; i++) + { + tg.create_thread(boost::bind(call_push, &pq, &b, i)); + } + tg.join_all(); + BOOST_TEST(!pq.empty()); + BOOST_TEST_EQ(pq.size(), std::size_t(n)); +} + +void test_both(const int n) +{ + sync_pq pq; + BOOST_TEST(pq.empty()); + + boost::barrier b(2*n); + boost::thread_group tg; + for(int i = 0; i < n; i++) + { + tg.create_thread(boost::bind(call_pull, &pq, &b)); + tg.create_thread(boost::bind(call_push, &pq, &b, i)); + } + tg.join_all(); + BOOST_TEST(pq.empty()); + BOOST_TEST_EQ(pq.size(), std::size_t(0)); +} + +void push_range(sync_pq* q, const int begin, const int end) +{ + for(int i = begin; i < end; i++) + q->push(i); +} + +void atomic_pull(sync_pq* q, boost::atomic<int>* sum) +{ + while(1) + { + try{ + const int val = q->pull(); + sum->fetch_add(val); + } + catch(std::exception& ){ + break; + } + } +} + +/** + * This test computes the sum of the first N integers upto $limit using + * $n threads for the push operation and $n threads for the pull and count + * operation. The push operation push a range of numbers on the queue while + * the pull operation pull from the queue and increments an atomic int. + * At the end of execution the value of atomic<int> $sum should be the same + * as n*(n+1)/2 as this is the closed form solution to this problem. + */ +void compute_sum(const int n) +{ + const int limit = 1000; + sync_pq pq; + BOOST_TEST(pq.empty()); + boost::atomic<int> sum(0); + boost::thread_group tg1; + boost::thread_group tg2; + for(int i = 0; i < n; i++) + { + tg1.create_thread(boost::bind(push_range, &pq, i*(limit/n)+1, (i+1)*(limit/n)+1)); + tg2.create_thread(boost::bind(atomic_pull, &pq, &sum)); + } + tg1.join_all(); + pq.close(); //Wait until all enqueuing is done before closing. + BOOST_TEST(pq.closed()); + tg2.join_all(); + BOOST_TEST(pq.empty()); + BOOST_TEST_EQ(sum.load(), limit*(limit+1)/2); +} + +void move_between_queues(sync_pq* q1, sync_pq* q2) +{ + while(1){ + try{ + const int val = q1->pull(); + q2->push(val); + } + catch(std::exception& ){ + break; + } + } +} + +/** + * This test computes the sum of the first N integers upto $limit by moving + * numbers between 2 sync_priority_queues. A range of numbers are pushed onto + * one queue by $n threads while $n threads pull from this queue and push onto + * another sync_pq. At the end the main thread ensures the the values in the + * second queue are in proper order and then sums all the values from this + * queue. The sum should match n*(n+1)/2, the closed form solution to this + * problem. + */ +void sum_with_moving(const int n) +{ + const int limit = 1000; + sync_pq pq1; + sync_pq pq2; + BOOST_TEST(pq1.empty()); + BOOST_TEST(pq2.empty()); + boost::thread_group tg1; + boost::thread_group tg2; + for(int i = 0; i < n; i++) + { + tg1.create_thread(boost::bind(push_range, &pq1, i*(limit/n)+1, (i+1)*(limit/n)+1)); + tg2.create_thread(boost::bind(move_between_queues, &pq1, &pq2)); + } + tg1.join_all(); + pq1.close(); //Wait until all enqueuing is done before closing. + BOOST_TEST(pq1.closed()); + tg2.join_all(); + BOOST_TEST(pq1.empty()); + BOOST_TEST(!pq2.empty()); + int sum = 0; + for(int i = 1000; i > 0; i--){ + const int val = pq2.pull(); + BOOST_TEST_EQ(i,val); + sum += val; + } + BOOST_TEST(pq2.empty()); + BOOST_TEST_EQ(sum, limit*(limit+1)/2); +} + +int main() +{ + for(int i = 1; i <= 64; i *= 2) + { + test_pull(i); + test_push(i); + test_both(i); + } + //These numbers must divide 1000 + compute_sum(1); + compute_sum(4); + compute_sum(10); + compute_sum(25); + compute_sum(50); + sum_with_moving(1); + sum_with_moving(4); + sum_with_moving(10); + sum_with_moving(25); + sum_with_moving(50); + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/sync_pq/pq_single_thread_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_pq/pq_single_thread_pass.cpp new file mode 100644 index 000000000..b51827731 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_pq/pq_single_thread_pass.cpp @@ -0,0 +1,429 @@ +// Copyright (C) 2014 Ian Forbed +// Copyright (C) 2014,2015 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) +// + +#include <boost/config.hpp> +#if ! defined BOOST_NO_CXX11_DECLTYPE +#define BOOST_RESULT_OF_USE_DECLTYPE +#endif + +#define BOOST_THREAD_VERSION 4 +#define BOOST_THREAD_PROVIDES_EXECUTORS + +#include <iostream> + +#include <boost/thread.hpp> +#include <boost/chrono.hpp> +#include <boost/thread/concurrent_queues/sync_priority_queue.hpp> + +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + +using namespace boost::chrono; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +typedef boost::concurrent::sync_priority_queue<int> sync_pq; + +class non_copyable +{ + BOOST_THREAD_MOVABLE_ONLY(non_copyable) + int val; +public: + non_copyable(int v) : val(v){} + non_copyable(BOOST_RV_REF(non_copyable) x): val(x.val) {} + non_copyable& operator=(BOOST_RV_REF(non_copyable) x) { val=x.val; return *this; } + bool operator==(non_copyable const& x) const {return val==x.val;} + template <typename OSTREAM> + friend OSTREAM& operator <<(OSTREAM& os, non_copyable const&x ) + { + os << x.val; + return os; + } + bool operator <(const non_copyable& other) const + { + return val < other.val; + } +}; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void test_pull_for() +{ + sync_pq pq; + steady_clock::time_point start = steady_clock::now(); + int val; + boost::queue_op_status st = pq.pull_for(milliseconds(500), val); + ns d = steady_clock::now() - start - milliseconds(500); + BOOST_THREAD_TEST_IT(d, ns(max_diff)); + BOOST_TEST(boost::queue_op_status::timeout == st); +} + +void test_pull_until() +{ + sync_pq pq; + steady_clock::time_point start = steady_clock::now(); + int val; + boost::queue_op_status st = pq.pull_until(start + milliseconds(500), val); + ns d = steady_clock::now() - start - milliseconds(500); + BOOST_THREAD_TEST_IT(d, ns(max_diff)); + BOOST_TEST(boost::queue_op_status::timeout == st); +} + +void test_nonblocking_pull() +{ + sync_pq pq; + steady_clock::time_point start = steady_clock::now(); + int val; + boost::queue_op_status st = pq.nonblocking_pull(val); + ns d = steady_clock::now() - start; + BOOST_THREAD_TEST_IT(d, ns(max_diff)); + BOOST_TEST(boost::queue_op_status::empty == st); +} + +void test_pull_for_when_not_empty() +{ + sync_pq pq; + pq.push(1); + steady_clock::time_point start = steady_clock::now(); + int val; + boost::queue_op_status st = pq.pull_for(milliseconds(500), val); + ns d = steady_clock::now() - start; + BOOST_THREAD_TEST_IT(d, ns(max_diff)); + BOOST_TEST(boost::queue_op_status::success == st); + BOOST_TEST(1 == val); +} + +void test_pull_until_when_not_empty() +{ + sync_pq pq; + pq.push(1); + steady_clock::time_point start = steady_clock::now(); + int val; + boost::queue_op_status st = pq.pull_until(start + milliseconds(500), val); + ns d = steady_clock::now() - start; + BOOST_THREAD_TEST_IT(d, ns(max_diff)); + BOOST_TEST(boost::queue_op_status::success == st); + BOOST_TEST(1 == val); +} + +int main() +{ + sync_pq pq; + BOOST_TEST(pq.empty()); + BOOST_TEST(!pq.closed()); + BOOST_TEST_EQ(pq.size(), std::size_t(0)); + + for(int i = 1; i <= 5; i++){ + pq.push(i); + BOOST_TEST(!pq.empty()); + BOOST_TEST_EQ(pq.size(), std::size_t(i)); + } + + for(int i = 6; i <= 10; i++){ + boost::queue_op_status succ = pq.try_push(i); + BOOST_TEST(succ == boost::queue_op_status::success ); + BOOST_TEST(!pq.empty()); + BOOST_TEST_EQ(pq.size(), std::size_t(i)); + } + + for(int i = 10; i > 5; i--){ + int val = pq.pull(); + BOOST_TEST_EQ(val, i); + } + +// for(int i = 5; i > 0; i--){ +// boost::optional<int> val = pq.try_pull(); +// BOOST_TEST(val); +// BOOST_TEST_EQ(*val, i); +// } + +// BOOST_TEST(pq.empty()); + pq.close(); + BOOST_TEST(pq.closed()); + + test_pull_for(); + test_pull_until(); + test_nonblocking_pull(); + + test_pull_for_when_not_empty(); + //test_pull_until_when_not_empty(); + +#if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES + { + // empty queue try_push rvalue/non-copyable succeeds + boost::concurrent::sync_priority_queue<non_copyable> q; + BOOST_TEST(boost::queue_op_status::success ==q.try_push(non_copyable(1))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + //fixme + // empty queue try_push rvalue/non-copyable succeeds + boost::concurrent::sync_priority_queue<non_copyable> q; + non_copyable nc(1); + BOOST_TEST(boost::queue_op_status::success == q.try_push(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + + { + // empty queue try_push lvalue succeeds + boost::concurrent::sync_priority_queue<int> q; + int i=1; + BOOST_TEST(boost::queue_op_status::success == q.try_push(i)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#if 0 + { + // empty queue try_push rvalue succeeds + boost::concurrent::sync_priority_queue<int> q; + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue nonblocking_push rvalue/non-copyable succeeds + boost::concurrent::sync_priority_queue<non_copyable> q; + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(non_copyable(1))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue nonblocking_push rvalue/non-copyable succeeds + boost::concurrent::sync_priority_queue<non_copyable> q; + non_copyable nc(1); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + + { + // 1-element queue pull succeed + boost::concurrent::sync_priority_queue<int> q; + q.push(1); + int i; + i=q.pull(); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES + { + // 1-element queue pull succeed + boost::concurrent::sync_priority_queue<non_copyable> q; + non_copyable nc1(1); + q.push(boost::move(nc1)); + non_copyable nc2(2); + nc2=q.pull(); + BOOST_TEST_EQ(nc1, nc2); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#endif + + { + // 1-element queue pull succeed + boost::concurrent::sync_priority_queue<int> q; + q.push(1); + int i = q.pull(); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES + { + // 1-element queue pull succeed + boost::concurrent::sync_priority_queue<non_copyable> q; + non_copyable nc1(1); + q.push(boost::move(nc1)); + non_copyable nc = q.pull(); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#endif + + { + // 1-element queue try_pull succeed + boost::concurrent::sync_priority_queue<int> q; + q.push(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.try_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES + { + // 1-element queue try_pull succeed + boost::concurrent::sync_priority_queue<non_copyable> q; + non_copyable nc1(1); + q.push(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.try_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#endif + { + // 1-element queue nonblocking_pull succeed + boost::concurrent::sync_priority_queue<int> q; + q.push(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES + { + // 1-element queue nonblocking_pull succeed + boost::concurrent::sync_priority_queue<non_copyable> q; + non_copyable nc1(1); + q.push(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue wait_pull succeed + boost::concurrent::sync_priority_queue<non_copyable> q; + non_copyable nc1(1); + q.push(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#endif + { + // 1-element queue wait_pull succeed + boost::concurrent::sync_priority_queue<int> q; + q.push(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES + { + // 1-element queue wait_pull succeed + boost::concurrent::sync_priority_queue<non_copyable> q; + non_copyable nc1(1); + q.push(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } +#endif + + { + // closed invariants + boost::concurrent::sync_priority_queue<int> q; + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed queue push fails + boost::concurrent::sync_priority_queue<int> q; + q.close(); + try { + q.push(1); + BOOST_TEST(false); // fixme + } catch (...) { + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + } + { + // 1-element closed queue pull succeed + boost::concurrent::sync_priority_queue<int> q; + q.push(1); + q.close(); + int i; + i=q.pull(); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // 1-element closed queue wait_pull succeed + boost::concurrent::sync_priority_queue<int> q; + q.push(1); + q.close(); + int i; + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed empty queue wait_pull fails + boost::concurrent::sync_priority_queue<int> q; + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + int i; + BOOST_TEST(boost::queue_op_status::closed == q.wait_pull(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/sync_pq/tq_multi_thread_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_pq/tq_multi_thread_pass.cpp new file mode 100644 index 000000000..77656f8b3 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_pq/tq_multi_thread_pass.cpp @@ -0,0 +1,124 @@ +// Copyright (C) 2019 Austin Beer +// Copyright (C) 2019 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) +// + +#include <boost/config.hpp> +#if ! defined BOOST_NO_CXX11_DECLTYPE +#define BOOST_RESULT_OF_USE_DECLTYPE +#endif + +#define BOOST_THREAD_VERSION 4 +#define BOOST_THREAD_PROVIDES_EXECUTORS + +#include <boost/thread.hpp> +#include <boost/chrono.hpp> +#include <boost/thread/concurrent_queues/sync_timed_queue.hpp> + +#include <boost/core/lightweight_test.hpp> +#include "../../../timming.hpp" + +using namespace boost::chrono; + +typedef boost::concurrent::sync_timed_queue<int> sync_tq; + +const int cnt = 5; + +void call_push(sync_tq* q, const steady_clock::time_point start) +{ + // push elements onto the queue every 500 milliseconds but with a decreasing delay each time + for (int i = 0; i < cnt; ++i) + { + boost::this_thread::sleep_until(start + milliseconds(i * 500)); + const steady_clock::time_point expected = start + milliseconds(i * 500) + seconds(cnt - i); + q->push(i, expected); + } +} + +void call_pull(sync_tq* q, const steady_clock::time_point start) +{ + // pull elements off of the queue (earliest element first) + for (int i = cnt - 1; i >= 0; --i) + { + int j; + q->pull(j); + BOOST_TEST_EQ(i, j); + const steady_clock::time_point expected = start + milliseconds(i * 500) + seconds(cnt - i); + BOOST_TEST_GE(steady_clock::now(), expected - milliseconds(BOOST_THREAD_TEST_TIME_MS)); + BOOST_TEST_LE(steady_clock::now(), expected + milliseconds(BOOST_THREAD_TEST_TIME_MS)); + } +} + +void call_pull_until(sync_tq* q, const steady_clock::time_point start) +{ + // pull elements off of the queue (earliest element first) + for (int i = cnt - 1; i >= 0; --i) + { + int j; + q->pull_until(steady_clock::now() + hours(1), j); + BOOST_TEST_EQ(i, j); + const steady_clock::time_point expected = start + milliseconds(i * 500) + seconds(cnt - i); + BOOST_TEST_GE(steady_clock::now(), expected - milliseconds(BOOST_THREAD_TEST_TIME_MS)); + BOOST_TEST_LE(steady_clock::now(), expected + milliseconds(BOOST_THREAD_TEST_TIME_MS)); + } +} + +void call_pull_for(sync_tq* q, const steady_clock::time_point start) +{ + // pull elements off of the queue (earliest element first) + for (int i = cnt - 1; i >= 0; --i) + { + int j; + q->pull_for(hours(1), j); + BOOST_TEST_EQ(i, j); + const steady_clock::time_point expected = start + milliseconds(i * 500) + seconds(cnt - i); + BOOST_TEST_GE(steady_clock::now(), expected - milliseconds(BOOST_THREAD_TEST_TIME_MS)); + BOOST_TEST_LE(steady_clock::now(), expected + milliseconds(BOOST_THREAD_TEST_TIME_MS)); + } +} + +void test_push_while_pull() +{ + sync_tq tq; + BOOST_TEST(tq.empty()); + boost::thread_group tg; + const steady_clock::time_point start = steady_clock::now(); + tg.create_thread(boost::bind(call_push, &tq, start)); + tg.create_thread(boost::bind(call_pull, &tq, start)); + tg.join_all(); + BOOST_TEST(tq.empty()); +} + +void test_push_while_pull_until() +{ + sync_tq tq; + BOOST_TEST(tq.empty()); + boost::thread_group tg; + const steady_clock::time_point start = steady_clock::now(); + tg.create_thread(boost::bind(call_push, &tq, start)); + tg.create_thread(boost::bind(call_pull_until, &tq, start)); + tg.join_all(); + BOOST_TEST(tq.empty()); +} + +void test_push_while_pull_for() +{ + sync_tq tq; + BOOST_TEST(tq.empty()); + boost::thread_group tg; + const steady_clock::time_point start = steady_clock::now(); + tg.create_thread(boost::bind(call_push, &tq, start)); + tg.create_thread(boost::bind(call_pull_for, &tq, start)); + tg.join_all(); + BOOST_TEST(tq.empty()); +} + +int main() +{ + test_push_while_pull(); + test_push_while_pull_until(); + test_push_while_pull_for(); + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/sync_pq/tq_single_thread_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_pq/tq_single_thread_pass.cpp new file mode 100644 index 000000000..dd4dfc17f --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_pq/tq_single_thread_pass.cpp @@ -0,0 +1,155 @@ +// Copyright (C) 2014 Ian Forbed +// Copyright (C) 2014 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) +// + +#include <boost/config.hpp> +#if ! defined BOOST_NO_CXX11_DECLTYPE +#define BOOST_RESULT_OF_USE_DECLTYPE +#endif + +#define BOOST_THREAD_VERSION 4 +#define BOOST_THREAD_PROVIDES_EXECUTORS + +#include <boost/thread.hpp> +#include <boost/chrono.hpp> +#include <boost/function.hpp> +#include <boost/thread/concurrent_queues/sync_timed_queue.hpp> +#include <boost/thread/executors/work.hpp> + +#include <boost/core/lightweight_test.hpp> + +using namespace boost::chrono; + +typedef boost::concurrent::sync_timed_queue<int> sync_tq; + +void test_all() +{ + sync_tq pq; + BOOST_TEST(pq.empty()); + BOOST_TEST(!pq.closed()); + BOOST_TEST_EQ(pq.size(), std::size_t(0)); + + for(int i = 1; i <= 5; i++){ + pq.push(i, milliseconds(i*100)); + BOOST_TEST(!pq.empty()); + BOOST_TEST_EQ(pq.size(), std::size_t(i)); + } + + for(int i = 6; i <= 10; i++){ + pq.push(i,steady_clock::now() + milliseconds(i*100)); + BOOST_TEST(!pq.empty()); + BOOST_TEST_EQ(pq.size(), std::size_t(i)); + } + + for(int i = 1; i <= 10; i++){ + int val = pq.pull(); + BOOST_TEST_EQ(val, i); + } + + int val; + boost::queue_op_status st = pq.nonblocking_pull(val); + BOOST_TEST(boost::queue_op_status::empty == st); + + BOOST_TEST(pq.empty()); + pq.close(); + BOOST_TEST(pq.closed()); +} + +void test_all_with_try() +{ + sync_tq pq; + BOOST_TEST(pq.empty()); + BOOST_TEST(!pq.closed()); + BOOST_TEST_EQ(pq.size(), std::size_t(0)); + + for(int i = 1; i <= 5; i++){ + boost::queue_op_status st = pq.try_push(i, milliseconds(i*100)); + BOOST_TEST(st == boost::queue_op_status::success ); + BOOST_TEST(!pq.empty()); + BOOST_TEST_EQ(pq.size(), std::size_t(i)); + } + + for(int i = 6; i <= 10; i++){ + boost::queue_op_status st = pq.try_push(i,steady_clock::now() + milliseconds(i*100)); + BOOST_TEST(st == boost::queue_op_status::success ); + BOOST_TEST(!pq.empty()); + BOOST_TEST_EQ(pq.size(), std::size_t(i)); + } + + for(int i = 1; i <= 10; i++){ + int val=0; + boost::queue_op_status st = pq.wait_pull(val); + BOOST_TEST(st == boost::queue_op_status::success ); + BOOST_TEST_EQ(val, i); + } + + int val; + boost::queue_op_status st = pq.nonblocking_pull(val); + BOOST_TEST(st == boost::queue_op_status::empty ); + + BOOST_TEST(pq.empty()); + pq.close(); + BOOST_TEST(pq.closed()); +} + +void func(steady_clock::time_point pushed, steady_clock::duration dur) +{ + BOOST_TEST(pushed + dur <= steady_clock::now()); +} +void func2() +{ + BOOST_TEST(false); +} + +/** + * This test ensures that when items come of the front of the queue + * that at least $dur has elapsed. + */ +void test_deque_times() +{ + boost::concurrent::sync_timed_queue<boost::function<void()> > tq; + for(int i = 0; i < 10; i++) + { + steady_clock::duration d = milliseconds(i*100); + boost::function<void()> fn = boost::bind(func, steady_clock::now(), d); + tq.push(fn, d); + } + while(!tq.empty()) + { + boost::function<void()> fn = tq.pull(); + fn(); + } +} + +/** + * This test ensures that when items come of the front of the queue + * that at least $dur has elapsed. + */ +#if 0 +void test_deque_times2() +{ + boost::concurrent::sync_timed_queue<boost::executors::work> tq; + for(int i = 0; i < 10; i++) + { + steady_clock::duration d = milliseconds(i*100); + tq.push(func2, d); + } + while(!tq.empty()) + { + boost::executors::work fn = tq.pull(); + fn(); + } +} +#endif + +int main() +{ + test_all(); + test_all_with_try(); + test_deque_times(); + //test_deque_times2(); // rt fails + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/sync_queue/multi_thread_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_queue/multi_thread_pass.cpp new file mode 100644 index 000000000..556ca68e9 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_queue/multi_thread_pass.cpp @@ -0,0 +1,256 @@ +// Copyright (C) 2013 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/sync_queue.hpp> + +// class sync_queue<T> + +// push || pull; + +#include <boost/config.hpp> +#if ! defined BOOST_NO_CXX11_DECLTYPE +#define BOOST_RESULT_OF_USE_DECLTYPE +#endif + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/sync_queue.hpp> +#include <boost/thread/future.hpp> +#include <boost/thread/barrier.hpp> + +#include <boost/detail/lightweight_test.hpp> + +template <typename ValueType> +struct call_push +{ + boost::sync_queue<ValueType> *q_; + boost::barrier *go_; + + call_push(boost::sync_queue<ValueType> *q, boost::barrier *go) : + q_(q), go_(go) + { + } + typedef void result_type; + void operator()() + { + go_->count_down_and_wait(); + q_->push(42); + } +}; + +template <typename ValueType> +struct call_pull +{ + boost::sync_queue<ValueType> *q_; + boost::barrier *go_; + + call_pull(boost::sync_queue<ValueType> *q, boost::barrier *go) : + q_(q), go_(go) + { + } + typedef ValueType result_type; + ValueType operator()() + { + go_->count_down_and_wait(); + return q_->pull(); + } +}; + +template <typename ValueType> +struct call_wait_pull +{ + boost::sync_queue<ValueType> *q_; + boost::barrier *go_; + + call_wait_pull(boost::sync_queue<ValueType> *q, boost::barrier *go) : + q_(q), go_(go) + { + } + typedef boost::queue_op_status result_type; + boost::queue_op_status operator()(ValueType& v) + { + go_->wait(); + return q_->wait_pull(v); + } +}; + +void test_concurrent_push_and_pull_on_empty_queue() +{ + boost::sync_queue<int> q; + + boost::barrier go(2); + + boost::future<void> push_done; + boost::future<int> pull_done; + + try + { + push_done=boost::async(boost::launch::async, + call_push<int>(&q,&go)); + pull_done=boost::async(boost::launch::async, + call_pull<int>(&q,&go)); + + push_done.get(); + BOOST_TEST_EQ(pull_done.get(), 42); + BOOST_TEST(q.empty()); + } + catch (...) + { + BOOST_TEST(false); + } +} + +#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) +void test_concurrent_push_and_wait_pull_on_empty_queue() +{ + boost::sync_queue<int> q; + const unsigned int n = 3; + boost::barrier go(n); + + boost::future<boost::queue_op_status> pull_done[n]; + int results[n]; + + try + { + for (unsigned int i =0; i< n; ++i) + pull_done[i]=boost::async(boost::launch::async, + call_wait_pull<int>(&q,&go), + boost::ref(results[i])); + + for (unsigned int i =0; i< n; ++i) + q.push(42); + + for (unsigned int i = 0; i < n; ++i) { + BOOST_TEST(pull_done[i].get() == boost::queue_op_status::success); + BOOST_TEST_EQ(results[i], 42); + } + BOOST_TEST(q.empty()); + } + catch (...) + { + BOOST_TEST(false); + } +} + +void test_concurrent_wait_pull_and_close_on_empty_queue() +{ + boost::sync_queue<int> q; + const unsigned int n = 3; + boost::barrier go(n); + + boost::future<boost::queue_op_status> pull_done[n]; + int results[n]; + + try + { + for (unsigned int i =0; i< n; ++i) + pull_done[i]=boost::async(boost::launch::async, + call_wait_pull<int>(&q,&go), + boost::ref(results[i])); + + q.close(); + + for (unsigned int i = 0; i < n; ++i) { + BOOST_TEST(pull_done[i].get() == boost::queue_op_status::closed); + } + BOOST_TEST(q.empty()); + } + catch (...) + { + BOOST_TEST(false); + } +} +#endif + +void test_concurrent_push_on_empty_queue() +{ + boost::sync_queue<int> q; + const unsigned int n = 3; + boost::barrier go(n); + boost::future<void> push_done[n]; + + try + { + for (unsigned int i =0; i< n; ++i) + push_done[i]=boost::async(boost::launch::async, + call_push<int>(&q,&go)); + + } + catch (...) + { + BOOST_TEST(false); + } + try + { + for (unsigned int i = 0; i < n; ++i) + push_done[i].get(); + + } + catch (...) + { + BOOST_TEST(false); + } + try + { + BOOST_TEST(!q.empty()); + for (unsigned int i =0; i< n; ++i) + BOOST_TEST_EQ(q.pull(), 42); + BOOST_TEST(q.empty()); + + } + catch (...) + { + BOOST_TEST(false); + } +} + +void test_concurrent_pull_on_queue() +{ + boost::sync_queue<int> q; + const unsigned int n = 3; + boost::barrier go(n); + + boost::future<int> pull_done[n]; + + try + { + for (unsigned int i =0; i< n; ++i) + q.push(42); + + for (unsigned int i =0; i< n; ++i) + pull_done[i]=boost::async(boost::launch::async, +#if ! defined BOOST_NO_CXX11_LAMBDAS + [&q,&go]() -> int + { + go.wait(); + return q.pull(); + } +#else + call_pull<int>(&q,&go) +#endif + ); + + for (unsigned int i = 0; i < n; ++i) + BOOST_TEST_EQ(pull_done[i].get(), 42); + BOOST_TEST(q.empty()); + } + catch (...) + { + BOOST_TEST(false); + } +} + +int main() +{ + test_concurrent_push_and_pull_on_empty_queue(); +#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) + test_concurrent_push_and_wait_pull_on_empty_queue(); + test_concurrent_wait_pull_and_close_on_empty_queue(); +#endif + test_concurrent_push_on_empty_queue(); + test_concurrent_pull_on_queue(); + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/sync_queue/single_thread_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_queue/single_thread_pass.cpp new file mode 100644 index 000000000..8f47ec82a --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/sync_queue/single_thread_pass.cpp @@ -0,0 +1,374 @@ +// Copyright (C) 2013,2015 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/sync_queue.hpp> + +// class sync_queue<T> + +// sync_queue(); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/sync_queue.hpp> + +#include <boost/detail/lightweight_test.hpp> + +class non_copyable +{ + BOOST_THREAD_MOVABLE_ONLY(non_copyable) + int val; +public: + non_copyable(int v) : val(v){} + non_copyable(BOOST_RV_REF(non_copyable) x): val(x.val) {} + non_copyable& operator=(BOOST_RV_REF(non_copyable) x) { val=x.val; return *this; } + bool operator==(non_copyable const& x) const {return val==x.val;} + template <typename OSTREAM> + friend OSTREAM& operator <<(OSTREAM& os, non_copyable const&x ) + { + os << x.val; + return os; + } + +}; + + + +int main() +{ + + { + // default queue invariants + boost::sync_queue<int> q; + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + { + // empty queue push rvalue/non_copyable succeeds + boost::sync_queue<non_copyable> q; + q.push(non_copyable(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + { + // empty queue push rvalue/non_copyable succeeds + boost::sync_queue<non_copyable> q; + non_copyable nc(1); + q.push(boost::move(nc)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + + { + // empty queue push rvalue succeeds + boost::sync_queue<int> q; + q.push(1); + q.push(2); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 2u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push lvalue succeeds + boost::sync_queue<int> q; + int i; + q.push(i); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue/copyable succeeds + boost::sync_queue<int> q; + BOOST_TEST(boost::queue_op_status::success == q.try_push(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue/copyable succeeds + boost::sync_queue<int> q; + BOOST_TEST(boost::queue_op_status::success == q.try_push(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + { + // empty queue try_push rvalue/non-copyable succeeds + boost::sync_queue<non_copyable> q; + BOOST_TEST(boost::queue_op_status::success ==q.try_push(non_copyable(1))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + { + // empty queue try_push rvalue/non-copyable succeeds + boost::sync_queue<non_copyable> q; + non_copyable nc(1); + BOOST_TEST(boost::queue_op_status::success == q.try_push(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + + { + // empty queue try_push lvalue succeeds + boost::sync_queue<int> q; + int i=1; + BOOST_TEST(boost::queue_op_status::success == q.try_push(i)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue succeeds + boost::sync_queue<int> q; + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + { + // empty queue nonblocking_push rvalue/non-copyable succeeds + boost::sync_queue<non_copyable> q; + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(non_copyable(1))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + { + // empty queue nonblocking_push rvalue/non-copyable succeeds + boost::sync_queue<non_copyable> q; + non_copyable nc(1); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull succeed + boost::sync_queue<int> q; + q.push(1); + int i; + q.pull(i); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull succeed + boost::sync_queue<non_copyable> q; + non_copyable nc1(1); + q.push(boost::move(nc1)); + non_copyable nc2(2); + q.pull(nc2); + BOOST_TEST_EQ(nc1, nc2); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull succeed + boost::sync_queue<int> q; + q.push(1); + int i = q.pull(); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull succeed + boost::sync_queue<non_copyable> q; + non_copyable nc1(1); + q.push(boost::move(nc1)); + non_copyable nc = q.pull(); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue try_pull succeed + boost::sync_queue<int> q; + q.push(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.try_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue try_pull succeed + boost::sync_queue<non_copyable> q; + non_copyable nc1(1); + q.push(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.try_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue nonblocking_pull succeed + boost::sync_queue<int> q; + q.push(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue nonblocking_pull succeed + boost::sync_queue<non_copyable> q; + non_copyable nc1(1); + q.push(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue wait_pull succeed + boost::sync_queue<non_copyable> q; + non_copyable nc1(1); + q.push(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue wait_pull succeed + boost::sync_queue<int> q; + q.push(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue wait_pull succeed + boost::sync_queue<non_copyable> q; + non_copyable nc1(1); + q.push(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + + { + // closed invariants + boost::sync_queue<int> q; + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed queue push fails + boost::sync_queue<int> q; + q.close(); + try { + q.push(1); + BOOST_TEST(false); + } catch (...) { + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + } + { + // 1-element closed queue pull succeed + boost::sync_queue<int> q; + q.push(1); + q.close(); + int i; + q.pull(i); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // 1-element closed queue wait_pull succeed + boost::sync_queue<int> q; + q.push(1); + q.close(); + int i; + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed empty queue wait_pull fails + boost::sync_queue<int> q; + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + int i; + BOOST_TEST(boost::queue_op_status::closed == q.wait_pull(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/call_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/call_pass.cpp new file mode 100644 index 000000000..f1ed8be4a --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/call_pass.cpp @@ -0,0 +1,144 @@ +// Copyright (C) 2013 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/synchronized_value.hpp> + +// class synchronized_value<T,M> + +// template <typename F> +// inline typename boost::result_of<F(value_type&)>::type +// operator()(BOOST_THREAD_RV_REF(F) fct); +// template <typename F> +// inline typename boost::result_of<F(value_type const&)>::type +// operator()(BOOST_THREAD_RV_REF(F) fct) const; + +#include <boost/config.hpp> +#if ! defined BOOST_NO_CXX11_DECLTYPE +#define BOOST_RESULT_OF_USE_DECLTYPE +#endif + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/synchronized_value.hpp> + +#include <boost/detail/lightweight_test.hpp> + +struct S { + int f() const {return 1;} + int g() {return 1;} +}; + +void c(S const& s) +{ + BOOST_TEST(s.f()==1); +} + +void nc(S & s) +{ + BOOST_TEST(s.f()==1); + BOOST_TEST(s.g()==1); +} + +struct cfctr { + typedef void result_type; + void operator()(S const& s) const { + BOOST_TEST(s.f()==1); + } +}; +struct ncfctr { + typedef void result_type; + void operator()(S& s) const { + BOOST_TEST(s.f()==1); + BOOST_TEST(s.g()==1); + } +}; + +struct cfctr3 { + typedef void result_type; + BOOST_THREAD_MOVABLE_ONLY(cfctr3) + cfctr3() + {} + cfctr3(BOOST_THREAD_RV_REF(cfctr3)) + {} + void operator()(S const& s) const { + BOOST_TEST(s.f()==1); + } +}; +struct ncfctr3 { + typedef void result_type; + BOOST_THREAD_MOVABLE_ONLY(ncfctr3) + ncfctr3() + {} + ncfctr3(BOOST_THREAD_RV_REF(ncfctr3)) + {} + void operator()(S& s) const { + BOOST_TEST(s.f()==1); + BOOST_TEST(s.g()==1); + } +}; + +cfctr3 make_cfctr3() { + return BOOST_THREAD_MAKE_RV_REF(cfctr3()); +} + +ncfctr3 make_ncfctr3() { + return BOOST_THREAD_MAKE_RV_REF(ncfctr3()); +} + +int main() +{ + { + boost::synchronized_value<S> v; + v(&nc); + v(&c); + } + { + const boost::synchronized_value<S> v; + v(&c); + } + { + boost::synchronized_value<S> v; + v(ncfctr()); + } + { + const boost::synchronized_value<S> v; + v(cfctr()); + } + { + boost::synchronized_value<S> v; + ncfctr fct; + v(fct); + } + { + const boost::synchronized_value<S> v; + cfctr fct; + v(fct); + } + { + boost::synchronized_value<S> v; + v(make_ncfctr3()); + } + { + const boost::synchronized_value<S> v; + v(make_cfctr3()); + } +#if ! defined BOOST_NO_CXX11_LAMBDAS + { + boost::synchronized_value<S> v; + v([](S& s) { + BOOST_TEST(s.f()==1); + BOOST_TEST(s.g()==1); + }); + } + { + const boost::synchronized_value<S> v; + v([](S const& s) { + BOOST_TEST(s.f()==1); + }); + } +#endif + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/copy_T_assign_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/copy_T_assign_pass.cpp new file mode 100644 index 000000000..3b43f8f90 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/copy_T_assign_pass.cpp @@ -0,0 +1,30 @@ +// Copyright (C) 2013 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/synchronized_value.hpp> + +// class synchronized_value<T,M> + +// synchronized_value& operator=(T const&); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/synchronized_value.hpp> + +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + + { + int i = 1; + boost::synchronized_value<int> v; + v = i; + BOOST_TEST(v.value() == 1); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/copy_T_ctor_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/copy_T_ctor_pass.cpp new file mode 100644 index 000000000..e395c57aa --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/copy_T_ctor_pass.cpp @@ -0,0 +1,29 @@ +// Copyright (C) 2013 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/synchronized_value.hpp> + +// class synchronized_value<T,M> + +// synchronized_value(T const&); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/synchronized_value.hpp> + +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + + { + int i = 1; + boost::synchronized_value<int> v(i); + BOOST_TEST(v.value() == 1); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/copy_assign_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/copy_assign_pass.cpp new file mode 100644 index 000000000..d4e80b0ce --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/copy_assign_pass.cpp @@ -0,0 +1,31 @@ +// Copyright (C) 2013 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/synchronized_value.hpp> + +// class synchronized_value<T,M> + +// synchronized_value& operator=(synchronized_value const&); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/synchronized_value.hpp> + +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + + { + int i = 1; + boost::synchronized_value<int> v1(i); + boost::synchronized_value<int> v2; + v2 = v1; + BOOST_TEST(v2.value() == 1); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/copy_ctor_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/copy_ctor_pass.cpp new file mode 100644 index 000000000..13fcf6d80 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/copy_ctor_pass.cpp @@ -0,0 +1,30 @@ +// Copyright (C) 2013 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/synchronized_value.hpp> + +// class synchronized_value<T,M> + +// synchronized_value(synchronized_value const&); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/synchronized_value.hpp> + +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + + { + int i = 1; + boost::synchronized_value<int> v1(i); + boost::synchronized_value<int> v2(v1); + BOOST_TEST(v2.value() == 1); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/default_ctor_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/default_ctor_pass.cpp new file mode 100644 index 000000000..7b4095650 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/default_ctor_pass.cpp @@ -0,0 +1,30 @@ +// Copyright (C) 2013 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/synchronized_value.hpp> + +// class synchronized_value<T,M> + +// synchronized_value(); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/synchronized_value.hpp> + +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + + { + boost::synchronized_value<int, boost::mutex > f; + } + { + boost::synchronized_value<int, boost::timed_mutex> f; + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/indirect_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/indirect_pass.cpp new file mode 100644 index 000000000..09b8e89d2 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/indirect_pass.cpp @@ -0,0 +1,38 @@ +// Copyright (C) 2013 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/synchronized_value.hpp> + +// class synchronized_value<T,M> + +// strict_lock_ptr<T,M> operator->(); +// const_strict_lock_ptr<T,M> operator->() const; + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/synchronized_value.hpp> + +#include <boost/detail/lightweight_test.hpp> + +struct S { + int f() const {return 1;} + int g() {return 1;} +}; + +int main() +{ + { + boost::synchronized_value<S> v; + BOOST_TEST(v->f()==1); + BOOST_TEST(v->g()==1); + } + { + const boost::synchronized_value<S> v; + BOOST_TEST(v->f()==1); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/move_T_assign_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/move_T_assign_pass.cpp new file mode 100644 index 000000000..146ed2e51 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/move_T_assign_pass.cpp @@ -0,0 +1,29 @@ +// Copyright (C) 2013 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/synchronized_value.hpp> + +// class synchronized_value<T,M> + +// synchronized_value& operator=(T &&); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/synchronized_value.hpp> + +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + + { + boost::synchronized_value<int> v; + v = 1; + BOOST_TEST(v.value() == 1); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/move_T_ctor_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/move_T_ctor_pass.cpp new file mode 100644 index 000000000..564d57da8 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/move_T_ctor_pass.cpp @@ -0,0 +1,28 @@ +// Copyright (C) 2013 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/synchronized_value.hpp> + +// class synchronized_value<T,M> + +// synchronized_value(T &&); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/synchronized_value.hpp> + +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + + { + boost::synchronized_value<int> v(1); + BOOST_TEST(v.value() == 1); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/move_assign_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/move_assign_pass.cpp new file mode 100644 index 000000000..818216382 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/move_assign_pass.cpp @@ -0,0 +1,30 @@ +// Copyright (C) 2013 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/synchronized_value.hpp> + +// class synchronized_value<T,M> + +// synchronized_value& operator=(synchronized_value &&); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/synchronized_value.hpp> + +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + + { + boost::synchronized_value<int> v1(1); + boost::synchronized_value<int> v2; + v2 = boost::move(v1); + BOOST_TEST(v2.value() == 1); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/move_ctor_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/move_ctor_pass.cpp new file mode 100644 index 000000000..7250e896f --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/move_ctor_pass.cpp @@ -0,0 +1,29 @@ +// Copyright (C) 2013 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/synchronized_value.hpp> + +// class synchronized_value<T,M> + +// synchronized_value(synchronized_value &&); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/synchronized_value.hpp> + +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + + { + boost::synchronized_value<int> v1(1); + boost::synchronized_value<int> v2(boost::move(v1)); + BOOST_TEST(v2.value() == 1); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/swap_T_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/swap_T_pass.cpp new file mode 100644 index 000000000..801b514d6 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/swap_T_pass.cpp @@ -0,0 +1,38 @@ +// Copyright (C) 2013 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/synchronized_value.hpp> + +// class synchronized_value<T,M> + +// void swap(synchronized_value&,synchronized_value&); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/synchronized_value.hpp> + +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + + { + boost::synchronized_value<int> v1(1); + int v2(2); + boost::swap(v1,v2); + BOOST_TEST(v1.value() == 2); + BOOST_TEST(v2 == 1); + } + { + boost::synchronized_value<int> v1(1); + int v2(2); + boost::swap(v2,v1); + BOOST_TEST(v1.value() == 2); + BOOST_TEST(v2 == 1); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/swap_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/swap_pass.cpp new file mode 100644 index 000000000..c52069ff3 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/swap_pass.cpp @@ -0,0 +1,31 @@ +// Copyright (C) 2013 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/synchronized_value.hpp> + +// class synchronized_value<T,M> + +// void swap(synchronized_value&,synchronized_value&); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/synchronized_value.hpp> + +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + + { + boost::synchronized_value<int> v1(1); + boost::synchronized_value<int> v2(2); + swap(v1,v2); + BOOST_TEST(v1.value() == 2); + BOOST_TEST(v2.value() == 1); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/synchronize_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/synchronize_pass.cpp new file mode 100644 index 000000000..af24d79b6 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/synchronized_value/synchronize_pass.cpp @@ -0,0 +1,41 @@ +// Copyright (C) 2013 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/synchronized_value.hpp> + +// class synchronized_value<T,M> + +// strict_lock_ptr<T,M> synchronize(); +// const_strict_lock_ptr<T,M> synchronize() const; + + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/synchronized_value.hpp> + +#include <boost/detail/lightweight_test.hpp> + +struct S { + int f() const {return 1;} + int g() {return 1;} +}; + +int main() +{ + { + boost::synchronized_value<S> v; + boost::strict_lock_ptr<S> ptr = v.synchronize(); + BOOST_TEST(ptr->f()==1); + BOOST_TEST(ptr->g()==1); + } + { + const boost::synchronized_value<S> v; + boost::const_strict_lock_ptr<S> ptr = v.synchronize(); + BOOST_TEST(ptr->f()==1); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/assign_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/assign_fail.cpp new file mode 100644 index 000000000..49188e130 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/assign_fail.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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/timed_mutex.hpp> + +// class timed_mutex; + +// timed_mutex& operator=(const timed_mutex&) = delete; + +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::timed_mutex m0; + boost::timed_mutex m1(m0); +} + +#include "../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/copy_fail.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/copy_fail.cpp new file mode 100644 index 000000000..ed0a4c955 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/copy_fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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/timed_mutex.hpp> + +// class timed_mutex; + +// timed_mutex(const timed_mutex&) = delete; + +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::timed_mutex m0; + boost::timed_mutex m1(m0); +} + +#include "../../../remove_error_code_unused_warning.hpp" diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/default_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/default_pass.cpp new file mode 100644 index 000000000..6b7c6f2b3 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/default_pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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/timed_mutex.hpp> + +// class timed_mutex; + +// timed_mutex(); + +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::timed_mutex m0; + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/lock_pass.cpp new file mode 100644 index 000000000..8d2733e1f --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/lock_pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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/timed_mutex.hpp> + +// class timed_mutex; + +// void lock(); + +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + +boost::timed_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + m.lock(); + t1 = Clock::now(); + m.unlock(); +#else + //time_point t0 = Clock::now(); + m.lock(); + //time_point t1 = Clock::now(); + m.unlock(); + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/native_handle_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/native_handle_pass.cpp new file mode 100644 index 000000000..b203e5d91 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/native_handle_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/timed_mutex.hpp> + +// class timed_mutex; + +// typedef pthread_timed_mutex_t* native_handle_type; +// native_handle_type native_handle(); + +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.hpp> + + +int main() +{ +#if defined BOOST_THREAD_DEFINES_TIMED_MUTEX_NATIVE_HANDLE + boost::timed_mutex m; + boost::timed_mutex::native_handle_type h = m.native_handle(); + BOOST_TEST(h); +#else +#error "Test not applicable: BOOST_THREAD_DEFINES_TIMED_MUTEX_NATIVE_HANDLE not defined for this platform as not supported" +#endif + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/try_lock_for_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/try_lock_for_pass.cpp new file mode 100644 index 000000000..94d790e0e --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/try_lock_for_pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// 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/timed_mutex.hpp> + +// class timed_mutex; + +// template <class Rep, class Period> +// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time); + +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + +#if defined BOOST_THREAD_USES_CHRONO + +boost::timed_mutex m; + +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f1() +{ + t0 = Clock::now(); + BOOST_TEST(m.try_lock_for(ms(750)) == true); + t1 = Clock::now(); + m.unlock(); +} + +void f2() +{ + t0 = Clock::now(); + BOOST_TEST(m.try_lock_for(ms(250)) == false); + t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); + m.unlock(); + t.join(); + + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(750)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + +#else +#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported" +#endif + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/try_lock_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/try_lock_pass.cpp new file mode 100644 index 000000000..96e99e7f7 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/try_lock_pass.cpp @@ -0,0 +1,92 @@ +//===----------------------------------------------------------------------===// +// +// 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/timed_mutex.hpp> + +// class timed_mutex; + +// bool try_lock(); + +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + + +boost::timed_mutex m; + +#if defined BOOST_THREAD_USES_CHRONO +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; +#else +#endif + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f() +{ +#if defined BOOST_THREAD_USES_CHRONO + t0 = Clock::now(); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + while (!m.try_lock()) + ; + t1 = Clock::now(); + m.unlock(); +#else + //time_point t0 = Clock::now(); + //BOOST_TEST(!m.try_lock()); + //BOOST_TEST(!m.try_lock()); + //BOOST_TEST(!m.try_lock()); + while (!m.try_lock()) + ; + //time_point t1 = Clock::now(); + m.unlock(); + //ns d = t1 - t0 - ms(250); + //BOOST_TEST(d < max_diff); +#endif +} + +int main() +{ + m.lock(); + boost::thread t(f); +#if defined BOOST_THREAD_USES_CHRONO + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); +#else +#endif + m.unlock(); + t.join(); + +#if defined BOOST_THREAD_USES_CHRONO + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); +#endif + + return boost::report_errors(); +} + + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/try_lock_until_pass.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/try_lock_until_pass.cpp new file mode 100644 index 000000000..958a42d03 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/timed_mutex/try_lock_until_pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// 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/timed_mutex.hpp> + +// class timed_mutex; + +// template <class Clock, class Duration> +// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time); + +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> +#include "../../../timming.hpp" + +#if defined BOOST_THREAD_USES_CHRONO + +boost::timed_mutex m; + +typedef boost::chrono::high_resolution_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; +time_point t0; +time_point t1; + +const ms max_diff(BOOST_THREAD_TEST_TIME_MS); + +void f1() +{ + t0 = Clock::now(); + BOOST_TEST(m.try_lock_until(Clock::now() + ms(750)) == true); + t1 = Clock::now(); + m.unlock(); +} + +void f2() +{ + t0 = Clock::now(); + BOOST_TEST(m.try_lock_until(Clock::now() + ms(250)) == false); + t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_THREAD_TEST_IT(d, ns(max_diff)); +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + time_point t2 = Clock::now(); + boost::this_thread::sleep_for(ms(250)); + time_point t3 = Clock::now(); + m.unlock(); + t.join(); + + ns sleep_time = t3 - t2; + ns d_ns = t1 - t0 - sleep_time; + ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); + // BOOST_TEST_GE(d_ms.count(), 0); + BOOST_THREAD_TEST_IT(d_ms, max_diff); + BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(750)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + +#else +#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported" +#endif + diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/with_lock_guard/with_lock_guard_bind.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/with_lock_guard/with_lock_guard_bind.cpp new file mode 100644 index 000000000..9ec0dfdfb --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/with_lock_guard/with_lock_guard_bind.cpp @@ -0,0 +1,145 @@ +// (C) Copyright 2013 Ruslan Baratov +// Copyright (C) 2014 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) + +// See www.boost.org/libs/thread for documentation. + +#define BOOST_THREAD_VERSION 4 + +#include <boost/detail/lightweight_test.hpp> // BOOST_TEST + +#include <boost/thread/mutex.hpp> +#include <boost/thread/with_lock_guard.hpp> +#include <boost/bind/bind.hpp> + +class Foo { + public: + Foo(int value): value_(value) { + } + + int func(int a, int b) const { + BOOST_TEST(a == 1); + BOOST_TEST(b == 31); + return a + b + value_; + } + + int func_ref(int& a) const { + a = 133; + return 36; + } + + void func_ref(int& a, int& b, int* c) const { + BOOST_TEST(value_ == 3); + a = 567; + b = 897; + *c = 345; + } + + private: + int value_; +}; + +void test_bind() { + boost::mutex m; + + Foo foo(2); + + int res_bind = boost::with_lock_guard( + m, + boost::bind(&Foo::func, foo, 1, 31) + ); + BOOST_TEST(res_bind == 34); + + int a = 0; + int res_bind_ref = boost::with_lock_guard( + m, + boost::bind(&Foo::func_ref, foo, boost::ref(a)) + ); + BOOST_TEST(res_bind_ref == 36); + BOOST_TEST(a == 133); + + a = 0; + int b = 0; + int c = 0; + Foo boo(3); + boost::with_lock_guard( + m, boost::bind(&Foo::func_ref, boo, boost::ref(a), boost::ref(b), &c) + ); + BOOST_TEST(a == 567); + BOOST_TEST(b == 897); + BOOST_TEST(c == 345); +} + +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +void test_bind_non_const() { + std::cout << "c++11 variadic templates disabled" << std::endl; +} +#else + +// calling non-const bind methods supported only with c++11 variadic templates +class Boo { + public: + Boo(int value): value_(value) { + } + + int func(int a, int b) { + BOOST_TEST(a == 7); + BOOST_TEST(b == 3); + return a - b + value_; + } + + int func_ref(int& a) { + a = 598; + return 23; + } + + void func_ref(int& a, int& b, int* c) { + BOOST_TEST(value_ == 67); + a = 111; + b = 222; + *c = 333; + } + + private: + int value_; +}; + +void test_bind_non_const() { + boost::mutex m; + + Boo boo(20); + + int res_bind = boost::with_lock_guard( + m, + boost::bind(&Boo::func, boo, 7, 3) + ); + BOOST_TEST(res_bind == 24); + + int a = 0; + int res_bind_ref = boost::with_lock_guard( + m, + boost::bind(&Boo::func_ref, boo, boost::ref(a)) + ); + BOOST_TEST(res_bind_ref == 23); + BOOST_TEST(a == 598); + + a = 0; + int b = 0; + int c = 0; + Boo foo(67); + boost::with_lock_guard( + m, boost::bind(&Boo::func_ref, foo, boost::ref(a), boost::ref(b), &c) + ); + BOOST_TEST(a == 111); + BOOST_TEST(b == 222); + BOOST_TEST(c == 333); +} +#endif + +int main() { + test_bind(); + test_bind_non_const(); + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/with_lock_guard/with_lock_guard_lambda.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/with_lock_guard/with_lock_guard_lambda.cpp new file mode 100644 index 000000000..8eda53dea --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/with_lock_guard/with_lock_guard_lambda.cpp @@ -0,0 +1,59 @@ +// (C) Copyright 2013 Ruslan Baratov +// Copyright (C) 2014 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) + +// See www.boost.org/libs/thread for documentation. + +#include <boost/config.hpp> + +#if !defined(BOOST_NO_CXX11_DECLTYPE) +# define BOOST_RESULT_OF_USE_DECLTYPE +#endif + +#define BOOST_THREAD_VERSION 4 + +#include <boost/detail/lightweight_test.hpp> // BOOST_TEST + +#include <iostream> // std::cout +#include <boost/thread/mutex.hpp> +#include <boost/thread/with_lock_guard.hpp> + +#if defined(BOOST_NO_CXX11_LAMBDAS) || (defined BOOST_MSVC && _MSC_VER < 1700) +void test_lambda() { + std::cout << "C++11 lambda disabled" << std::endl; +} +#else +void test_lambda() { + boost::mutex m; + int res_1 = boost::with_lock_guard( + m, + [](int a) { + BOOST_TEST(a == 13); + return a + 3; + }, + 13 + ); + BOOST_TEST(res_1 == 16); + + int v = 0; + int res_2 = boost::with_lock_guard( + m, + [&v](int a) { + BOOST_TEST(a == 55); + v = 15; + return 45; + }, + 55 + ); + BOOST_TEST(res_2 == 45); + BOOST_TEST(v == 15); +} +#endif + +int main() { + std::cout << std::boolalpha; + test_lambda(); + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/with_lock_guard/with_lock_guard_move.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/with_lock_guard/with_lock_guard_move.cpp new file mode 100644 index 000000000..2c685790d --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/with_lock_guard/with_lock_guard_move.cpp @@ -0,0 +1,110 @@ +// (C) Copyright 2013 Ruslan Baratov +// Copyright (C) 2014 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) + +// See www.boost.org/libs/thread for documentation. + +#define BOOST_THREAD_VERSION 4 + +#include <boost/detail/lightweight_test.hpp> // BOOST_TEST + +#include <boost/thread/mutex.hpp> +#include <boost/thread/with_lock_guard.hpp> + +class Foo { + public: + explicit Foo(int a) : a_(a) { + } + + Foo(BOOST_RV_REF(Foo) foo) : a_(foo.a_) { + BOOST_ASSERT(&foo != this); + foo.a_ = 0; + } + + Foo& operator=(BOOST_RV_REF(Foo) foo) { + BOOST_ASSERT(&foo != this); + a_ = foo.a_; + foo.a_ = 0; + return *this; + } + + int get() const { + return a_; + } + + private: + BOOST_MOVABLE_BUT_NOT_COPYABLE(Foo) + + int a_; +}; + +template <class T1, class T2> +bool func_with_2_arg(BOOST_FWD_REF(T1) arg_1, BOOST_FWD_REF(T2) arg_2) { + BOOST_TEST(arg_1.get() == 3); + BOOST_TEST(arg_2.get() == 767); + return false; +} + +void test_movable() { + boost::mutex m; + + Foo foo_1(3); + Foo foo_2(767); + + bool res = boost::with_lock_guard( + m, &func_with_2_arg<Foo, Foo>, boost::move(foo_1), boost::move(foo_2) + ); + BOOST_TEST(!res); +} + +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +void test_real_movable() { + std::cout << "c++11 move emulated" << std::endl; +} +#else +// test real one +class Boo { + public: + Boo(int a) : a_(a) { + } + + Boo(Boo&& boo) : a_(boo.a_) { + BOOST_ASSERT(&boo != this); + boo.a_ = 0; + } + + int get() const { + return a_; + } + + BOOST_DELETED_FUNCTION(Boo(Boo&)) + BOOST_DELETED_FUNCTION(Boo& operator=(Boo&)) + BOOST_DELETED_FUNCTION(Boo& operator=(Boo&&)) + private: + int a_; +}; + +void func_with_3_arg(Boo&& boo_1, Boo&& boo_2, Boo&& boo_3) { + BOOST_TEST(boo_1.get() == 11); + BOOST_TEST(boo_2.get() == 12); + BOOST_TEST(boo_3.get() == 13); +} + +void test_real_movable() { + boost::mutex m; + + Boo boo_3(13); + + boost::with_lock_guard( + m, func_with_3_arg, Boo(11), Boo(12), boost::move(boo_3) + ); +} +#endif + +int main() { + test_movable(); + test_real_movable(); + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/sync/mutual_exclusion/with_lock_guard/with_lock_guard_simple.cpp b/src/boost/libs/thread/test/sync/mutual_exclusion/with_lock_guard/with_lock_guard_simple.cpp new file mode 100644 index 000000000..dc9c44455 --- /dev/null +++ b/src/boost/libs/thread/test/sync/mutual_exclusion/with_lock_guard/with_lock_guard_simple.cpp @@ -0,0 +1,139 @@ +// (C) Copyright 2013 Ruslan Baratov +// (C) Copyright 2013 Ruslan Baratov +// +// 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) + +// See www.boost.org/libs/thread for documentation. + +#define BOOST_THREAD_VERSION 4 + +#include <boost/detail/lightweight_test.hpp> // BOOST_TEST + +#include <boost/thread/mutex.hpp> +#include <boost/thread/with_lock_guard.hpp> +#include <boost/ref.hpp> + +void func_with_0_arg() { +} + +void func_with_1_arg(int arg_1) { + BOOST_TEST(arg_1 == 3); +} + +bool func_with_2_arg(int arg_1, bool arg_2) { + BOOST_TEST(arg_1 == 3); + BOOST_TEST(arg_2 == true); + return !arg_2; +} + +int func_with_3_arg(int arg_1, bool arg_2, const char* arg_3) { + BOOST_TEST(arg_1 == 13); + BOOST_TEST(arg_2 == false); + BOOST_TEST(std::string(arg_3) == "message for func with 3 arg"); + return 12; +} + +const char* func_with_4_arg(int arg_1, bool arg_2, int* arg_3, int& arg_4) { + BOOST_TEST(arg_1 == 23); + BOOST_TEST(arg_2 == false); + *arg_3 = 128; + arg_4 = 456; + return "hello"; +} + +void test_simple() { + boost::mutex m; + + // #0 + boost::with_lock_guard(m, func_with_0_arg); + + // #1 + boost::with_lock_guard(m, func_with_1_arg, 3); + + // #2 + bool res2 = boost::with_lock_guard(m, func_with_2_arg, 3, true); + BOOST_TEST(res2 == false); + + // #3 + int arg1 = 13; + const char* mes = "message for func with 3 arg"; + int res3 = boost::with_lock_guard(m, func_with_3_arg, arg1, false, mes); + BOOST_TEST(res3 == 12); + + // #4 + int arg3 = 0; + int arg4 = 0; + const char* res4 = boost::with_lock_guard( + m, + func_with_4_arg, + 23, + false, + &arg3, + boost::ref(arg4) + ); + BOOST_TEST(arg3 == 128); + BOOST_TEST(arg4 == 456); + BOOST_TEST(std::string(res4) == "hello"); +} + +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +void test_variadic_templates() { + std::cout << "C++11 variadic templates disabled" << std::endl; +} +#else +int func_with_5_args(int a1, char a2, int& a3, bool* a4, bool a5) { + BOOST_TEST(a1 == 12); + BOOST_TEST(a2 == 'x'); + BOOST_TEST(a5 == false); + a3 = 135; + *a4 = false; + return 45; +} + +int func_with_6_args(int a1, char a2, int& a3, bool* a4, int&& a5, bool a6) { + BOOST_TEST(a1 == 12); + BOOST_TEST(a2 == 'N'); + BOOST_TEST(a5 == 2 || a5 == 13); + BOOST_TEST(a6 == false); + a3 = 200; + *a4 = true; + return 888; +} + +void test_variadic_templates() { + boost::mutex m; + + int a3 = 0; + bool a4 = true; + int res5 = boost::with_lock_guard( + m, func_with_5_args, 12, 'x', a3, &a4, false + ); + BOOST_TEST(a3 == 135); + BOOST_TEST(a4 == false); + BOOST_TEST(res5 == 45); + + int res6 = boost::with_lock_guard( + m, func_with_6_args, 12, 'N', a3, &a4, 2, false + ); + BOOST_TEST(a3 == 200); + BOOST_TEST(a4 == true); + BOOST_TEST(res6 == 888); + + a3 = 0; + a4 = false; + int a5 = 13; + int res6_move = boost::with_lock_guard( + m, func_with_6_args, 12, 'N', a3, &a4, boost::move(a5), false + ); + BOOST_TEST(a3 == 200); + BOOST_TEST(a4 == true); + BOOST_TEST_EQ(res6_move, 888); +} +#endif + +int main() { + test_simple(); + test_variadic_templates(); + return boost::report_errors(); +} |