Ticket #1850: 1850.patch
File 1850.patch, 12.2 KB (added by , 11 years ago) |
---|
-
reverse_lock.hpp
1 // Distributed under the Boost Software License, Version 1.0. (See 2 // accompanying file LICENSE_1_0.txt or copy at 3 // http://www.boost.org/LICENSE_1_0.txt) 4 // (C) Copyright 2012 Vicente J. Botet Escriba 5 6 #ifndef BOOST_THREAD_REVERSE_LOCK_HPP 7 #define BOOST_THREAD_REVERSE_LOCK_HPP 8 #include <boost/thread/detail/config.hpp> 9 #include <boost/thread/locks.hpp> 10 11 namespace boost 12 { 13 14 template<typename Lock> 15 class reverse_lock 16 { 17 18 #ifndef BOOST_NO_DELETED_FUNCTIONS 19 public: 20 reverse_lock(reverse_lock const&) = delete; 21 reverse_lock& operator=(reverse_lock const&) = delete; 22 #else // BOOST_NO_DELETED_FUNCTIONS 23 private: 24 reverse_lock(reverse_lock&); 25 reverse_lock& operator=(reverse_lock&); 26 #endif // BOOST_NO_DELETED_FUNCTIONS 27 public: 28 typedef typename Lock::mutex_type mutex_type; 29 30 explicit reverse_lock(Lock& m_) 31 : m(m_), mtx(0) 32 { 33 if (m.owns_lock()) 34 { 35 m.unlock(); 36 } 37 mtx=m.release(); 38 } 39 ~reverse_lock() 40 { 41 if (mtx) { 42 mtx->lock(); 43 m = Lock(*mtx, adopt_lock); 44 } 45 } 46 47 private: 48 Lock& m; 49 mutex_type* mtx; 50 }; 51 52 53 #ifdef BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES 54 template<typename T> 55 struct is_mutex_type<reverse_lock<T> > 56 { 57 BOOST_STATIC_CONSTANT(bool, value = true); 58 }; 59 60 #endif 61 62 63 } 64 65 #endif // header -
../../libs/thread/doc/overview.qbk
Property changes on: reverse_lock.hpp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Id Added: svn:eol-style + native
20 20 [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2139.html N2139], and 21 21 [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2094.html N2094] 22 22 23 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. 23 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 24 as thread attributes, reverse_lock, shared_lock_guard. 24 25 25 [/ as some new features as thread attributes, unlock_guard, shared_guard, ]26 27 26 In order to use the classes and functions described here, you can 28 27 either include the specific headers specified by the descriptions of 29 28 each class or function, or include the master thread library header: -
../../libs/thread/doc/changes.qbk
12 12 13 13 New Features: 14 14 15 [/16 15 * [@http://svn.boost.org/trac/boost/ticket/1850 #1850] Request for unlock_guard to compliment lock_guard. 17 ]18 19 16 * [@http://svn.boost.org/trac/boost/ticket/2637 #2637] Request for shared_mutex duration timed_lock and timed_lock_shared. 20 17 * [@http://svn.boost.org/trac/boost/ticket/2741 #2741] Proposal to manage portable and non portable thread attributes. 21 18 * [@http://svn.boost.org/trac/boost/ticket/3567 #3567] Request for shared_lock_guard. … … 188 185 * [@http://svn.boost.org/trac/boost/ticket/6270 #6270] Add thread constructor from movable callable and movable arguments following C++11. 189 186 190 187 191 # Add some complementary locks192 193 * [@http://svn.boost.org/trac/boost/ticket/1850 #1850] Request for unlock_guard (and/or unique_unlock) to compliment lock_guard/unique_lock.194 * [@http://svn.boost.org/trac/boost/ticket/3567 #3567] Request for shared_lock_guard.195 196 188 # Add the shared locking upward conversions. 197 189 198 190 * [@http://svn.boost.org/trac/boost/ticket/6217 #6217] Enhance Boost.Thread shared mutex interface following Howard Hinnant proposal. -
../../libs/thread/doc/mutex_concepts.qbk
1593 1593 1594 1594 [endsect] 1595 1595 1596 [/1597 1596 [section:reverse_lock Class template `reverse_lock`] 1598 1597 1599 1598 #include <boost/thread/reverse_lock.hpp> … … 1642 1641 1643 1642 1644 1643 [endsect] 1645 ]1646 1644 1647 1645 [endsect] 1648 1646 -
../../libs/thread/test/Jamfile.v2
387 387 [ thread-run2 ./sync/mutual_exclusion/locks/shared_lock_guard/types_pass.cpp : shared_lock_guard__types_p ] 388 388 ; 389 389 390 #explicit reverse_lock ; 391 test-suite reverse_lock 392 : 393 [ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp : : reverse_lock__copy_assign_f ] 394 [ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/reverse_lock/copy_ctor_fail.cpp : : reverse_lock__copy_ctor_f ] 395 [ thread-run2 ./sync/mutual_exclusion/locks/reverse_lock/unique_lock_ctor_pass.cpp : reverse_lock__unique_lock_ctor_p ] 396 [ thread-run2 ./sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp : reverse_lock__types_p ] 397 ; 398 390 399 } -
../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp
1 // Copyright (C) 2012 Vicente J. Botet Escriba 2 // 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 // <boost/thread/locks.hpp> 7 8 // template <class Mutex> class unlock_guard; 9 10 // unlock_guard& operator=(unlock_guard const&) = delete; 11 12 #include <boost/thread/locks.hpp> 13 #include <boost/thread/mutex.hpp> 14 #include <boost/detail/lightweight_test.hpp> 15 16 17 int main() 18 { 19 boost::mutex m0; 20 boost::mutex m1; 21 boost::unique_lock<boost::mutex> lk0(m0); 22 boost::unique_lock<boost::mutex> lk1(m1); 23 { 24 boost::unlock_guard<boost::unique_lock<boost::mutex> > lg0(lk0); 25 boost::unlock_guard<boost::unique_lock<boost::mutex> > lg1(lk1); 26 lk1 = lk0; 27 } 28 29 } 30 -
../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp
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
1 // Copyright (C) 2012 Vicente J. Botet Escriba 2 // 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 // <boost/thread/mutex.hpp> 7 8 // <mutex> 9 10 // template <class Mutex> 11 // class unlock_guard 12 // { 13 // public: 14 // typedef Mutex mutex_type; 15 // ... 16 // }; 17 18 19 #include <boost/thread/mutex.hpp> 20 #include <boost/thread/reverse_lock.hpp> 21 #include <boost/thread/locks.hpp> 22 #include <boost/thread/mutex.hpp> 23 #include <boost/static_assert.hpp> 24 #include <boost/detail/lightweight_test.hpp> 25 26 int main() 27 { 28 BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::reverse_lock<boost::unique_lock<boost::mutex> >::mutex_type, 29 boost::mutex>::value), ""); 30 31 return boost::report_errors(); 32 } 33 -
../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/unique_lock_ctor_pass.cpp
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
1 // Copyright (C) 2012 Vicente J. Botet Escriba 2 // 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 // <boost/thread/locks.hpp> 7 8 // template <class Mutex> class unlock_guard; 9 10 // unlock_guard(unlock_guard const&) = delete; 11 12 #include <boost/thread/reverse_lock.hpp> 13 #include <boost/thread/locks.hpp> 14 #include <boost/thread/mutex.hpp> 15 #include <boost/thread/thread.hpp> 16 #include <boost/detail/lightweight_test.hpp> 17 18 19 int main() 20 { 21 { 22 boost::mutex m; 23 boost::unique_lock<boost::mutex> lk(m); 24 BOOST_TEST(lk.owns_lock()); 25 BOOST_TEST(lk.mutex()==&m); 26 27 { 28 boost::reverse_lock<boost::unique_lock<boost::mutex> > lg(lk); 29 BOOST_TEST(!lk.owns_lock()); 30 BOOST_TEST(lk.mutex()==0); 31 } 32 BOOST_TEST(lk.owns_lock()); 33 BOOST_TEST(lk.mutex()==&m); 34 } 35 36 { 37 boost::mutex m; 38 boost::unique_lock<boost::mutex> lk(m, boost::defer_lock); 39 BOOST_TEST(! lk.owns_lock()); 40 BOOST_TEST(lk.mutex()==&m); 41 { 42 boost::reverse_lock<boost::unique_lock<boost::mutex> > lg(lk); 43 BOOST_TEST(!lk.owns_lock()); 44 BOOST_TEST(lk.mutex()==0); 45 } 46 BOOST_TEST(lk.owns_lock()); 47 BOOST_TEST(lk.mutex()==&m); 48 } 49 50 51 return boost::report_errors(); 52 } -
../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_ctor_fail.cpp
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
1 // Copyright (C) 2012 Vicente J. Botet Escriba 2 // 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 // <boost/thread/locks.hpp> 7 8 // template <class Mutex> class unlock_guard; 9 10 // unlock_guard(unlock_guard const&) = delete; 11 12 13 #include <boost/thread/locks.hpp> 14 #include <boost/thread/mutex.hpp> 15 #include <boost/detail/lightweight_test.hpp> 16 17 boost::mutex m0; 18 boost::mutex m1; 19 20 int main() 21 { 22 boost::mutex m0; 23 boost::mutex m1; 24 boost::unique_lock<boost::mutex> lk0(m0); 25 boost::unique_lock<boost::mutex> lk1(m1); 26 { 27 boost::unlock_guard<boost::unique_lock<boost::mutex> > lg0(lk0); 28 boost::unlock_guard<boost::unique_lock<boost::mutex> > lg1(lg0); 29 } 30 } 31