Skip to content

Commit

Permalink
simplify the fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Sep 11, 2024
1 parent f1ed36c commit 7c4d194
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ void Watcher::notify() {
mCond.notify_all();

if (mCallbacks.size() > 0 && mEvents.size() > 0) {
// We must release 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.
lk.unlock();
mDebounce->trigger();
}
}
Expand Down Expand Up @@ -113,7 +118,7 @@ void Watcher::notifyError(std::exception &err) {

// This function is called from the debounce thread.
void Watcher::triggerCallbacks() {
std::unique_lock<std::mutex> lk(mCallbackEventsMutex);
std::unique_lock<std::mutex> lk(mMutex);
if (mCallbacks.size() > 0 && mEvents.size() > 0) {
auto events = mEvents.getEvents();
mEvents.clear();
Expand Down
1 change: 0 additions & 1 deletion src/Watcher.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ struct Watcher {

private:
std::mutex mMutex;
std::mutex mCallbackEventsMutex;
std::condition_variable mCond;
std::vector<Callback> mCallbacks;
std::shared_ptr<Debounce> mDebounce;
Expand Down

0 comments on commit 7c4d194

Please sign in to comment.