]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_LOCK_FACTORIES_HPP | |
7 | #define BOOST_THREAD_LOCK_FACTORIES_HPP | |
8 | ||
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. | |
13 | #endif | |
14 | #include <boost/config/abi_prefix.hpp> | |
15 | ||
16 | namespace boost | |
17 | { | |
18 | ||
19 | template <typename Lockable> | |
20 | unique_lock<Lockable> make_unique_lock(Lockable& mtx) | |
21 | { | |
22 | return unique_lock<Lockable> (mtx); | |
23 | } | |
24 | ||
25 | template <typename Lockable> | |
26 | unique_lock<Lockable> make_unique_lock(Lockable& mtx, adopt_lock_t) | |
27 | { | |
28 | return unique_lock<Lockable> (mtx, adopt_lock); | |
29 | } | |
30 | ||
31 | template <typename Lockable> | |
32 | unique_lock<Lockable> make_unique_lock(Lockable& mtx, defer_lock_t) | |
33 | { | |
34 | return unique_lock<Lockable> (mtx, defer_lock); | |
35 | } | |
36 | ||
37 | template <typename Lockable> | |
38 | unique_lock<Lockable> make_unique_lock(Lockable& mtx, try_to_lock_t) | |
39 | { | |
40 | return unique_lock<Lockable> (mtx, try_to_lock); | |
41 | } | |
42 | #if ! defined(BOOST_THREAD_NO_MAKE_UNIQUE_LOCKS) | |
43 | ||
44 | #if ! defined BOOST_NO_CXX11_VARIADIC_TEMPLATES | |
45 | template <typename ...Lockable> | |
46 | std::tuple<unique_lock<Lockable> ...> make_unique_locks(Lockable& ...mtx) | |
47 | { | |
48 | boost::lock(mtx...); | |
49 | return std::tuple<unique_lock<Lockable> ...>(unique_lock<Lockable>(mtx, adopt_lock)...); | |
50 | } | |
51 | #else | |
52 | template <typename L1, typename L2> | |
53 | std::tuple<unique_lock<L1>, unique_lock<L2> > make_unique_locks(L1& m1, L2& m2) | |
54 | { | |
55 | boost::lock(m1, 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) | |
59 | ); | |
60 | } | |
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) | |
63 | { | |
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) | |
69 | ); | |
70 | } | |
71 | ||
72 | #endif | |
73 | #endif | |
74 | ||
75 | } | |
76 | ||
77 | #include <boost/config/abi_suffix.hpp> | |
78 | #endif |