]> go.fuhry.dev Git - fsnotify.git/commit
Watch.Add improvements (avoid race, fix consistency, reduce garbage) (#189)
authorTom Payne <twpayne@gmail.com>
Tue, 21 Mar 2017 12:55:22 +0000 (13:55 +0100)
committerPawel Knap <ppknap@users.noreply.github.com>
Tue, 21 Mar 2017 12:55:22 +0000 (13:55 +0100)
commitff7bc41d4007f67e5456703c34342df4e0113f64
tree881d553c93c8ec1bdd198d90e54be7cb9a914df8
parent7d7316ed6e1ed2de075aab8dfc76de5d158d66e1
Watch.Add improvements (avoid race, fix consistency, reduce garbage) (#189)

* hold mutex for longer to avoid race condition

If Watcher.Add is called with the same name from multiple goroutines and
name is not already in the watches map then the last call to complete
wins and the watch created by the first call to complete is lost.

This commit holds the mutex for the full duration of the update to the
watches map.

* avoid clobbering existing flags if inotify_add_watch fails

Previously, the watch entry is the watches map was updated before the
call to InotifyAddWatch. If InotifyAddWatch fails then this left the
watch entry in an inconsistent state.

* reuse existing watch entry when possible
inotify.go