Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:09:30

0001 // Distributed under the Boost Software License, Version 1.0. (See
0002 // accompanying file LICENSE_1_0.txt or copy at
0003 // http://www.boost.org/LICENSE_1_0.txt)
0004 // (C) Copyright 2012 Vicente J. Botet Escriba
0005 
0006 #ifndef BOOST_THREAD_LOCK_FACTORIES_HPP
0007 #define BOOST_THREAD_LOCK_FACTORIES_HPP
0008 
0009 #include <boost/thread/lock_types.hpp>
0010 #include <boost/thread/lock_algorithms.hpp>
0011 #if ! defined(BOOST_THREAD_NO_MAKE_UNIQUE_LOCKS)
0012 #include <tuple> // todo change to <boost/tuple.hpp> once Boost.Tuple or Boost.Fusion provides Move semantics.
0013 #endif
0014 #include <boost/config/abi_prefix.hpp>
0015 
0016 namespace boost
0017 {
0018 
0019   template <typename Lockable>
0020   unique_lock<Lockable> make_unique_lock(Lockable& mtx)
0021   {
0022     return unique_lock<Lockable> (mtx);
0023   }
0024 
0025   template <typename Lockable>
0026   unique_lock<Lockable> make_unique_lock(Lockable& mtx, adopt_lock_t)
0027   {
0028     return unique_lock<Lockable> (mtx, adopt_lock);
0029   }
0030 
0031   template <typename Lockable>
0032   unique_lock<Lockable> make_unique_lock(Lockable& mtx, defer_lock_t)
0033   {
0034     return unique_lock<Lockable> (mtx, defer_lock);
0035   }
0036 
0037   template <typename Lockable>
0038   unique_lock<Lockable> make_unique_lock(Lockable& mtx, try_to_lock_t)
0039   {
0040     return unique_lock<Lockable> (mtx, try_to_lock);
0041   }
0042 #if ! defined(BOOST_THREAD_NO_MAKE_UNIQUE_LOCKS)
0043 
0044 #if ! defined BOOST_NO_CXX11_VARIADIC_TEMPLATES
0045   template <typename ...Lockable>
0046   std::tuple<unique_lock<Lockable> ...> make_unique_locks(Lockable& ...mtx)
0047   {
0048     boost::lock(mtx...);
0049     return std::tuple<unique_lock<Lockable> ...>(unique_lock<Lockable>(mtx, adopt_lock)...);
0050   }
0051 #else
0052   template <typename L1, typename L2>
0053   std::tuple<unique_lock<L1>, unique_lock<L2> > make_unique_locks(L1& m1, L2& m2)
0054   {
0055     boost::lock(m1, m2);
0056     return std::tuple<unique_lock<L1>,unique_lock<L2> >(
0057         unique_lock<L1>(m1, adopt_lock),
0058         unique_lock<L2>(m2, adopt_lock)
0059     );
0060   }
0061   template <typename L1, typename L2, typename L3>
0062   std::tuple<unique_lock<L1>, unique_lock<L2>, unique_lock<L3> > make_unique_locks(L1& m1, L2& m2, L3& m3)
0063   {
0064     boost::lock(m1, m2, m3);
0065     return std::tuple<unique_lock<L1>,unique_lock<L2>,unique_lock<L3> >(
0066         unique_lock<L1>(m1, adopt_lock),
0067         unique_lock<L2>(m2, adopt_lock),
0068         unique_lock<L3>(m3, adopt_lock)
0069     );
0070   }
0071 
0072 #endif
0073 #endif
0074 
0075 }
0076 
0077 #include <boost/config/abi_suffix.hpp>
0078 #endif