File: attach_context.go

package info (click to toggle)
docker.io 26.1.5%2Bdfsg1-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 68,576 kB
  • sloc: sh: 5,748; makefile: 912; ansic: 664; asm: 228; python: 162
file content (35 lines) | stat: -rw-r--r-- 732 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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()
}