File tree 1 file changed +7
-7
lines changed
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) {
26
26
}
27
27
28
28
// remove removes a watcher from the container.
29
- func (c * watcherContainer ) remove (watcher * poolWatcher ) {
29
+ func (c * watcherContainer ) remove (watcher * poolWatcher ) bool {
30
30
c .mutex .Lock ()
31
31
defer c .mutex .Unlock ()
32
32
33
33
if watcher == c .head {
34
34
c .head = watcher .next
35
+ return true
35
36
} else {
36
37
cur := c .head
37
38
for cur .next != nil {
38
39
if cur .next == watcher {
39
40
cur .next = watcher .next
40
- break
41
+ return true
41
42
}
42
43
cur = cur .next
43
44
}
44
45
}
46
+ return false
45
47
}
46
48
47
49
// foreach iterates over the container to the end or until the call returns
@@ -83,15 +85,13 @@ type poolWatcher struct {
83
85
84
86
// Unregister unregisters the pool watcher.
85
87
func (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 ()
91
90
w .unregistered = true
92
91
for _ , watcher := range w .watchers {
93
92
watcher .Unregister ()
94
93
}
94
+ w .mutex .Unlock ()
95
95
}
96
96
}
97
97
You can’t perform that action at this time.
0 commit comments