Skip to content

Commit 5071ed6

Browse files
cuishuanggopherbot
authored andcommitted
all: fix some comments to improve readability
Change-Id: If88a7d731009bfb40774ea45a94187ce4d0db848 Reviewed-on: https://go-review.googlesource.com/c/sync/+/785081 Reviewed-by: Mark Freeman <markfreeman@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
1 parent ec11c4a commit 5071ed6

6 files changed

Lines changed: 14 additions & 14 deletions

File tree

errgroup/errgroup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (g *Group) TryGo(f func() error) bool {
109109
if g.sem != nil {
110110
select {
111111
case g.sem <- token{}:
112-
// Note: this allows barging iff channels in general allow barging.
112+
// Note: this allows barging if and only if channels in general allow barging.
113113
default:
114114
return false
115115
}

semaphore/semaphore.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (s *Weighted) Acquire(ctx context.Context, n int64) error {
8383
default:
8484
isFront := s.waiters.Front() == elem
8585
s.waiters.Remove(elem)
86-
// If we're at the front and there're extra tokens left, notify other waiters.
86+
// If we're at the front and there are extra tokens left, notify other waiters.
8787
if isFront && s.size > s.cur {
8888
s.notifyWaiters()
8989
}
@@ -139,15 +139,15 @@ func (s *Weighted) notifyWaiters() {
139139

140140
w := next.Value.(waiter)
141141
if s.size-s.cur < w.n {
142-
// Not enough tokens for the next waiter. We could keep going (to try to
142+
// Not enough tokens for the next waiter. We could keep going (to try to
143143
// find a waiter with a smaller request), but under load that could cause
144144
// starvation for large requests; instead, we leave all remaining waiters
145145
// blocked.
146146
//
147147
// Consider a semaphore used as a read-write lock, with N tokens, N
148-
// readers, and one writer. Each reader can Acquire(1) to obtain a read
149-
// lock. The writer can Acquire(N) to obtain a write lock, excluding all
150-
// of the readers. If we allow the readers to jump ahead in the queue,
148+
// readers, and one writer. Each reader can Acquire(1) to obtain a read
149+
// lock. The writer can Acquire(N) to obtain a write lock, excluding all
150+
// of the readers. If we allow the readers to jump ahead in the queue,
151151
// the writer will starve — there is always one token available for every
152152
// reader.
153153
break

semaphore/semaphore_bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"golang.org/x/sync/semaphore"
1313
)
1414

15-
// weighted is an interface matching a subset of *Weighted. It allows
15+
// weighted is an interface matching a subset of *Weighted. It allows
1616
// alternate implementations for testing and benchmarking.
1717
type weighted interface {
1818
Acquire(context.Context, int64) error

semaphore/semaphore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func TestWeightedAcquireCanceled(t *testing.T) {
217217
sem.Release(1)
218218
close(ch)
219219
}()
220-
// Since the context closing happens before enough tokens become available,
220+
// Since the context being closed happens before enough tokens become available,
221221
// this Acquire must fail.
222222
if err := sem.Acquire(ctx, 2); err != context.Canceled {
223223
t.Errorf("Acquire with canceled context returned wrong error: want context.Canceled, got %v", err)

singleflight/singleflight.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import (
1515
"sync"
1616
)
1717

18-
// errGoexit indicates the runtime.Goexit was called in
19-
// the user given function.
18+
// errGoexit indicates runtime.Goexit was called in
19+
// the user-given function.
2020
var errGoexit = errors.New("runtime.Goexit was called")
2121

2222
// A panicError is an arbitrary value recovered from a panic
23-
// with the stack trace during the execution of given function.
23+
// with the stack trace during the execution of the given function.
2424
type panicError struct {
2525
value any
2626
stack []byte
@@ -204,7 +204,7 @@ func (g *Group) doCall(c *call, key string, fn func() (any, error)) {
204204
}
205205
}
206206

207-
// Forget tells the singleflight to forget about a key. Future calls
207+
// Forget tells the singleflight to forget about a key. Future calls
208208
// to Do for this key will call the function rather than waiting for
209209
// an earlier call to complete.
210210
func (g *Group) Forget(key string) {

syncmap/map_reference_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"sync/atomic"
1010
)
1111

12-
// This file contains reference map implementations for unit-tests.
12+
// This file contains reference map implementations for unit tests.
1313

1414
// mapInterface is the interface Map implements.
1515
type mapInterface interface {
@@ -82,7 +82,7 @@ func (m *RWMutexMap) Range(f func(key, value any) (shouldContinue bool)) {
8282
}
8383

8484
// DeepCopyMap is an implementation of mapInterface using a Mutex and
85-
// atomic.Value. It makes deep copies of the map on every write to avoid
85+
// atomic.Value. It makes deep copies of the map on every write to avoid
8686
// acquiring the Mutex in Load.
8787
type DeepCopyMap struct {
8888
mu sync.Mutex

0 commit comments

Comments
 (0)