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)
7 #ifndef BOOST_FIBERS_TIMED_MUTEX_H
8 #define BOOST_FIBERS_TIMED_MUTEX_H
12 #include <boost/assert.hpp>
13 #include <boost/config.hpp>
15 #include <boost/fiber/context.hpp>
16 #include <boost/fiber/detail/config.hpp>
17 #include <boost/fiber/detail/convert.hpp>
18 #include <boost/fiber/detail/spinlock.hpp>
20 #ifdef BOOST_HAS_ABI_HEADERS
21 # include BOOST_ABI_PREFIX
25 # pragma warning(push)
26 # pragma warning(disable:4251)
32 class condition_variable;
34 class BOOST_FIBERS_DECL timed_mutex {
36 friend class condition_variable;
38 typedef context::wait_queue_t wait_queue_t;
40 context * owner_{ nullptr };
41 wait_queue_t wait_queue_{};
42 detail::spinlock wait_queue_splk_{};
44 bool try_lock_until_( std::chrono::steady_clock::time_point const& timeout_time) noexcept;
47 timed_mutex() = default;
50 BOOST_ASSERT( nullptr == owner_);
51 BOOST_ASSERT( wait_queue_.empty() );
54 timed_mutex( timed_mutex const&) = delete;
55 timed_mutex & operator=( timed_mutex const&) = delete;
61 template< typename Clock, typename Duration >
62 bool try_lock_until( std::chrono::time_point< Clock, Duration > const& timeout_time_) {
63 std::chrono::steady_clock::time_point timeout_time(
64 detail::convert( timeout_time_) );
65 return try_lock_until_( timeout_time);
68 template< typename Rep, typename Period >
69 bool try_lock_for( std::chrono::duration< Rep, Period > const& timeout_duration) {
70 return try_lock_until_( std::chrono::steady_clock::now() + timeout_duration);
82 #ifdef BOOST_HAS_ABI_HEADERS
83 # include BOOST_ABI_SUFFIX
86 #endif // BOOST_FIBERS_TIMED_MUTEX_H