]> go.fuhry.dev Git - fsnotify.git/commitdiff
Explicit mutext (un)locking (#462)
authorJohn Olheiser <john+github@jolheiser.com>
Thu, 21 Jul 2022 07:25:52 +0000 (02:25 -0500)
committerGitHub <noreply@github.com>
Thu, 21 Jul 2022 07:25:52 +0000 (09:25 +0200)
Signed-off-by: jolheiser <john.olheiser@gmail.com>
windows.go

index 1c1fe412d028abed99a4b47d359eda5b92008978..ecae0ce1c23cd43b98314ea56bde66a220fe6018 100644 (file)
@@ -54,12 +54,12 @@ func NewWatcher() (*Watcher, error) {
 // Close removes all watches and closes the events channel.
 func (w *Watcher) Close() error {
        w.mu.Lock()
-       defer w.mu.Unlock()
-
        if w.isClosed {
+               w.mu.Unlock()
                return nil
        }
        w.isClosed = true
+       w.mu.Unlock()
 
        // Send "quit" message to the reader goroutine
        ch := make(chan error)
@@ -74,6 +74,7 @@ func (w *Watcher) Close() error {
 func (w *Watcher) Add(name string) error {
        w.mu.Lock()
        if w.isClosed {
+               w.mu.Unlock()
                return errors.New("watcher already closed")
        }
        w.mu.Unlock()