From 02eed27ce19ca32582f2b194dbe845af96567de2 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 10 Sep 2017 20:45:22 -0400 Subject: [PATCH] gps: remove unused context.WithCancel Remove unnecessary getLifetimeContext method while I'm here. --- internal/gps/deduce.go | 4 ++-- internal/gps/source.go | 4 ++-- internal/gps/source_manager.go | 27 ++++++++++----------------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/internal/gps/deduce.go b/internal/gps/deduce.go index fe6a64cdb3..9b4e49e08d 100644 --- a/internal/gps/deduce.go +++ b/internal/gps/deduce.go @@ -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 diff --git a/internal/gps/source.go b/internal/gps/source.go index 5f8b34219b..b01d37a8ee 100644 --- a/internal/gps/source.go +++ b/internal/gps/source.go @@ -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() diff --git a/internal/gps/source_manager.go b/internal/gps/source_manager.go index e5110b042e..e24afbf0d0 100644 --- a/internal/gps/source_manager.go +++ b/internal/gps/source_manager.go @@ -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} @@ -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 {