proxygen
WheelTimerInstance.cpp
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 
12 
13 #include <folly/Singleton.h>
16 
17 namespace proxygen {
18 
20 }
21 
23  wheelTimerPtr_(timer) {
24  if (timer) {
25  // If you use an external timer with no default timeout set, you will get
26  // a check failed if you attempt to schedule a default timeout.
28  }
29 }
30 
32  std::chrono::milliseconds defaultTimeoutMS,
33  folly::EventBase* eventBase) : defaultTimeoutMS_(defaultTimeoutMS) {
34  if (!eventBase) {
36  }
37  wheelTimerPtr_ = &eventBase->timer();
38 }
39 
41  : wheelTimerPtr_(timerInstance.wheelTimerPtr_),
42  defaultTimeoutMS_(timerInstance.defaultTimeoutMS_) {
43 }
44 
46  WheelTimerInstance&& timerInstance) noexcept
47  : wheelTimerPtr_(std::move(timerInstance.wheelTimerPtr_)),
48  defaultTimeoutMS_(std::move(timerInstance.defaultTimeoutMS_)) {
49 }
50 
51 std::chrono::milliseconds WheelTimerInstance::getDefaultTimeout() const {
52  return defaultTimeoutMS_;
53 }
54 
55 void WheelTimerInstance::setDefaultTimeout(std::chrono::milliseconds timeout) {
56  defaultTimeoutMS_ = timeout;
57 }
58 
61  std::chrono::milliseconds timeout) {
62  if (wheelTimerPtr_) {
63  wheelTimerPtr_->scheduleTimeout(callback, timeout);
64  } else {
65  VLOG(2) << "Ingoring scheduleTimeout on an empty WheelTimerInstance";
66  }
67 }
68 
71  CHECK_GE(defaultTimeoutMS_.count(), 0);
73 }
74 
78  return *this;
79 }
80 
83  wheelTimerPtr_ = std::move(timer.wheelTimerPtr_);
84  defaultTimeoutMS_ = std::move(timer.defaultTimeoutMS_);
85  return *this;
86 }
87 
88 WheelTimerInstance::operator bool() const {
89  return (wheelTimerPtr_ != nullptr);
90 }
91 
92 }
WheelTimerInstance & operator=(const WheelTimerInstance &timer)
EventBase * getEventBase() const
folly::HHWheelTimer * wheelTimerPtr_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::chrono::milliseconds getDefaultTimeout() const
STL namespace.
std::chrono::milliseconds defaultTimeoutMS_
requires E e noexcept(noexcept(s.error(std::move(e))))
void scheduleTimeout(folly::HHWheelTimer::Callback *callback, std::chrono::milliseconds timeout)
static EventBaseManager * get()
void scheduleTimeout(Callback *callback, std::chrono::milliseconds timeout)
std::chrono::milliseconds getDefaultTimeout() const
Definition: HHWheelTimer.h:193
void setDefaultTimeout(std::chrono::milliseconds timeout)
HHWheelTimer & timer()
Definition: EventBase.h:526