Skip to content

Commit

Permalink
Explicit mutext (un)locking (#462)
Browse files Browse the repository at this point in the history
Signed-off-by: jolheiser <john.olheiser@gmail.com>
  • Loading branch information
John Olheiser authored and shogo82148 committed Mar 6, 2024
1 parent 2b2b5b1 commit 32a11e9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ func NewWatcher() (*Watcher, error) {

// Close removes all watches and closes the events channel.
func (w *Watcher) Close() error {
w.mu.Lock()
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)
Expand All @@ -68,6 +71,7 @@ func (w *Watcher) Close() error {
// Add starts watching the named file or directory (non-recursively).
func (w *Watcher) Add(name string) error {
if w.isClosed {
w.mu.Unlock()
return errors.New("watcher already closed")
}
in := &input{
Expand Down

0 comments on commit 32a11e9

Please sign in to comment.