@@ -856,7 +856,8 @@ func (c *Cacher) startDispatchingBookmarkEvents() {
856
856
// as we don't delete watcher from bookmarkWatchers when it is stopped.
857
857
for _ , watchers := range c .bookmarkWatchers .popExpiredWatchers () {
858
858
for _ , watcher := range watchers {
859
- // watcher.stop() is protected by c.Lock()
859
+ // c.Lock() is held here.
860
+ // watcher.stopThreadUnsafe() is protected by c.Lock()
860
861
if watcher .stopped {
861
862
continue
862
863
}
@@ -926,7 +927,7 @@ func (c *Cacher) finishDispatching() {
926
927
defer c .Unlock ()
927
928
c .dispatching = false
928
929
for _ , watcher := range c .watchersToStop {
929
- watcher .stop ()
930
+ watcher .stopThreadUnsafe ()
930
931
}
931
932
c .watchersToStop = c .watchersToStop [:0 ]
932
933
}
@@ -941,7 +942,7 @@ func (c *Cacher) stopWatcherThreadUnsafe(watcher *cacheWatcher) {
941
942
if c .dispatching {
942
943
c .watchersToStop = append (c .watchersToStop , watcher )
943
944
} else {
944
- watcher .stop ()
945
+ watcher .stopThreadUnsafe ()
945
946
}
946
947
}
947
948
@@ -971,7 +972,7 @@ func forgetWatcher(c *Cacher, index int, triggerValue string, triggerSupported b
971
972
defer c .Unlock ()
972
973
973
974
// It's possible that the watcher is already not in the structure (e.g. in case of
974
- // simultaneous Stop() and terminateAllWatchers(), but it is safe to call stop ()
975
+ // simultaneous Stop() and terminateAllWatchers(), but it is safe to call stopThreadUnsafe ()
975
976
// on a watcher multiple times.
976
977
c .watchers .deleteWatcher (index , triggerValue , triggerSupported , c .stopWatcherThreadUnsafe )
977
978
}
@@ -1073,8 +1074,8 @@ func (c *errWatcher) Stop() {
1073
1074
}
1074
1075
1075
1076
// cacheWatcher implements watch.Interface
1077
+ // this is not thread-safe
1076
1078
type cacheWatcher struct {
1077
- sync.Mutex
1078
1079
input chan * watchCacheEvent
1079
1080
result chan watch.Event
1080
1081
done chan struct {}
@@ -1115,12 +1116,8 @@ func (c *cacheWatcher) Stop() {
1115
1116
c .forget ()
1116
1117
}
1117
1118
1118
- // TODO(#73958)
1119
- // stop() is protected by Cacher.Lock(), rename it to
1120
- // stopThreadUnsafe and remove the sync.Mutex.
1121
- func (c * cacheWatcher ) stop () {
1122
- c .Lock ()
1123
- defer c .Unlock ()
1119
+ // we rely on the fact that stopThredUnsafe is actually protected by Cacher.Lock()
1120
+ func (c * cacheWatcher ) stopThreadUnsafe () {
1124
1121
if ! c .stopped {
1125
1122
c .stopped = true
1126
1123
close (c .done )
0 commit comments