File indexing completed on 2024-11-15 09:05:26
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_FIBERS_RECURSIVE_TIMED_MUTEX_H
0010 #define BOOST_FIBERS_RECURSIVE_TIMED_MUTEX_H
0011
0012 #include <chrono>
0013 #include <cstddef>
0014
0015 #include <boost/config.hpp>
0016
0017 #include <boost/assert.hpp>
0018
0019 #include <boost/fiber/context.hpp>
0020 #include <boost/fiber/detail/config.hpp>
0021 #include <boost/fiber/detail/convert.hpp>
0022 #include <boost/fiber/detail/spinlock.hpp>
0023 #include <boost/fiber/waker.hpp>
0024
0025 #ifdef BOOST_HAS_ABI_HEADERS
0026 # include BOOST_ABI_PREFIX
0027 #endif
0028
0029 #ifdef _MSC_VER
0030 # pragma warning(push)
0031 # pragma warning(disable:4251)
0032 #endif
0033
0034 namespace boost {
0035 namespace fibers {
0036
0037 class condition_variable;
0038
0039 class BOOST_FIBERS_DECL recursive_timed_mutex {
0040 private:
0041 friend class condition_variable;
0042
0043 detail::spinlock wait_queue_splk_{};
0044 wait_queue wait_queue_{};
0045 context * owner_{ nullptr };
0046 std::size_t count_{ 0 };
0047
0048 bool try_lock_until_( std::chrono::steady_clock::time_point const& timeout_time) noexcept;
0049
0050 public:
0051 recursive_timed_mutex() = default;
0052
0053 ~recursive_timed_mutex() {
0054 BOOST_ASSERT( nullptr == owner_);
0055 BOOST_ASSERT( 0 == count_);
0056 BOOST_ASSERT( wait_queue_.empty() );
0057 }
0058
0059 recursive_timed_mutex( recursive_timed_mutex const&) = delete;
0060 recursive_timed_mutex & operator=( recursive_timed_mutex const&) = delete;
0061
0062 void lock();
0063
0064 bool try_lock() noexcept;
0065
0066 template< typename Clock, typename Duration >
0067 bool try_lock_until( std::chrono::time_point< Clock, Duration > const& timeout_time_) {
0068 std::chrono::steady_clock::time_point timeout_time = detail::convert( timeout_time_);
0069 return try_lock_until_( timeout_time);
0070 }
0071
0072 template< typename Rep, typename Period >
0073 bool try_lock_for( std::chrono::duration< Rep, Period > const& timeout_duration) {
0074 return try_lock_until_( std::chrono::steady_clock::now() + timeout_duration);
0075 }
0076
0077 void unlock();
0078 };
0079
0080 }}
0081
0082 #ifdef _MSC_VER
0083 # pragma warning(pop)
0084 #endif
0085
0086 #ifdef BOOST_HAS_ABI_HEADERS
0087 # include BOOST_ABI_SUFFIX
0088 #endif
0089
0090 #endif