Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/util/goroutinemap: apply idiomatic Go cleanups #29598

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions pkg/util/goroutinemap/goroutinemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ const (
// that GoRoutineMap will refuse to allow another operation to start with
// the same operation name (if exponentialBackOffOnError is enabled). Each
// successive error results in a wait 2x times the previous.
initialDurationBeforeRetry time.Duration = 500 * time.Millisecond
initialDurationBeforeRetry = 500 * time.Millisecond

// maxDurationBeforeRetry is the maximum amount of time that
// durationBeforeRetry will grow to due to exponential backoff.
maxDurationBeforeRetry time.Duration = 2 * time.Minute
maxDurationBeforeRetry = 2 * time.Minute
)

// GoRoutineMap defines the supported set of operations.
Expand All @@ -65,18 +65,17 @@ func NewGoRoutineMap(exponentialBackOffOnError bool) GoRoutineMap {
g := &goRoutineMap{
operations: make(map[string]operation),
exponentialBackOffOnError: exponentialBackOffOnError,
lock: &sync.Mutex{},
}

g.cond = sync.NewCond(g.lock)
g.cond = sync.NewCond(&g.lock)
return g
}

type goRoutineMap struct {
operations map[string]operation
exponentialBackOffOnError bool
cond *sync.Cond
lock *sync.Mutex
lock sync.Mutex
}

type operation struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,16 @@ func NewNestedPendingOperations(exponentialBackOffOnError bool) NestedPendingOpe
g := &nestedPendingOperations{
operations: []operation{},
exponentialBackOffOnError: exponentialBackOffOnError,
lock: &sync.Mutex{},
}
g.cond = sync.NewCond(g.lock)
g.cond = sync.NewCond(&g.lock)
return g
}

type nestedPendingOperations struct {
operations []operation
exponentialBackOffOnError bool
cond *sync.Cond
lock *sync.Mutex
lock sync.Mutex
}

type operation struct {
Expand Down