Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1153 from tamird/remove-ununused-cancel
Browse files Browse the repository at this point in the history
gps: remove unused context.WithCancel
  • Loading branch information
sdboyer authored Sep 11, 2017
2 parents 28fb6b0 + 02eed27 commit beb6bb1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
4 changes: 2 additions & 2 deletions internal/gps/deduce.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ func newDeductionCoordinator(superv *supervisor) *deductionCoordinator {
// the root path and a list of maybeSources, which can be subsequently used to
// create a handler that will manage the particular source.
func (dc *deductionCoordinator) deduceRootPath(ctx context.Context, path string) (pathDeduction, error) {
if dc.suprvsr.getLifetimeContext().Err() != nil {
return pathDeduction{}, errors.New("deductionCoordinator has been terminated")
if err := dc.suprvsr.ctx.Err(); err != nil {
return pathDeduction{}, err
}

// First, check the rootxt to see if there's a prefix match - if so, we
Expand Down
4 changes: 2 additions & 2 deletions internal/gps/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func newSourceCoordinator(superv *supervisor, deducer deducer, cachedir string,
func (sc *sourceCoordinator) close() {}

func (sc *sourceCoordinator) getSourceGatewayFor(ctx context.Context, id ProjectIdentifier) (*sourceGateway, error) {
if sc.supervisor.getLifetimeContext().Err() != nil {
return nil, errors.New("sourceCoordinator has been terminated")
if err := sc.supervisor.ctx.Err(); err != nil {
return nil, err
}

normalizedName := id.normalizedSource()
Expand Down
27 changes: 10 additions & 17 deletions internal/gps/source_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,21 +593,18 @@ type durCount struct {
}

type supervisor struct {
ctx context.Context
cancelFunc context.CancelFunc
mu sync.Mutex // Guards all maps
cond sync.Cond // Wraps mu so callers can wait until all calls end
running map[callInfo]timeCount
ran map[callType]durCount
ctx context.Context
mu sync.Mutex // Guards all maps
cond sync.Cond // Wraps mu so callers can wait until all calls end
running map[callInfo]timeCount
ran map[callType]durCount
}

func newSupervisor(ctx context.Context) *supervisor {
ctx, cf := context.WithCancel(ctx)
supv := &supervisor{
ctx: ctx,
cancelFunc: cf,
running: make(map[callInfo]timeCount),
ran: make(map[callType]durCount),
ctx: ctx,
running: make(map[callInfo]timeCount),
ran: make(map[callType]durCount),
}

supv.cond = sync.Cond{L: &supv.mu}
Expand Down Expand Up @@ -635,16 +632,12 @@ func (sup *supervisor) do(inctx context.Context, name string, typ callType, f fu
return err
}

func (sup *supervisor) getLifetimeContext() context.Context {
return sup.ctx
}

func (sup *supervisor) start(ci callInfo) (context.Context, error) {
sup.mu.Lock()
defer sup.mu.Unlock()
if sup.ctx.Err() != nil {
if err := sup.ctx.Err(); err != nil {
// We've already been canceled; error out.
return nil, sup.ctx.Err()
return nil, err
}

if existingInfo, has := sup.running[ci]; has {
Expand Down

0 comments on commit beb6bb1

Please sign in to comment.