File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ type ServerNode struct {
99
99
params * ServerParams
100
100
sumCost uint64 // sum of req costs sent to this server
101
101
pending map [uint64 ]uint64 // value = sumCost after sending the given req
102
- lock sync.Mutex
102
+ lock sync.RWMutex
103
103
}
104
104
105
105
func NewServerNode (params * ServerParams ) * ServerNode {
@@ -135,8 +135,8 @@ func (peer *ServerNode) canSend(maxCost uint64) uint64 {
135
135
}
136
136
137
137
func (peer * ServerNode ) CanSend (maxCost uint64 ) uint64 {
138
- peer .lock .Lock ()
139
- defer peer .lock .Unlock ()
138
+ peer .lock .RLock ()
139
+ defer peer .lock .RUnlock ()
140
140
141
141
return peer .canSend (maxCost )
142
142
}
@@ -148,7 +148,10 @@ func (peer *ServerNode) SendRequest(reqID, maxCost uint64) {
148
148
149
149
peer .recalcBLE (getTime ())
150
150
for peer .bufEstimate < maxCost {
151
- time .Sleep (time .Duration (peer .canSend (maxCost )))
151
+ wait := time .Duration (peer .canSend (maxCost ))
152
+ peer .lock .Unlock ()
153
+ time .Sleep (wait )
154
+ peer .lock .Lock ()
152
155
peer .recalcBLE (getTime ())
153
156
}
154
157
peer .bufEstimate -= maxCost
You can’t perform that action at this time.
0 commit comments