Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/log/utility/strictest_lock.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 /* | |
2 * Copyright Andrey Semashev 2007 - 2013. | |
3 * Distributed under the Boost Software License, Version 1.0. | |
4 * (See accompanying file LICENSE_1_0.txt or copy at | |
5 * http://www.boost.org/LICENSE_1_0.txt) | |
6 */ | |
7 /*! | |
8 * \file utility/strictest_lock.hpp | |
9 * \author Andrey Semashev | |
10 * \date 30.05.2010 | |
11 * | |
12 * The header contains definition of the \c strictest_lock metafunction that | |
13 * allows to select a lock with the strictest access requirements. | |
14 */ | |
15 | |
16 #ifndef BOOST_LOG_UTILITY_STRICTEST_LOCK_HPP_INCLUDED_ | |
17 #define BOOST_LOG_UTILITY_STRICTEST_LOCK_HPP_INCLUDED_ | |
18 | |
19 #include <boost/mpl/integral_c.hpp> | |
20 #include <boost/log/detail/config.hpp> | |
21 #include <boost/log/detail/locks.hpp> | |
22 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
23 #include <boost/preprocessor/cat.hpp> | |
24 #include <boost/preprocessor/arithmetic/sub.hpp> | |
25 #include <boost/preprocessor/arithmetic/inc.hpp> | |
26 #include <boost/preprocessor/arithmetic/dec.hpp> | |
27 #include <boost/preprocessor/repetition/enum_trailing.hpp> | |
28 #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp> | |
29 #include <boost/log/detail/pp_identity.hpp> | |
30 #endif | |
31 #if defined(BOOST_LOG_BROKEN_CONSTANT_EXPRESSIONS) | |
32 #include <boost/mpl/less.hpp> | |
33 #endif | |
34 #include <boost/log/detail/header.hpp> | |
35 | |
36 #ifdef BOOST_HAS_PRAGMA_ONCE | |
37 #pragma once | |
38 #endif | |
39 | |
40 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
41 #if !defined(BOOST_LOG_STRICTEST_LOCK_LIMIT) | |
42 /*! | |
43 * The macro defines the maximum number of template arguments that the \c strictest_lock | |
44 * metafunction accepts. Should not be less than 2. | |
45 */ | |
46 #define BOOST_LOG_STRICTEST_LOCK_LIMIT 10 | |
47 #endif // BOOST_LOG_STRICTEST_LOCK_LIMIT | |
48 #if BOOST_LOG_STRICTEST_LOCK_LIMIT < 2 | |
49 #error The BOOST_LOG_STRICTEST_LOCK_LIMIT macro should not be less than 2 | |
50 #endif | |
51 #endif // defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
52 | |
53 namespace boost { | |
54 | |
55 BOOST_LOG_OPEN_NAMESPACE | |
56 | |
57 //! Access modes for different types of locks | |
58 enum lock_access_mode | |
59 { | |
60 unlocked_access, //!< A thread that owns this kind of lock doesn't restrict other threads in any way | |
61 shared_access, //!< A thread that owns this kind of lock requires that no other thread modify the locked data | |
62 exclusive_access //!< A thread that owns this kind of lock requires that no other thread has access to the locked data | |
63 }; | |
64 | |
65 //! The trait allows to select an access mode by the lock type | |
66 template< typename LockT > | |
67 struct thread_access_mode_of; | |
68 | |
69 template< typename MutexT > | |
70 struct thread_access_mode_of< no_lock< MutexT > > : mpl::integral_c< lock_access_mode, unlocked_access > | |
71 { | |
72 }; | |
73 | |
74 #if !defined(BOOST_LOG_NO_THREADS) | |
75 | |
76 template< typename MutexT > | |
77 struct thread_access_mode_of< lock_guard< MutexT > > : mpl::integral_c< lock_access_mode, exclusive_access > | |
78 { | |
79 }; | |
80 | |
81 template< typename MutexT > | |
82 struct thread_access_mode_of< unique_lock< MutexT > > : mpl::integral_c< lock_access_mode, exclusive_access > | |
83 { | |
84 }; | |
85 | |
86 template< typename MutexT > | |
87 struct thread_access_mode_of< shared_lock< MutexT > > : mpl::integral_c< lock_access_mode, shared_access > | |
88 { | |
89 }; | |
90 | |
91 template< typename MutexT > | |
92 struct thread_access_mode_of< upgrade_lock< MutexT > > : mpl::integral_c< lock_access_mode, shared_access > | |
93 { | |
94 }; | |
95 | |
96 template< typename MutexT > | |
97 struct thread_access_mode_of< boost::log::aux::exclusive_lock_guard< MutexT > > : mpl::integral_c< lock_access_mode, exclusive_access > | |
98 { | |
99 }; | |
100 | |
101 template< typename MutexT > | |
102 struct thread_access_mode_of< boost::log::aux::shared_lock_guard< MutexT > > : mpl::integral_c< lock_access_mode, shared_access > | |
103 { | |
104 }; | |
105 | |
106 #endif // !defined(BOOST_LOG_NO_THREADS) | |
107 | |
108 namespace aux { | |
109 | |
110 //! The metafunction selects the most strict lock type of the two | |
111 template< | |
112 typename LeftLockT, | |
113 typename RightLockT, | |
114 #if !defined(BOOST_LOG_BROKEN_CONSTANT_EXPRESSIONS) | |
115 bool CondV = (thread_access_mode_of< LeftLockT >::value < thread_access_mode_of< RightLockT >::value) | |
116 #else | |
117 bool CondV = mpl::less< thread_access_mode_of< LeftLockT >, thread_access_mode_of< RightLockT > >::value | |
118 #endif | |
119 > | |
120 struct strictest_lock_impl | |
121 { | |
122 typedef RightLockT type; | |
123 }; | |
124 template< typename LeftLockT, typename RightLockT > | |
125 struct strictest_lock_impl< LeftLockT, RightLockT, false > | |
126 { | |
127 typedef LeftLockT type; | |
128 }; | |
129 | |
130 } // namespace aux | |
131 | |
132 #if defined(BOOST_LOG_DOXYGEN_PASS) | |
133 | |
134 /*! | |
135 * \brief The metafunction selects the most strict lock type of the specified. | |
136 * | |
137 * The template supports all lock types provided by the Boost.Thread | |
138 * library (except for \c upgrade_to_unique_lock), plus additional | |
139 * pseudo-lock \c no_lock that indicates no locking at all. | |
140 * Exclusive locks are considered the strictest, shared locks are weaker, | |
141 * and \c no_lock is the weakest. | |
142 */ | |
143 template< typename... LocksT > | |
144 struct strictest_lock | |
145 { | |
146 typedef implementation_defined type; | |
147 }; | |
148 | |
149 #else // defined(BOOST_LOG_DOXYGEN_PASS) | |
150 | |
151 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
152 | |
153 template< typename LockT, typename... LocksT > | |
154 struct strictest_lock; | |
155 | |
156 template< typename LockT > | |
157 struct strictest_lock< LockT > | |
158 { | |
159 typedef LockT type; | |
160 }; | |
161 | |
162 template< typename LeftLockT, typename RightLockT > | |
163 struct strictest_lock< LeftLockT, RightLockT > | |
164 { | |
165 typedef typename aux::strictest_lock_impl< LeftLockT, RightLockT >::type type; | |
166 }; | |
167 | |
168 template< typename LeftLockT, typename RightLockT, typename... LocksT > | |
169 struct strictest_lock< LeftLockT, RightLockT, LocksT... > | |
170 { | |
171 typedef typename strictest_lock< | |
172 typename aux::strictest_lock_impl< LeftLockT, RightLockT >::type, | |
173 LocksT... | |
174 >::type type; | |
175 }; | |
176 | |
177 #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
178 | |
179 # define BOOST_LOG_TYPE_INTERNAL(z, i, data) BOOST_PP_CAT(T, BOOST_PP_INC(i)) | |
180 | |
181 template< | |
182 typename T, | |
183 BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PP_DEC(BOOST_LOG_STRICTEST_LOCK_LIMIT), typename T, void) | |
184 > | |
185 struct strictest_lock | |
186 { | |
187 typedef typename strictest_lock< | |
188 typename boost::log::aux::strictest_lock_impl< T, T0 >::type | |
189 BOOST_PP_ENUM_TRAILING(BOOST_PP_SUB(BOOST_LOG_STRICTEST_LOCK_LIMIT, 2), BOOST_LOG_TYPE_INTERNAL, ~) | |
190 >::type type; | |
191 }; | |
192 | |
193 template< typename T > | |
194 struct strictest_lock< | |
195 T | |
196 BOOST_PP_ENUM_TRAILING(BOOST_PP_DEC(BOOST_LOG_STRICTEST_LOCK_LIMIT), BOOST_LOG_PP_IDENTITY, void) | |
197 > | |
198 { | |
199 typedef T type; | |
200 }; | |
201 | |
202 # undef BOOST_LOG_TYPE_INTERNAL | |
203 | |
204 #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
205 | |
206 #endif // defined(BOOST_LOG_DOXYGEN_PASS) | |
207 | |
208 BOOST_LOG_CLOSE_NAMESPACE // namespace log | |
209 | |
210 } // namespace boost | |
211 | |
212 #include <boost/log/detail/footer.hpp> | |
213 | |
214 #endif // BOOST_LOG_UTILITY_STRICTEST_LOCK_HPP_INCLUDED_ |