Blame view

3rdparty/boost_1_81_0/boost/fiber/waker.hpp 1.86 KB
598bfd3f   Hu Chunming   提交_GLIBCXX_USE_CX...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  #ifndef BOOST_FIBERS_WAKER_H
  #define BOOST_FIBERS_WAKER_H
  
  #include <cstddef>
  
  #include <boost/config.hpp>
  #include <boost/fiber/detail/config.hpp>
  #include <boost/fiber/detail/spinlock.hpp>
  #include <boost/intrusive/slist.hpp>
  
  namespace boost {
  namespace fibers {
  
  class context;
  
  namespace detail {
  
  typedef intrusive::slist_member_hook<> waker_queue_hook;
  
  } // detail
  
  
  class BOOST_FIBERS_DECL waker {
  private:
      context *ctx_{};
      size_t epoch_{};
  
  public:
      friend class context;
  
      waker() = default;
  
      waker(context * ctx, const size_t epoch)
          : ctx_{ ctx }
          , epoch_{ epoch }
      {}
  
      bool wake() const noexcept;
  };
  
  
  class BOOST_FIBERS_DECL waker_with_hook : public waker {
  public:
      explicit waker_with_hook(waker && w)
          : waker{ std::move(w) }
      {}
  
      bool is_linked() const noexcept {
          return waker_queue_hook_.is_linked();
      }
  
      friend bool
      operator==( waker const& lhs, waker const& rhs) noexcept {
          return & lhs == & rhs;
      }
  
  public:
      detail::waker_queue_hook waker_queue_hook_{};
  };
  
  namespace detail {
      typedef intrusive::slist<
              waker_with_hook,
              intrusive::member_hook<
                  waker_with_hook, detail::waker_queue_hook, & waker_with_hook::waker_queue_hook_ >,
              intrusive::constant_time_size< false >,
              intrusive::cache_last< true >
          >                                               waker_slist_t;
  }
  
  class BOOST_FIBERS_DECL wait_queue {
  private:
      detail::waker_slist_t   slist_{};
  
  public:
      void suspend_and_wait( detail::spinlock_lock &, context *);
      bool suspend_and_wait_until( detail::spinlock_lock &,
                                   context *,
                                   std::chrono::steady_clock::time_point const&);
      void notify_one();
      void notify_all();
  
      bool empty() const;
  };
  
  }}
  
  #endif // BOOST_FIBERS_WAKER_H