1 2 // Copyright Oliver Kowalke 2013. 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 #ifndef BOOST_FIBERS_MUTEX_H 8 #define BOOST_FIBERS_MUTEX_H 9 10 #include <boost/config.hpp> 11 12 #include <boost/assert.hpp> 13 14 #include <boost/fiber/context.hpp> 15 #include <boost/fiber/detail/config.hpp> 16 #include <boost/fiber/detail/spinlock.hpp> 17 18 #ifdef BOOST_HAS_ABI_HEADERS 19 # include BOOST_ABI_PREFIX 20 #endif 21 22 #ifdef _MSC_VER 23 # pragma warning(push) 24 # pragma warning(disable:4251) 25 #endif 26 27 namespace boost { 28 namespace fibers { 29 30 class condition_variable; 31 32 class BOOST_FIBERS_DECL mutex { 33 private: 34 friend class condition_variable; 35 36 using wait_queue_type = context::wait_queue_t; 37 38 detail::spinlock wait_queue_splk_{}; 39 wait_queue_type wait_queue_{}; 40 context * owner_{ nullptr }; 41 42 public: 43 mutex() = default; 44 ~mutex()45 ~mutex() { 46 BOOST_ASSERT( nullptr == owner_); 47 BOOST_ASSERT( wait_queue_.empty() ); 48 } 49 50 mutex( mutex const&) = delete; 51 mutex & operator=( mutex const&) = delete; 52 53 void lock(); 54 55 bool try_lock(); 56 57 void unlock(); 58 }; 59 60 }} 61 62 #ifdef _MSC_VER 63 # pragma warning(pop) 64 #endif 65 66 #ifdef BOOST_HAS_ABI_HEADERS 67 # include BOOST_ABI_SUFFIX 68 #endif 69 70 #endif // BOOST_FIBERS_MUTEX_H 71