#include <folly/experimental/ExecutionObserver.h>
#include <folly/futures/DrivableExecutor.h>
#include <folly/io/async/AsyncTimeout.h>
+#include <folly/io/async/HHWheelTimer.h>
#include <folly/io/async/Request.h>
#include <folly/io/async/TimeoutManager.h>
#include <folly/portability/PThread.h>
loopThread_.load(std::memory_order_relaxed), pthread_self());
}
+ HHWheelTimer& timer() {
+ if (!wheelTimer_) {
+ wheelTimer_ = HHWheelTimer::newTimer(this, std::chrono::milliseconds(1));
+ }
+ return *wheelTimer_.get();
+ }
+
// --------- interface to underlying libevent base ------------
// Avoid using these functions if possible. These functions are not
// guaranteed to always be present if we ever provide alternative EventBase
void initNotificationQueue();
+ // should only be accessed through public getter
+ HHWheelTimer::UniquePtr wheelTimer_;
+
CobTimeout::List pendingCobTimeouts_;
LoopCallbackList loopCallbacks_;
* Test scheduling a timeout from another timeout callback.
*/
TEST_F(HHWheelTimerTest, TestSchedulingWithinCallback) {
- StackWheelTimer t(&eventBase, milliseconds(10));
+ HHWheelTimer& t = eventBase.timer();
TestTimeout t1;
// Delayed to simulate the steady_clock counter lagging
*/
TEST_F(HHWheelTimerTest, CancelTimeout) {
- StackWheelTimer t(&eventBase, milliseconds(1));
+ HHWheelTimer& t = eventBase.timer();
// Create several timeouts that will all fire in 5ms.
TestTimeout t5_1(&t, milliseconds(5));
*/
TEST_F(HHWheelTimerTest, SlowLoop) {
- StackWheelTimer t(&eventBase, milliseconds(1));
+ HHWheelTimer& t = eventBase.timer();
TestTimeout t1;
TestTimeout t2;
}
TEST_F(HHWheelTimerTest, lambda) {
- StackWheelTimer t(&eventBase, milliseconds(1));
+ HHWheelTimer& t = eventBase.timer();
size_t count = 0;
t.scheduleTimeoutFn([&]{ count++; }, milliseconds(1));
eventBase.loop();
// shouldn't crash because we swallow and log the error (you'll have to look
// at the console to confirm logging)
TEST_F(HHWheelTimerTest, lambdaThrows) {
- StackWheelTimer t(&eventBase, milliseconds(1));
+ HHWheelTimer& t = eventBase.timer();
t.scheduleTimeoutFn([&]{ throw std::runtime_error("expected"); },
milliseconds(1));
eventBase.loop();
}
TEST_F(HHWheelTimerTest, cancelAll) {
- StackWheelTimer t(&eventBase);
+ HHWheelTimer& t = eventBase.timer();
TestTimeout tt;
t.scheduleTimeout(&tt, std::chrono::minutes(1));
EXPECT_EQ(1, t.cancelAll());