File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -26,22 +26,24 @@ func (c *watcherContainer) add(watcher *poolWatcher) {
2626}
2727
2828// remove removes a watcher from the container.
29- func (c * watcherContainer ) remove (watcher * poolWatcher ) {
29+ func (c * watcherContainer ) remove (watcher * poolWatcher ) bool {
3030 c .mutex .Lock ()
3131 defer c .mutex .Unlock ()
3232
3333 if watcher == c .head {
3434 c .head = watcher .next
35+ return true
3536 } else {
3637 cur := c .head
3738 for cur .next != nil {
3839 if cur .next == watcher {
3940 cur .next = watcher .next
40- break
41+ return true
4142 }
4243 cur = cur .next
4344 }
4445 }
46+ return false
4547}
4648
4749// foreach iterates over the container to the end or until the call returns
@@ -83,15 +85,13 @@ type poolWatcher struct {
8385
8486// Unregister unregisters the pool watcher.
8587func (w * poolWatcher ) Unregister () {
86- w .mutex .Lock ()
87- defer w .mutex .Unlock ()
88-
89- if ! w .unregistered {
90- w .container .remove (w )
88+ if ! w .unregistered && w .container .remove (w ) {
89+ w .mutex .Lock ()
9190 w .unregistered = true
9291 for _ , watcher := range w .watchers {
9392 watcher .Unregister ()
9493 }
94+ w .mutex .Unlock ()
9595 }
9696}
9797
You can’t perform that action at this time.
0 commit comments