proxygen
TimeoutManager.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <chrono>
20 #include <cstdint>
21 
22 #include <folly/Function.h>
23 
24 namespace folly {
25 
26 class AsyncTimeout;
27 
34  public:
35  typedef std::chrono::milliseconds timeout_type;
37 
38  enum class InternalEnum { INTERNAL, NORMAL };
39 
41 
42  virtual ~TimeoutManager();
43 
47  virtual void attachTimeoutManager(
48  AsyncTimeout* obj,
49  InternalEnum internal) = 0;
50  virtual void detachTimeoutManager(AsyncTimeout* obj) = 0;
51 
55  virtual bool scheduleTimeout(AsyncTimeout* obj, timeout_type timeout) = 0;
56 
60  virtual void cancelTimeout(AsyncTimeout* obj) = 0;
61 
66  virtual void bumpHandlingTime() = 0;
67 
72  virtual bool isInTimeoutManagerThread() = 0;
73 
80  void runAfterDelay(
81  Func cob,
82  uint32_t milliseconds,
84 
90  bool tryRunAfterDelay(
91  Func cob,
92  uint32_t milliseconds,
94 
95  protected:
96  void clearCobTimeouts();
97 
98  private:
99  struct CobTimeouts;
100  std::unique_ptr<CobTimeouts> cobTimeouts_;
101 };
102 
103 } // namespace folly
std::chrono::milliseconds timeout_type
bool tryRunAfterDelay(Func cob, uint32_t milliseconds, InternalEnum internal=InternalEnum::NORMAL)
virtual bool scheduleTimeout(AsyncTimeout *obj, timeout_type timeout)=0
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
virtual void attachTimeoutManager(AsyncTimeout *obj, InternalEnum internal)=0
std::unique_ptr< CobTimeouts > cobTimeouts_
virtual bool isInTimeoutManagerThread()=0
virtual void detachTimeoutManager(AsyncTimeout *obj)=0
void runAfterDelay(Func cob, uint32_t milliseconds, InternalEnum internal=InternalEnum::NORMAL)
virtual void bumpHandlingTime()=0
virtual void cancelTimeout(AsyncTimeout *obj)=0