23 #include <boost/intrusive/list.hpp> 24 #include <glog/logging.h> 57 using UniquePtr = std::unique_ptr<HHWheelTimer, Destructor>;
60 template <
typename...
Args>
69 :
public boost::intrusive::list_base_hook<
70 boost::intrusive::link_mode<boost::intrusive::auto_unlink>> {
128 std::chrono::steady_clock::time_point
now)
const {
130 return std::chrono::milliseconds(0);
132 return std::chrono::duration_cast<std::chrono::milliseconds>(
143 typedef boost::intrusive::
144 list<Callback, boost::intrusive::constant_time_size<false>>
166 std::chrono::milliseconds intervalMS =
167 std::chrono::milliseconds(DEFAULT_TICK_INTERVAL),
169 std::chrono::milliseconds defaultTimeoutMS =
170 std::chrono::milliseconds(-1));
214 std::chrono::milliseconds timeout);
235 }
catch (std::exception
const& e) {
236 LOG(ERROR) <<
"HHWheelTimer timeout callback threw an exception: " 239 LOG(ERROR) <<
"HHWheelTimer timeout callback threw a non-exception.";
295 return t.count() / interval_.count();
static constexpr unsigned int WHEEL_MASK
static constexpr int WHEEL_BUCKETS
static constexpr int WHEEL_BITS
virtual void callbackCanceled() noexcept
static constexpr uint32_t LARGEST_SLOT
constexpr detail::Map< Move > move
std::chrono::steady_clock::time_point now()
const TimeoutManager * getTimeoutManager()
boost::intrusive::list< Callback, boost::intrusive::constant_time_size< false > > List
std::vector< std::size_t > bitmap_
void setDefaultTimeout(std::chrono::milliseconds timeout)
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
std::chrono::milliseconds getTimeRemaining()
—— Concurrent Priority Queue Implementation ——
static int DEFAULT_TICK_INTERVAL
requires E e noexcept(noexcept(s.error(std::move(e))))
HHWheelTimer(folly::TimeoutManager *timeoutManager, std::chrono::milliseconds intervalMS=std::chrono::milliseconds(DEFAULT_TICK_INTERVAL), AsyncTimeout::InternalEnum internal=AsyncTimeout::InternalEnum::NORMAL, std::chrono::milliseconds defaultTimeoutMS=std::chrono::milliseconds(-1))
void scheduleTimeout(Callback *callback, std::chrono::milliseconds timeout)
std::shared_ptr< HHWheelTimer > SharedPtr
std::chrono::steady_clock::time_point startTime_
CallbackList buckets_[WHEEL_BUCKETS][WHEEL_SIZE]
static UniquePtr newTimer(Args &&...args)
std::shared_ptr< RequestContext > requestContext_
bool isDetachable() const
void setScheduled(HHWheelTimer *wheel, std::chrono::milliseconds)
void scheduleTimeoutImpl(Callback *callback, std::chrono::milliseconds timeout)
static constexpr unsigned int WHEEL_SIZE
void scheduleTimeoutFn(F fn, std::chrono::milliseconds timeout)
virtual std::chrono::steady_clock::time_point getCurTime()
std::unique_ptr< HHWheelTimer, Destructor > UniquePtr
std::chrono::steady_clock::time_point expiration_
bool * processingCallbacksGuard_
void attachEventBase(EventBase *eventBase, InternalEnum internal=InternalEnum::NORMAL)
std::chrono::milliseconds defaultTimeout_
void scheduleNextTimeout()
int64_t timeToWheelTicks(std::chrono::milliseconds t)
friend class HHWheelTimer
std::chrono::milliseconds getTimeRemaining(std::chrono::steady_clock::time_point now) const
HHWheelTimer & operator=(HHWheelTimer const &)=delete
std::chrono::milliseconds getTickInterval() const
std::size_t count() const
Callback::List CallbackList
std::chrono::milliseconds getDefaultTimeout() const
bool cascadeTimers(int bucket, int tick)
virtual void timeoutExpired() noexcept=0
std::chrono::milliseconds interval_
std::chrono::steady_clock::time_point getCurTime()