1 // 2 // detail/std_mutex.hpp 3 // ~~~~~~~~~~~~~~~~~~~~ 4 // 5 // Copyright (c) 2003-2016 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 ASIO_DETAIL_STD_MUTEX_HPP 12 #define ASIO_DETAIL_STD_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 "asio/detail/config.hpp" 19 20 #if defined(ASIO_HAS_STD_MUTEX_AND_CONDVAR) 21 22 #include <mutex> 23 #include "asio/detail/noncopyable.hpp" 24 #include "asio/detail/scoped_lock.hpp" 25 26 #include "asio/detail/push_options.hpp" 27 28 namespace asio { 29 namespace detail { 30 31 class std_event; 32 33 class std_mutex 34 : private noncopyable 35 { 36 public: 37 typedef asio::detail::scoped_lock<std_mutex> scoped_lock; 38 39 // Constructor. std_mutex()40 std_mutex() 41 { 42 } 43 44 // Destructor. ~std_mutex()45 ~std_mutex() 46 { 47 } 48 49 // Lock the mutex. lock()50 void lock() 51 { 52 mutex_.lock(); 53 } 54 55 // Unlock the mutex. unlock()56 void unlock() 57 { 58 mutex_.unlock(); 59 } 60 61 private: 62 friend class std_event; 63 std::mutex mutex_; 64 }; 65 66 } // namespace detail 67 } // namespace asio 68 69 #include "asio/detail/pop_options.hpp" 70 71 #endif // defined(ASIO_HAS_STD_MUTEX_AND_CONDVAR) 72 73 #endif // ASIO_DETAIL_STD_MUTEX_HPP 74