Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef BOOST_FIBERS_WAKER_H
0002 #define BOOST_FIBERS_WAKER_H
0003 
0004 #include <cstddef>
0005 
0006 #include <boost/config.hpp>
0007 #include <boost/fiber/detail/config.hpp>
0008 #include <boost/fiber/detail/spinlock.hpp>
0009 #include <boost/intrusive/slist.hpp>
0010 
0011 namespace boost {
0012 namespace fibers {
0013 
0014 class context;
0015 
0016 namespace detail {
0017 
0018 typedef intrusive::slist_member_hook<> waker_queue_hook;
0019 
0020 } // detail
0021 
0022 
0023 class BOOST_FIBERS_DECL waker {
0024 private:
0025     context *ctx_{};
0026     size_t epoch_{};
0027 
0028 public:
0029     friend class context;
0030 
0031     waker() = default;
0032 
0033     waker(context * ctx, const size_t epoch)
0034         : ctx_{ ctx }
0035         , epoch_{ epoch }
0036     {}
0037 
0038     bool wake() const noexcept;
0039 };
0040 
0041 
0042 class BOOST_FIBERS_DECL waker_with_hook : public waker {
0043 public:
0044     explicit waker_with_hook(waker && w)
0045         : waker{ std::move(w) }
0046     {}
0047 
0048     bool is_linked() const noexcept {
0049         return waker_queue_hook_.is_linked();
0050     }
0051 
0052     friend bool
0053     operator==( waker const& lhs, waker const& rhs) noexcept {
0054         return & lhs == & rhs;
0055     }
0056 
0057 public:
0058     detail::waker_queue_hook waker_queue_hook_{};
0059 };
0060 
0061 namespace detail {
0062     typedef intrusive::slist<
0063             waker_with_hook,
0064             intrusive::member_hook<
0065                 waker_with_hook, detail::waker_queue_hook, & waker_with_hook::waker_queue_hook_ >,
0066             intrusive::constant_time_size< false >,
0067             intrusive::cache_last< true >
0068         >                                               waker_slist_t;
0069 }
0070 
0071 class BOOST_FIBERS_DECL wait_queue {
0072 private:
0073     detail::waker_slist_t   slist_{};
0074 
0075 public:
0076     void suspend_and_wait( detail::spinlock_lock &, context *);
0077     bool suspend_and_wait_until( detail::spinlock_lock &,
0078                                  context *,
0079                                  std::chrono::steady_clock::time_point const&);
0080     void notify_one();
0081     void notify_all();
0082 
0083     bool empty() const;
0084 };
0085 
0086 }}
0087 
0088 #endif // BOOST_FIBERS_WAKER_H