Print expected/actual thread names when running EventBase logic in unexpected thread
[folly.git] / folly / io / async / EventBase.h
index 81fda805ead4578d2bf3e1160c3ded0f26c6352f..0ee54f57c812114f3c27ad2592fbe297cd28cd26 100644 (file)
@@ -492,6 +492,18 @@ class EventBase : private boost::noncopyable,
         std::this_thread::get_id();
   }
 
+  /**
+   * Equivalent to CHECK(isInEventBaseThread()) (and assert/DCHECK for
+   * dcheckIsInEventBaseThread), but it prints more information on
+   * failure.
+   */
+  void checkIsInEventBaseThread() const;
+  void dcheckIsInEventBaseThread() const {
+    if (kIsDebug) {
+      checkIsInEventBaseThread();
+    }
+  }
+
   HHWheelTimer& timer() {
     if (!wheelTimer_) {
       wheelTimer_ = HHWheelTimer::newTimer(this);
@@ -641,7 +653,7 @@ class EventBase : private boost::noncopyable,
 
  protected:
   void keepAliveRelease() override {
-    DCHECK(isInEventBaseThread());
+    dcheckIsInEventBaseThread();
     loopKeepAliveCount_--;
   }