1 // 2 // detail/std_static_mutex.hpp 3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4 // 5 // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) 6 // 7 // Distributed under the Boost Software License, Version 1.0. (See accompanying 8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 // 10 11 #ifndef BOOST_ASIO_DETAIL_STD_STATIC_MUTEX_HPP 12 #define BOOST_ASIO_DETAIL_STD_STATIC_MUTEX_HPP 13 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 15 # pragma once 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 17 18 #include <boost/asio/detail/config.hpp> 19 20 #if defined(BOOST_ASIO_HAS_STD_MUTEX_AND_CONDVAR) 21 22 #include <mutex> 23 #include <boost/asio/detail/noncopyable.hpp> 24 #include <boost/asio/detail/scoped_lock.hpp> 25 26 #include <boost/asio/detail/push_options.hpp> 27 28 namespace boost { 29 namespace asio { 30 namespace detail { 31 32 class std_event; 33 34 class std_static_mutex 35 : private noncopyable 36 { 37 public: 38 typedef boost::asio::detail::scoped_lock<std_static_mutex> scoped_lock; 39 40 // Constructor. std_static_mutex(int)41 std_static_mutex(int) 42 { 43 } 44 45 // Destructor. ~std_static_mutex()46 ~std_static_mutex() 47 { 48 } 49 50 // Initialise the mutex. init()51 void init() 52 { 53 // Nothing to do. 54 } 55 56 // Lock the mutex. lock()57 void lock() 58 { 59 mutex_.lock(); 60 } 61 62 // Unlock the mutex. unlock()63 void unlock() 64 { 65 mutex_.unlock(); 66 } 67 68 private: 69 friend class std_event; 70 std::mutex mutex_; 71 }; 72 73 #define BOOST_ASIO_STD_STATIC_MUTEX_INIT 0 74 75 } // namespace detail 76 } // namespace asio 77 } // namespace boost 78 79 #include <boost/asio/detail/pop_options.hpp> 80 81 #endif // defined(BOOST_ASIO_HAS_STD_MUTEX_AND_CONDVAR) 82 83 #endif // BOOST_ASIO_DETAIL_STD_STATIC_MUTEX_HPP 84