diff --git a/src/Watcher.cc b/src/Watcher.cc index 4c7e24e..d3eeba8 100644 --- a/src/Watcher.cc +++ b/src/Watcher.cc @@ -75,6 +75,23 @@ void Watcher::notify() { } } +void Watcher::notify() { + { + std::unique_lock lk(mMutex); + mCond.notify_all(); + + if (mCallbacks.size() == 0 || mEvents.size() == 0) { + return; + } + } + + // We must have released our lock before calling into the debouncer + // to avoid a deadlock: the debouncer thread itself will require + // our lock from its thread when calling into `triggerCallbacks` + // while holding its own debouncer lock. + mDebounce->trigger(); +} + struct CallbackData { std::string error; std::vector events;