mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fn: resource and slot cancel and broadcast improvements (#696)
* fn: resource and slot cancel and broadcast improvements *) Context argument does not wake up the waiters correctly upon cancellation/timeout. *) Avoid unnecessary broadcasts in slot and resource. * fn: limit scope of context in resource/slot calls in agent
This commit is contained in:
@@ -112,25 +112,29 @@ func (a *slotQueue) ejectSlot(s *slotToken) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (a *slotQueue) startDequeuer() (chan *slotToken, context.CancelFunc) {
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
myCancel := func() {
|
||||
cancel()
|
||||
a.cond.L.Lock()
|
||||
a.cond.Broadcast()
|
||||
a.cond.L.Unlock()
|
||||
}
|
||||
func (a *slotQueue) startDequeuer(ctx context.Context) chan *slotToken {
|
||||
|
||||
isWaiting := false
|
||||
output := make(chan *slotToken)
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
a.cond.L.Lock()
|
||||
if isWaiting {
|
||||
a.cond.Broadcast()
|
||||
}
|
||||
a.cond.L.Unlock()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
a.cond.L.Lock()
|
||||
|
||||
isWaiting = true
|
||||
for len(a.slots) <= 0 && (ctx.Err() == nil) {
|
||||
a.cond.Wait()
|
||||
}
|
||||
isWaiting = false
|
||||
|
||||
if ctx.Err() != nil {
|
||||
a.cond.L.Unlock()
|
||||
@@ -154,7 +158,7 @@ func (a *slotQueue) startDequeuer() (chan *slotToken, context.CancelFunc) {
|
||||
}
|
||||
}()
|
||||
|
||||
return output, myCancel
|
||||
return output
|
||||
}
|
||||
|
||||
func (a *slotQueue) queueSlot(slot Slot) *slotToken {
|
||||
|
||||
Reference in New Issue
Block a user