diff options
Diffstat (limited to 'libs/thread/test/sync/mutual_exclusion/locks/reverse_lock')
4 files changed, 166 insertions, 0 deletions
diff --git a/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp b/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp new file mode 100755 index 0000000000..77808fc028 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp @@ -0,0 +1,41 @@ +// 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/locks.hpp> +#include <boost/thread/reverse_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.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; + } + +} + +void remove_unused_warning() +{ + //../../../boost/system/error_code.hpp:214:36: warning: Ôboost::system::posix_categoryÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:215:36: warning: Ôboost::system::errno_ecatÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:216:36: warning: Ôboost::system::native_ecatÕ defined but not used [-Wunused-variable] + + (void)boost::system::posix_category; + (void)boost::system::errno_ecat; + (void)boost::system::native_ecat; +} diff --git a/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_ctor_fail.cpp b/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_ctor_fail.cpp new file mode 100755 index 0000000000..a5e2348457 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_ctor_fail.cpp @@ -0,0 +1,40 @@ +// 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/locks.hpp> +#include <boost/thread/reverse_lock.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/detail/lightweight_test.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); + } +} + +void remove_unused_warning() +{ + //../../../boost/system/error_code.hpp:214:36: warning: Ôboost::system::posix_categoryÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:215:36: warning: Ôboost::system::errno_ecatÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:216:36: warning: Ôboost::system::native_ecatÕ defined but not used [-Wunused-variable] + + (void)boost::system::posix_category; + (void)boost::system::errno_ecat; + (void)boost::system::native_ecat; +} diff --git a/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp new file mode 100755 index 0000000000..30dafa1fa4 --- /dev/null +++ b/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/types_pass.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/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/locks.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::reverse_lock<boost::unique_lock<boost::mutex> >::mutex_type, + boost::mutex>::value), ""); + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/unique_lock_ctor_pass.cpp b/libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/unique_lock_ctor_pass.cpp new file mode 100755 index 0000000000..99b4f00c33 --- /dev/null +++ b/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/locks.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(); +} |