Back to home page

EIC code displayed by LXR

 
 

    


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

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_REVERSE_LOCK_HPP
0007 #define BOOST_THREAD_REVERSE_LOCK_HPP
0008 #include <boost/thread/detail/config.hpp>
0009 #include <boost/thread/detail/move.hpp>
0010 #include <boost/thread/lockable_traits.hpp>
0011 #include <boost/thread/lock_options.hpp>
0012 #include <boost/thread/detail/delete.hpp>
0013 
0014 namespace boost
0015 {
0016 
0017     template<typename Lock>
0018     class reverse_lock
0019     {
0020     public:
0021         typedef typename Lock::mutex_type mutex_type;
0022         BOOST_THREAD_NO_COPYABLE(reverse_lock)
0023 
0024         explicit reverse_lock(Lock& m_)
0025         : m(m_), mtx(0)
0026         {
0027             if (m.owns_lock())
0028             {
0029               m.unlock();
0030             }
0031             mtx=m.release();
0032         }
0033         ~reverse_lock()
0034         {
0035           if (mtx) {
0036             mtx->lock();
0037             m = BOOST_THREAD_MAKE_RV_REF(Lock(*mtx, adopt_lock));
0038           }
0039         }
0040 
0041     private:
0042       Lock& m;
0043       mutex_type* mtx;
0044     };
0045 
0046 
0047 #ifdef BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES
0048     template<typename T>
0049     struct is_mutex_type<reverse_lock<T> >
0050     {
0051         BOOST_STATIC_CONSTANT(bool, value = true);
0052     };
0053 
0054 #endif
0055 
0056 
0057 }
0058 
0059 #endif // header