Index: reverse_lock.hpp =================================================================== --- reverse_lock.hpp (revision 0) +++ reverse_lock.hpp (revision 0) @@ -0,0 +1,65 @@ +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// (C) Copyright 2012 Vicente J. Botet Escriba + +#ifndef BOOST_THREAD_REVERSE_LOCK_HPP +#define BOOST_THREAD_REVERSE_LOCK_HPP +#include +#include + +namespace boost +{ + + template + class reverse_lock + { + +#ifndef BOOST_NO_DELETED_FUNCTIONS + public: + reverse_lock(reverse_lock const&) = delete; + reverse_lock& operator=(reverse_lock const&) = delete; +#else // BOOST_NO_DELETED_FUNCTIONS + private: + reverse_lock(reverse_lock&); + reverse_lock& operator=(reverse_lock&); +#endif // BOOST_NO_DELETED_FUNCTIONS + public: + typedef typename Lock::mutex_type mutex_type; + + explicit reverse_lock(Lock& m_) + : m(m_), mtx(0) + { + if (m.owns_lock()) + { + m.unlock(); + } + mtx=m.release(); + } + ~reverse_lock() + { + if (mtx) { + mtx->lock(); + m = Lock(*mtx, adopt_lock); + } + } + + private: + Lock& m; + mutex_type* mtx; + }; + + +#ifdef BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES + template + struct is_mutex_type > + { + BOOST_STATIC_CONSTANT(bool, value = true); + }; + +#endif + + +} + +#endif // header Property changes on: reverse_lock.hpp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Id Added: svn:eol-style + native Index: ../../libs/thread/doc/overview.qbk =================================================================== --- ../../libs/thread/doc/overview.qbk (revision 77660) +++ ../../libs/thread/doc/overview.qbk (working copy) @@ -20,10 +20,9 @@ [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2139.html N2139], and [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2094.html N2094] -Vicente J. Botet Escriba started in version 2 the adaptation to comply with the accepted Thread C++11 library (Make use of Boost.Chrono and Boost.Move) and the [@http://home.roadrunner.com/~hinnant/bloomington/shared_mutex.html Shared Locking] Howard Hinnant proposal except for the upward conversions. +Vicente J. Botet Escriba started in version 2 the adaptation to comply with the accepted Thread C++11 library (Make use of Boost.Chrono and Boost.Move) and the [@http://home.roadrunner.com/~hinnant/bloomington/shared_mutex.html Shared Locking] Howard Hinnant proposal except for the upward conversions. Some minor features have been added also +as thread attributes, reverse_lock, shared_lock_guard. -[/ as some new features as thread attributes, unlock_guard, shared_guard, ] - In order to use the classes and functions described here, you can either include the specific headers specified by the descriptions of each class or function, or include the master thread library header: Index: ../../libs/thread/doc/changes.qbk =================================================================== --- ../../libs/thread/doc/changes.qbk (revision 77661) +++ ../../libs/thread/doc/changes.qbk (working copy) @@ -12,10 +12,7 @@ New Features: -[/ * [@http://svn.boost.org/trac/boost/ticket/1850 #1850] Request for unlock_guard to compliment lock_guard. -] - * [@http://svn.boost.org/trac/boost/ticket/2637 #2637] Request for shared_mutex duration timed_lock and timed_lock_shared. * [@http://svn.boost.org/trac/boost/ticket/2741 #2741] Proposal to manage portable and non portable thread attributes. * [@http://svn.boost.org/trac/boost/ticket/3567 #3567] Request for shared_lock_guard. @@ -188,11 +185,6 @@ * [@http://svn.boost.org/trac/boost/ticket/6270 #6270] Add thread constructor from movable callable and movable arguments following C++11. -# Add some complementary locks - - * [@http://svn.boost.org/trac/boost/ticket/1850 #1850] Request for unlock_guard (and/or unique_unlock) to compliment lock_guard/unique_lock. - * [@http://svn.boost.org/trac/boost/ticket/3567 #3567] Request for shared_lock_guard. - # Add the shared locking upward conversions. * [@http://svn.boost.org/trac/boost/ticket/6217 #6217] Enhance Boost.Thread shared mutex interface following Howard Hinnant proposal. Index: ../../libs/thread/doc/mutex_concepts.qbk =================================================================== --- ../../libs/thread/doc/mutex_concepts.qbk (revision 77661) +++ ../../libs/thread/doc/mutex_concepts.qbk (working copy) @@ -1593,7 +1593,6 @@ [endsect] -[/ [section:reverse_lock Class template `reverse_lock`] #include @@ -1642,7 +1641,6 @@ [endsect] -] [endsect] Index: ../../libs/thread/test/Jamfile.v2 =================================================================== --- ../../libs/thread/test/Jamfile.v2 (revision 77661) +++ ../../libs/thread/test/Jamfile.v2 (working copy) @@ -387,4 +387,13 @@ [ thread-run2 ./sync/mutual_exclusion/locks/shared_lock_guard/types_pass.cpp : shared_lock_guard__types_p ] ; + #explicit reverse_lock ; + test-suite reverse_lock + : + [ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp : : reverse_lock__copy_assign_f ] + [ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/reverse_lock/copy_ctor_fail.cpp : : reverse_lock__copy_ctor_f ] + [ thread-run2 ./sync/mutual_exclusion/locks/reverse_lock/unique_lock_ctor_pass.cpp : reverse_lock__unique_lock_ctor_p ] + [ thread-run2 ./sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp : reverse_lock__types_p ] + ; + } Index: ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp =================================================================== --- ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp (revision 0) +++ ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp (revision 0) @@ -0,0 +1,30 @@ +// 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) + +// + +// template class unlock_guard; + +// unlock_guard& operator=(unlock_guard const&) = delete; + +#include +#include +#include + + +int main() +{ + boost::mutex m0; + boost::mutex m1; + boost::unique_lock lk0(m0); + boost::unique_lock lk1(m1); + { + boost::unlock_guard > lg0(lk0); + boost::unlock_guard > lg1(lk1); + lk1 = lk0; + } + +} + Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Added: svn:eol-style + native Index: ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp =================================================================== --- ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp (revision 0) +++ ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp (revision 0) @@ -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) + +// + +// + +// template +// class unlock_guard +// { +// public: +// typedef Mutex mutex_type; +// ... +// }; + + +#include +#include +#include +#include +#include +#include + +int main() +{ + BOOST_STATIC_ASSERT_MSG((boost::is_same >::mutex_type, + boost::mutex>::value), ""); + + return boost::report_errors(); +} + Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Added: svn:eol-style + native Index: ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/unique_lock_ctor_pass.cpp =================================================================== --- ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/unique_lock_ctor_pass.cpp (revision 0) +++ ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/unique_lock_ctor_pass.cpp (revision 0) @@ -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) + +// + +// template class unlock_guard; + +// unlock_guard(unlock_guard const&) = delete; + +#include +#include +#include +#include +#include + + +int main() +{ + { + boost::mutex m; + boost::unique_lock lk(m); + BOOST_TEST(lk.owns_lock()); + BOOST_TEST(lk.mutex()==&m); + + { + boost::reverse_lock > 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 lk(m, boost::defer_lock); + BOOST_TEST(! lk.owns_lock()); + BOOST_TEST(lk.mutex()==&m); + { + boost::reverse_lock > 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(); +} Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/unique_lock_ctor_pass.cpp ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Added: svn:eol-style + native Index: ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_ctor_fail.cpp =================================================================== --- ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_ctor_fail.cpp (revision 0) +++ ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_ctor_fail.cpp (revision 0) @@ -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) + +// + +// template class unlock_guard; + +// unlock_guard(unlock_guard const&) = delete; + + +#include +#include +#include + +boost::mutex m0; +boost::mutex m1; + +int main() +{ + boost::mutex m0; + boost::mutex m1; + boost::unique_lock lk0(m0); + boost::unique_lock lk1(m1); + { + boost::unlock_guard > lg0(lk0); + boost::unlock_guard > lg1(lg0); + } +} + Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_ctor_fail.cpp ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Added: svn:eol-style + native