Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:05:27

0001 
0002 //          Copyright Oliver Kowalke 2013.
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //    (See accompanying file LICENSE_1_0.txt or copy at
0005 //          http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef BOOST_FIBERS_TIMED_MUTEX_H
0008 #define BOOST_FIBERS_TIMED_MUTEX_H
0009 
0010 #include <chrono>
0011 
0012 #include <boost/assert.hpp>
0013 #include <boost/config.hpp>
0014 
0015 #include <boost/fiber/context.hpp>
0016 #include <boost/fiber/detail/config.hpp>
0017 #include <boost/fiber/detail/convert.hpp>
0018 #include <boost/fiber/detail/spinlock.hpp>
0019 #include <boost/fiber/waker.hpp>
0020 
0021 #ifdef BOOST_HAS_ABI_HEADERS
0022 #  include BOOST_ABI_PREFIX
0023 #endif
0024 
0025 #ifdef _MSC_VER
0026 # pragma warning(push)
0027 # pragma warning(disable:4251)
0028 #endif
0029 
0030 namespace boost {
0031 namespace fibers {
0032 
0033 class condition_variable;
0034 
0035 class BOOST_FIBERS_DECL timed_mutex {
0036 private:
0037     friend class condition_variable;
0038 
0039     detail::spinlock            wait_queue_splk_{};
0040     wait_queue                  wait_queue_{};
0041     context                 *   owner_{ nullptr };
0042 
0043     bool try_lock_until_( std::chrono::steady_clock::time_point const& timeout_time) noexcept;
0044 
0045 public:
0046     timed_mutex() = default;
0047 
0048     ~timed_mutex() {
0049         BOOST_ASSERT( nullptr == owner_);
0050         BOOST_ASSERT( wait_queue_.empty() );
0051     }
0052 
0053     timed_mutex( timed_mutex const&) = delete;
0054     timed_mutex & operator=( timed_mutex const&) = delete;
0055 
0056     void lock();
0057 
0058     bool try_lock();
0059 
0060     template< typename Clock, typename Duration >
0061     bool try_lock_until( std::chrono::time_point< Clock, Duration > const& timeout_time_) {
0062         std::chrono::steady_clock::time_point timeout_time = detail::convert( timeout_time_);
0063         return try_lock_until_( timeout_time);
0064     }
0065 
0066     template< typename Rep, typename Period >
0067     bool try_lock_for( std::chrono::duration< Rep, Period > const& timeout_duration) {
0068         return try_lock_until_( std::chrono::steady_clock::now() + timeout_duration);
0069     }
0070 
0071     void unlock();
0072 };
0073 
0074 }}
0075 
0076 #ifdef _MSC_VER
0077 # pragma warning(pop)
0078 #endif
0079 
0080 #ifdef BOOST_HAS_ABI_HEADERS
0081 #  include BOOST_ABI_SUFFIX
0082 #endif
0083 
0084 #endif // BOOST_FIBERS_TIMED_MUTEX_H