@@ -862,7 +862,8 @@ func (c *Cacher) startDispatchingBookmarkEvents() {
862
862
// as we don't delete watcher from bookmarkWatchers when it is stopped.
863
863
for _ , watchers := range c .bookmarkWatchers .popExpiredWatchers () {
864
864
for _ , watcher := range watchers {
865
- // watcher.stop() is protected by c.Lock()
865
+ // c.Lock() is held here.
866
+ // watcher.stopThreadUnsafe() is protected by c.Lock()
866
867
if watcher .stopped {
867
868
continue
868
869
}
@@ -932,7 +933,7 @@ func (c *Cacher) finishDispatching() {
932
933
defer c .Unlock ()
933
934
c .dispatching = false
934
935
for _ , watcher := range c .watchersToStop {
935
- watcher .stop ()
936
+ watcher .stopThreadUnsafe ()
936
937
}
937
938
c .watchersToStop = c .watchersToStop [:0 ]
938
939
}
@@ -947,7 +948,7 @@ func (c *Cacher) stopWatcherThreadUnsafe(watcher *cacheWatcher) {
947
948
if c .dispatching {
948
949
c .watchersToStop = append (c .watchersToStop , watcher )
949
950
} else {
950
- watcher .stop ()
951
+ watcher .stopThreadUnsafe ()
951
952
}
952
953
}
953
954
@@ -977,7 +978,7 @@ func forgetWatcher(c *Cacher, index int, triggerValue string, triggerSupported b
977
978
defer c .Unlock ()
978
979
979
980
// It's possible that the watcher is already not in the structure (e.g. in case of
980
- // simultaneous Stop() and terminateAllWatchers(), but it is safe to call stop ()
981
+ // simultaneous Stop() and terminateAllWatchers(), but it is safe to call stopThreadUnsafe ()
981
982
// on a watcher multiple times.
982
983
c .watchers .deleteWatcher (index , triggerValue , triggerSupported , c .stopWatcherThreadUnsafe )
983
984
}
@@ -1079,8 +1080,8 @@ func (c *errWatcher) Stop() {
1079
1080
}
1080
1081
1081
1082
// cacheWatcher implements watch.Interface
1083
+ // this is not thread-safe
1082
1084
type cacheWatcher struct {
1083
- sync.Mutex
1084
1085
input chan * watchCacheEvent
1085
1086
result chan watch.Event
1086
1087
done chan struct {}
@@ -1121,12 +1122,8 @@ func (c *cacheWatcher) Stop() {
1121
1122
c .forget ()
1122
1123
}
1123
1124
1124
- // TODO(#73958)
1125
- // stop() is protected by Cacher.Lock(), rename it to
1126
- // stopThreadUnsafe and remove the sync.Mutex.
1127
- func (c * cacheWatcher ) stop () {
1128
- c .Lock ()
1129
- defer c .Unlock ()
1125
+ // we rely on the fact that stopThredUnsafe is actually protected by Cacher.Lock()
1126
+ func (c * cacheWatcher ) stopThreadUnsafe () {
1130
1127
if ! c .stopped {
1131
1128
c .stopped = true
1132
1129
close (c .done )
0 commit comments