proxygen
WheelTimerInstance.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
10 
11 #pragma once
12 
13 #include <chrono>
14 #include <memory>
15 
17 
18 namespace folly {
19 
20 class EventBase;
21 
22 }
23 
24 namespace proxygen {
25 
26 /*
27  * Class to be used to schedule timeouts, has associated HHWheelTimer & timeout
28  */
30  public:
31 
32  // will ignore all scheduleTimeout operations, to be used instead of
33  // nullptr for HHWheelTimer
35 
36  // will use WheelTimer of the EventBase thread
37  explicit WheelTimerInstance(std::chrono::milliseconds defaultTimeoutMS,
38  folly::EventBase* eventBase = nullptr);
39 
40  WheelTimerInstance(const WheelTimerInstance& timerInstance);
42 
43  // timer could be nullptr which is correct usecase meaning that timeout
44  // will not be scheduled
45  explicit WheelTimerInstance(folly::HHWheelTimer* timer);
46 
47  std::chrono::milliseconds getDefaultTimeout() const;
48  void setDefaultTimeout(std::chrono::milliseconds timeout);
49 
50  // These timeout callbacks will be scheduled on the current thread
51  void scheduleTimeout(folly::HHWheelTimer::Callback* callback,
52  std::chrono::milliseconds timeout);
53  void scheduleTimeout(folly::HHWheelTimer::Callback* callback);
54 
55  WheelTimerInstance& operator=(const WheelTimerInstance& timer);
56  WheelTimerInstance& operator=(const WheelTimerInstance&& timer);
57 
58  // returns true if it is empty
59  explicit operator bool() const;
60 
62  return wheelTimerPtr_;
63  }
64 
65  private:
66 
67  folly::HHWheelTimer* wheelTimerPtr_{nullptr}; // to support cases when
68  // external WheelTimer is
69  // specified
70 
71  std::chrono::milliseconds defaultTimeoutMS_;
72 };
73 
74 }
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
std::chrono::milliseconds defaultTimeoutMS_
requires E e noexcept(noexcept(s.error(std::move(e))))
folly::HHWheelTimer * getWheelTimer() const