delete &runBeforeLoopCallbacks_.front();
}
- (void) runLoopCallbacks(false);
+ (void)runLoopCallbacks();
if (!fnRunner_->consumeUntilDrained()) {
LOG(ERROR) << "~EventBase(): Unable to drain notification queue";
return true;
}
-bool EventBase::runLoopCallbacks(bool setContext) {
+bool EventBase::runLoopCallbacks() {
if (!loopCallbacks_.empty()) {
bumpHandlingTime();
// Swap the loopCallbacks_ list with a temporary list on our stack.
while (!currentCallbacks.empty()) {
LoopCallback* callback = ¤tCallbacks.front();
currentCallbacks.pop_front();
- if (setContext) {
- RequestContext::setContext(callback->context_);
- }
+ folly::RequestContextScopeGuard rctx(callback->context_);
callback->runLoopCallback();
}
bool loopBody(int flags = 0);
// executes any callbacks queued by runInLoop(); returns false if none found
- bool runLoopCallbacks(bool setContext = true);
+ bool runLoopCallbacks();
void initNotificationQueue();
t.join();
}
+
+TEST(EventBaseTest, RequestContextTest) {
+ EventBase evb;
+ auto defaultCtx = RequestContext::get();
+
+ {
+ RequestContextScopeGuard rctx;
+ auto context = RequestContext::get();
+ EXPECT_NE(defaultCtx, context);
+ evb.runInLoop([context] { EXPECT_EQ(context, RequestContext::get()); });
+ }
+
+ EXPECT_EQ(defaultCtx, RequestContext::get());
+ evb.loop();
+ EXPECT_EQ(defaultCtx, RequestContext::get());
+}