File tree Expand file tree Collapse file tree 2 files changed +4
-10
lines changed Expand file tree Collapse file tree 2 files changed +4
-10
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,6 @@ package wrr
2020import (
2121 "fmt"
2222 "sort"
23- "sync"
2423
2524 "google.golang.org/grpc/internal/grpcrand"
2625)
@@ -38,7 +37,6 @@ func (w *weightedItem) String() string {
3837
3938// randomWRR is a struct that contains weighted items implement weighted random algorithm.
4039type randomWRR struct {
41- mu sync.RWMutex
4240 items []* weightedItem
4341 // Are all item's weights equal
4442 equalWeights bool
@@ -52,8 +50,6 @@ func NewRandom() WRR {
5250var grpcrandInt63n = grpcrand .Int63n
5351
5452func (rw * randomWRR ) Next () (item any ) {
55- rw .mu .RLock ()
56- defer rw .mu .RUnlock ()
5753 if len (rw .items ) == 0 {
5854 return nil
5955 }
@@ -72,8 +68,6 @@ func (rw *randomWRR) Next() (item any) {
7268}
7369
7470func (rw * randomWRR ) Add (item any , weight int64 ) {
75- rw .mu .Lock ()
76- defer rw .mu .Unlock ()
7771 accumulatedWeight := weight
7872 equalWeights := true
7973 if len (rw .items ) > 0 {
Original file line number Diff line number Diff line change @@ -21,12 +21,12 @@ package wrr
2121
2222// WRR defines an interface that implements weighted round robin.
2323type WRR interface {
24- // Add adds an item with weight to the WRR set.
25- //
26- // Add and Next need to be thread safe.
24+ // Add adds an item with weight to the WRR set. Add must be only called
25+ // before any calls to Next.
2726 Add (item any , weight int64 )
2827 // Next returns the next picked item.
2928 //
30- // Add and Next need to be thread safe.
29+ // Next needs to be thread safe. Add may not be called after any call to
30+ // Next.
3131 Next () any
3232}
You can’t perform that action at this time.
0 commit comments