moby/container/attach_context.go
Sebastiaan van Stijn 4adc40ac40
fix duplicate words (dupwords)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-03-07 10:57:03 +01:00

35 lines
732 B
Go

package container
import (
"context"
"sync"
)
// attachContext is the context used for attach calls.
type attachContext struct {
mu sync.Mutex
ctx context.Context
cancelFunc context.CancelFunc
}
// init returns the context for attach calls. It creates a new context
// if no context is created yet.
func (ac *attachContext) init() context.Context {
ac.mu.Lock()
defer ac.mu.Unlock()
if ac.ctx == nil {
ac.ctx, ac.cancelFunc = context.WithCancel(context.Background())
}
return ac.ctx
}
// cancelFunc cancels the attachContext. All attach calls should detach
// after this call.
func (ac *attachContext) cancel() {
ac.mu.Lock()
if ac.ctx != nil {
ac.cancelFunc()
ac.ctx = nil
}
ac.mu.Unlock()
}