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
6 #ifndef BOOST_THREAD_LOCK_FACTORIES_HPP
7 #define BOOST_THREAD_LOCK_FACTORIES_HPP
9 #include <boost/thread/lock_types.hpp>
10 #include <boost/thread/lock_algorithms.hpp>
11 #if ! defined(BOOST_THREAD_NO_MAKE_UNIQUE_LOCKS)
12 #include <tuple> // todo change to <boost/tuple.hpp> once Boost.Tuple or Boost.Fusion provides Move semantics.
14 #include <boost/config/abi_prefix.hpp>
19 template <typename Lockable>
20 unique_lock<Lockable> make_unique_lock(Lockable& mtx)
22 return unique_lock<Lockable> (mtx);
25 template <typename Lockable>
26 unique_lock<Lockable> make_unique_lock(Lockable& mtx, adopt_lock_t)
28 return unique_lock<Lockable> (mtx, adopt_lock);
31 template <typename Lockable>
32 unique_lock<Lockable> make_unique_lock(Lockable& mtx, defer_lock_t)
34 return unique_lock<Lockable> (mtx, defer_lock);
37 template <typename Lockable>
38 unique_lock<Lockable> make_unique_lock(Lockable& mtx, try_to_lock_t)
40 return unique_lock<Lockable> (mtx, try_to_lock);
42 #if ! defined(BOOST_THREAD_NO_MAKE_UNIQUE_LOCKS)
44 #if ! defined BOOST_NO_CXX11_VARIADIC_TEMPLATES
45 template <typename ...Lockable>
46 std::tuple<unique_lock<Lockable> ...> make_unique_locks(Lockable& ...mtx)
49 return std::tuple<unique_lock<Lockable> ...>(unique_lock<Lockable>(mtx, adopt_lock)...);
52 template <typename L1, typename L2>
53 std::tuple<unique_lock<L1>, unique_lock<L2> > make_unique_locks(L1& m1, L2& m2)
56 return std::tuple<unique_lock<L1>,unique_lock<L2> >(
57 unique_lock<L1>(m1, adopt_lock),
58 unique_lock<L2>(m2, adopt_lock)
61 template <typename L1, typename L2, typename L3>
62 std::tuple<unique_lock<L1>, unique_lock<L2>, unique_lock<L3> > make_unique_locks(L1& m1, L2& m2, L3& m3)
64 boost::lock(m1, m2, m3);
65 return std::tuple<unique_lock<L1>,unique_lock<L2>,unique_lock<L3> >(
66 unique_lock<L1>(m1, adopt_lock),
67 unique_lock<L2>(m2, adopt_lock),
68 unique_lock<L3>(m3, adopt_lock)
77 #include <boost/config/abi_suffix.hpp>