Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions util/execpool/backlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,19 @@ package execpool
import (
"context"
"sync"

"github.com/algorand/go-deadlock"
)

// A backlog for an execution pool. The typical usage of this is to
// create non-blocking queue which would get executed once the execution pool is ready to accept new
// tasks.
type backlog struct {
mu deadlock.Mutex
pool ExecutionPool
wg sync.WaitGroup
buffer chan backlogItemTask
ctx context.Context
ctxCancel context.CancelFunc
owner interface{}
priority Priority
quit bool
}

type backlogItemTask struct {
Expand Down Expand Up @@ -82,25 +78,11 @@ func (b *backlog) GetParallelism() int {

// IsFull test to see if the input buffer is full.
func (b *backlog) IsFull() bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method actually called anywhere?

b.mu.Lock()
defer b.mu.Unlock()
return len(b.buffer) == cap(b.buffer)
}

// Enqueue enqueues a single task into the backlog
func (b *backlog) Enqueue(enqueueCtx context.Context, t ExecFunc, arg interface{}, priority Priority, out chan interface{}) error {
b.mu.Lock()
defer b.mu.Unlock()
if b.quit {
select {
case <-enqueueCtx.Done():
return enqueueCtx.Err()
case <-b.ctx.Done():
return b.ctx.Err()
default:
return nil
}
}
select {
case b.buffer <- backlogItemTask{
enqueuedTask: enqueuedTask{
Expand All @@ -120,18 +102,6 @@ func (b *backlog) Enqueue(enqueueCtx context.Context, t ExecFunc, arg interface{

// Enqueue enqueues a single task into the backlog
func (b *backlog) EnqueueBacklog(enqueueCtx context.Context, t ExecFunc, arg interface{}, out chan interface{}) error {
b.mu.Lock()
defer b.mu.Unlock()
if b.quit {
select {
case <-enqueueCtx.Done():
return enqueueCtx.Err()
case <-b.ctx.Done():
return b.ctx.Err()
default:
return nil
}
}
select {
case b.buffer <- backlogItemTask{
enqueuedTask: enqueuedTask{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

github won't let me comment on lines not in this PR, but it looks like this doesn't totally undo the changes done to this file in #700 b/c of the case <-b.ctx.Done() case

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(in both Enqueue and EnqueueBacklog)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may actually be the minimum change needed to fix things. I think without this Enqueue() and EnqueueBacklog() will panic if Shutdown() has been called because they try to send on a closed b.buffer . The internal Context b.ctx is the only thing that can signal that Enqueue shuoldn't actually try to append to b.buffer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a race between context cancellation and closing the buffer?

Expand All @@ -151,9 +121,6 @@ func (b *backlog) EnqueueBacklog(enqueueCtx context.Context, t ExecFunc, arg int

// Shutdown shuts down the backlog.
func (b *backlog) Shutdown() {
b.mu.Lock()
defer b.mu.Unlock()
b.quit = true
b.ctxCancel()
close(b.buffer)
b.wg.Wait()
Expand Down