File tree 2 files changed +4
-10
lines changed
2 files changed +4
-10
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,6 @@ package wrr
20
20
import (
21
21
"fmt"
22
22
"sort"
23
- "sync"
24
23
25
24
"google.golang.org/grpc/internal/grpcrand"
26
25
)
@@ -38,7 +37,6 @@ func (w *weightedItem) String() string {
38
37
39
38
// randomWRR is a struct that contains weighted items implement weighted random algorithm.
40
39
type randomWRR struct {
41
- mu sync.RWMutex
42
40
items []* weightedItem
43
41
// Are all item's weights equal
44
42
equalWeights bool
@@ -52,8 +50,6 @@ func NewRandom() WRR {
52
50
var grpcrandInt63n = grpcrand .Int63n
53
51
54
52
func (rw * randomWRR ) Next () (item any ) {
55
- rw .mu .RLock ()
56
- defer rw .mu .RUnlock ()
57
53
if len (rw .items ) == 0 {
58
54
return nil
59
55
}
@@ -72,8 +68,6 @@ func (rw *randomWRR) Next() (item any) {
72
68
}
73
69
74
70
func (rw * randomWRR ) Add (item any , weight int64 ) {
75
- rw .mu .Lock ()
76
- defer rw .mu .Unlock ()
77
71
accumulatedWeight := weight
78
72
equalWeights := true
79
73
if len (rw .items ) > 0 {
Original file line number Diff line number Diff line change @@ -21,12 +21,12 @@ package wrr
21
21
22
22
// WRR defines an interface that implements weighted round robin.
23
23
type 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.
27
26
Add (item any , weight int64 )
28
27
// Next returns the next picked item.
29
28
//
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.
31
31
Next () any
32
32
}
You can’t perform that action at this time.
0 commit comments