mutex.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include <boost/fiber/waker.hpp>
  13. #ifdef BOOST_HAS_ABI_HEADERS
  14. # include BOOST_ABI_PREFIX
  15. #endif
  16. #ifdef _MSC_VER
  17. # pragma warning(push)
  18. # pragma warning(disable:4251)
  19. #endif
  20. namespace boost {
  21. namespace fibers {
  22. class condition_variable;
  23. class BOOST_FIBERS_DECL mutex {
  24. private:
  25. friend class condition_variable;
  26. detail::spinlock wait_queue_splk_{};
  27. wait_queue 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