@@ -119,26 +119,29 @@ func (l *LifoBlockingListener) unblock() {
119
119
l .limiter .mu .Lock ()
120
120
defer l .limiter .mu .Unlock ()
121
121
122
- if l .limiter .backlog .len () > 0 {
123
-
124
- evict , nextEvent := l .limiter .backlog .peek ()
125
- listener , ok := l .limiter .delegate .Acquire (nextEvent .ctx )
126
-
127
- if ok && listener != nil {
128
- // We successfully acquired a listener from the
129
- // delegate. Now we can evict the element from
130
- // the queue
131
- evict ()
132
-
133
- // If the listener is not accepted due to subtle timings
134
- // between setListener being invoked and the element
135
- // expiration elapsing we need to be sure to release it.
136
- if accepted := nextEvent .setListener (listener ); ! accepted {
137
- listener .OnIgnore ()
138
- }
122
+ evict , nextEvent := l .limiter .backlog .peek ()
123
+
124
+ // The queue is empty
125
+ if nextEvent == nil {
126
+ return
127
+ }
128
+
129
+ listener , ok := l .limiter .delegate .Acquire (nextEvent .ctx )
130
+
131
+ if ok && listener != nil {
132
+ // We successfully acquired a listener from the
133
+ // delegate. Now we can evict the element from
134
+ // the queue
135
+ evict ()
136
+
137
+ // If the listener is not accepted due to subtle timings
138
+ // between setListener being invoked and the element
139
+ // expiration elapsing we need to be sure to release it.
140
+ if accepted := nextEvent .setListener (listener ); ! accepted {
141
+ listener .OnIgnore ()
139
142
}
140
- // otherwise: still can't acquire the limit. unblock will be called again next time the limit is released.
141
143
}
144
+ // otherwise: still can't acquire the limit. unblock will be called again next time the limit is released.
142
145
}
143
146
144
147
// OnDropped is called to indicate the request failed and was dropped due to being rejected by an external limit or
@@ -175,7 +178,6 @@ type LifoBlockingLimiter struct {
175
178
maxBacklogTimeout time.Duration
176
179
177
180
backlog lifoQueue
178
- c * sync.Cond
179
181
mu sync.RWMutex
180
182
}
181
183
@@ -191,13 +193,11 @@ func NewLifoBlockingLimiter(
191
193
if maxBacklogTimeout == 0 {
192
194
maxBacklogTimeout = time .Millisecond * 1000
193
195
}
194
- mu := sync.Mutex {}
195
196
return & LifoBlockingLimiter {
196
197
delegate : delegate ,
197
198
maxBacklogSize : uint64 (maxBacklogSize ),
198
199
maxBacklogTimeout : maxBacklogTimeout ,
199
200
backlog : lifoQueue {},
200
- c : sync .NewCond (& mu ),
201
201
}
202
202
}
203
203
0 commit comments