Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:42

0001 #ifndef BOOST_SMART_PTR_DETAIL_LWM_STD_MUTEX_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_LWM_STD_MUTEX_HPP_INCLUDED
0003 
0004 // Copyright 2020 Peter Dimov
0005 // Distributed under the Boost Software License, Version 1.0.
0006 // https://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #include <boost/assert.hpp>
0009 #include <mutex>
0010 
0011 namespace boost
0012 {
0013 
0014 namespace detail
0015 {
0016 
0017 class lightweight_mutex
0018 {
0019 private:
0020 
0021     std::mutex m_;
0022 
0023     lightweight_mutex(lightweight_mutex const &);
0024     lightweight_mutex & operator=(lightweight_mutex const &);
0025 
0026 public:
0027 
0028     lightweight_mutex()
0029     {
0030     }
0031 
0032     class scoped_lock;
0033     friend class scoped_lock;
0034 
0035     class scoped_lock
0036     {
0037     private:
0038 
0039         std::mutex & m_;
0040 
0041         scoped_lock(scoped_lock const &);
0042         scoped_lock & operator=(scoped_lock const &);
0043 
0044     public:
0045 
0046         scoped_lock( lightweight_mutex & m ): m_( m.m_ )
0047         {
0048             m_.lock();
0049         }
0050 
0051         ~scoped_lock()
0052         {
0053             m_.unlock();
0054         }
0055     };
0056 };
0057 
0058 } // namespace detail
0059 
0060 } // namespace boost
0061 
0062 #endif // #ifndef BOOST_SMART_PTR_DETAIL_LWM_STD_MUTEX_HPP_INCLUDED