mutex.hpp 1.3 KB

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