Index: shared_lock_guard.hpp =================================================================== --- shared_lock_guard.hpp (revision 0) +++ shared_lock_guard.hpp (revision 0) @@ -0,0 +1,59 @@ +// 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_SHARED_LOCK_GUARD_HPP +#define BOOST_THREAD_SHARED_LOCK_GUARD_HPP +#include +#include + +namespace boost +{ + + template + class shared_lock_guard + { + private: + SharedMutex& m; + +#ifndef BOOST_NO_DELETED_FUNCTIONS + public: + shared_lock_guard(shared_lock_guard const&) = delete; + shared_lock_guard& operator=(shared_lock_guard const&) = delete; +#else // BOOST_NO_DELETED_FUNCTIONS + private: + shared_lock_guard(shared_lock_guard&); + shared_lock_guard& operator=(shared_lock_guard&); +#endif // BOOST_NO_DELETED_FUNCTIONS + public: + typedef SharedMutex mutex_type; + explicit shared_lock_guard(SharedMutex& m_): + m(m_) + { + m.lock_shared(); + } + shared_lock_guard(SharedMutex& m_,adopt_lock_t): + m(m_) + {} + ~shared_lock_guard() + { + m.unlock_shared(); + } + }; + +#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: shared_lock_guard.hpp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Id Added: svn:eol-style + native Index: ../../libs/thread/doc/changes.qbk =================================================================== --- ../../libs/thread/doc/changes.qbk (revision 77660) +++ ../../libs/thread/doc/changes.qbk (working copy) @@ -14,9 +14,9 @@ [/ * [@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/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. * [@http://svn.boost.org/trac/boost/ticket/6194 #6194] Adapt to Boost.Move. Index: ../../libs/thread/doc/mutex_concepts.qbk =================================================================== --- ../../libs/thread/doc/mutex_concepts.qbk (revision 77660) +++ ../../libs/thread/doc/mutex_concepts.qbk (working copy) @@ -1524,6 +1524,8 @@ [endsect] [endsect] +] + [section:other_locks Other Lock Types] @@ -1591,6 +1593,7 @@ [endsect] +[/ [section:reverse_lock Class template `reverse_lock`] #include @@ -1639,10 +1642,11 @@ [endsect] +] [endsect] -] + [section:lock_functions Lock functions] [section:lock_multiple Non-member function `lock(Lockable1,Lockable2,...)`] Index: ../../libs/thread/test/Jamfile.v2 =================================================================== --- ../../libs/thread/test/Jamfile.v2 (revision 77658) +++ ../../libs/thread/test/Jamfile.v2 (working copy) @@ -377,4 +377,14 @@ #; + #explicit shared_lock_guard ; + test-suite shared_lock_guard + : + [ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/shared_lock_guard/copy_assign_fail.cpp : : shared_lock_guard__cons__copy_assign_f ] + [ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/shared_lock_guard/copy_ctor_fail.cpp : : shared_lock_guard__cons__copy_ctor_f ] + [ thread-run2 ./sync/mutual_exclusion/locks/shared_lock_guard/adopt_lock_pass.cpp : shared_lock_guard__cons__adopt_lock_p ] + [ thread-run2 ./sync/mutual_exclusion/locks/shared_lock_guard/default_pass.cpp : shared_lock_guard__cons__default_p ] + [ thread-run2 ./sync/mutual_exclusion/locks/shared_lock_guard/types_pass.cpp : shared_lock_guard__types_p ] + ; + } Index: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/adopt_lock_pass.cpp =================================================================== --- ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/adopt_lock_pass.cpp (revision 0) +++ ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/adopt_lock_pass.cpp (revision 0) @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class shared_lock_guard; + +// shared_lock_guard(mutex_type& m, adopt_lock_t); + +#include +#include +#include +#include + +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; + +boost::shared_mutex m; + +void f() +{ + time_point t0 = Clock::now(); + time_point t1; + { + m.lock(); + boost::shared_lock_guard lg(m, boost::adopt_lock); + t1 = Clock::now(); + } + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms +} + +int main() +{ + m.lock(); + boost::thread t(f); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + + return boost::report_errors(); +} + Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/adopt_lock_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/shared_lock_guard/copy_assign_fail.cpp =================================================================== --- ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_assign_fail.cpp (revision 0) +++ ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_assign_fail.cpp (revision 0) @@ -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) + +// + +// template class shared_lock_guard; + +// shared_lock_guard& operator=(shared_lock_guard const&) = delete; + +#include +#include +#include + +boost::shared_mutex m0; +boost::shared_mutex m1; + +int main() +{ + boost::shared_lock_guard lk0(m0); + boost::shared_lock_guard lk1(m1); + lk1 = lk0; + +} + Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/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/shared_lock_guard/default_pass.cpp =================================================================== --- ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/default_pass.cpp (revision 0) +++ ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/default_pass.cpp (revision 0) @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class shared_lock_guard; + +// shared_lock_guard(shared_lock_guard const&) = delete; + +#include +#include +#include +#include + +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; + +boost::shared_mutex m; + +void f() +{ + time_point t0 = Clock::now(); + time_point t1; + { + boost::shared_lock_guard lg(m); + t1 = Clock::now(); + } + ns d = t1 - t0 - ms(250); + // This test is spurious as it depends on the time the thread system switches the threads + BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms +} + +int main() +{ + m.lock(); + boost::thread t(f); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + + return boost::report_errors(); +} Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/default_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/shared_lock_guard/types_pass.cpp =================================================================== --- ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/types_pass.cpp (revision 0) +++ ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/types_pass.cpp (revision 0) @@ -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) 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 shared_lock_guard +// { +// public: +// typedef Mutex mutex_type; +// ... +// }; + + +#include +#include +#include +#include + +int main() +{ + BOOST_STATIC_ASSERT_MSG((boost::is_same::mutex_type, + boost::shared_mutex>::value), ""); + + return boost::report_errors(); +} + Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/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/shared_lock_guard/copy_ctor_fail.cpp =================================================================== --- ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_ctor_fail.cpp (revision 0) +++ ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_ctor_fail.cpp (revision 0) @@ -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) + +// + +// template class shared_lock_guard; + +// shared_lock_guard(shared_lock_guard const&) = delete; + + +#include +#include +#include + +boost::shared_mutex m0; +boost::shared_mutex m1; + +int main() +{ + boost::shared_lock_guard lk0(m0); + boost::shared_lock_guard lk1 = lk0; +} + Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_ctor_fail.cpp ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Added: svn:eol-style + native