Vendor integration dependencies.
This commit is contained in:
parent
dd5e3fba01
commit
55b57c736b
2451 changed files with 731611 additions and 0 deletions
146
integration/vendor/github.com/containous/traefik/safe/routine.go
generated
vendored
Normal file
146
integration/vendor/github.com/containous/traefik/safe/routine.go
generated
vendored
Normal file
|
@ -0,0 +1,146 @@
|
|||
package safe
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/containous/traefik/log"
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type routine struct {
|
||||
goroutine func(chan bool)
|
||||
stop chan bool
|
||||
}
|
||||
|
||||
type routineCtx func(ctx context.Context)
|
||||
|
||||
// Pool is a pool of go routines
|
||||
type Pool struct {
|
||||
routines []routine
|
||||
routinesCtx []routineCtx
|
||||
waitGroup sync.WaitGroup
|
||||
lock sync.Mutex
|
||||
baseCtx context.Context
|
||||
baseCancel context.CancelFunc
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
// NewPool creates a Pool
|
||||
func NewPool(parentCtx context.Context) *Pool {
|
||||
baseCtx, baseCancel := context.WithCancel(parentCtx)
|
||||
ctx, cancel := context.WithCancel(baseCtx)
|
||||
return &Pool{
|
||||
baseCtx: baseCtx,
|
||||
baseCancel: baseCancel,
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
}
|
||||
}
|
||||
|
||||
// Ctx returns main context
|
||||
func (p *Pool) Ctx() context.Context {
|
||||
return p.baseCtx
|
||||
}
|
||||
|
||||
//AddGoCtx adds a recoverable goroutine with a context without starting it
|
||||
func (p *Pool) AddGoCtx(goroutine routineCtx) {
|
||||
p.lock.Lock()
|
||||
p.routinesCtx = append(p.routinesCtx, goroutine)
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
||||
//GoCtx starts a recoverable goroutine with a context
|
||||
func (p *Pool) GoCtx(goroutine routineCtx) {
|
||||
p.lock.Lock()
|
||||
p.routinesCtx = append(p.routinesCtx, goroutine)
|
||||
p.waitGroup.Add(1)
|
||||
Go(func() {
|
||||
goroutine(p.ctx)
|
||||
p.waitGroup.Done()
|
||||
})
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
||||
// Go starts a recoverable goroutine, and can be stopped with stop chan
|
||||
func (p *Pool) Go(goroutine func(stop chan bool)) {
|
||||
p.lock.Lock()
|
||||
newRoutine := routine{
|
||||
goroutine: goroutine,
|
||||
stop: make(chan bool, 1),
|
||||
}
|
||||
p.routines = append(p.routines, newRoutine)
|
||||
p.waitGroup.Add(1)
|
||||
Go(func() {
|
||||
goroutine(newRoutine.stop)
|
||||
p.waitGroup.Done()
|
||||
})
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
||||
// Stop stops all started routines, waiting for their termination
|
||||
func (p *Pool) Stop() {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
p.cancel()
|
||||
for _, routine := range p.routines {
|
||||
routine.stop <- true
|
||||
}
|
||||
p.waitGroup.Wait()
|
||||
for _, routine := range p.routines {
|
||||
close(routine.stop)
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup releases resources used by the pool, and should be called when the pool will no longer be used
|
||||
func (p *Pool) Cleanup() {
|
||||
p.Stop()
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
p.baseCancel()
|
||||
}
|
||||
|
||||
// Start starts all stopped routines
|
||||
func (p *Pool) Start() {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
p.ctx, p.cancel = context.WithCancel(p.baseCtx)
|
||||
for _, routine := range p.routines {
|
||||
p.waitGroup.Add(1)
|
||||
routine.stop = make(chan bool, 1)
|
||||
Go(func() {
|
||||
routine.goroutine(routine.stop)
|
||||
p.waitGroup.Done()
|
||||
})
|
||||
}
|
||||
|
||||
for _, routine := range p.routinesCtx {
|
||||
p.waitGroup.Add(1)
|
||||
Go(func() {
|
||||
routine(p.ctx)
|
||||
p.waitGroup.Done()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Go starts a recoverable goroutine
|
||||
func Go(goroutine func()) {
|
||||
GoWithRecover(goroutine, defaultRecoverGoroutine)
|
||||
}
|
||||
|
||||
// GoWithRecover starts a recoverable goroutine using given customRecover() function
|
||||
func GoWithRecover(goroutine func(), customRecover func(err interface{})) {
|
||||
go func() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
customRecover(err)
|
||||
}
|
||||
}()
|
||||
goroutine()
|
||||
}()
|
||||
}
|
||||
|
||||
func defaultRecoverGoroutine(err interface{}) {
|
||||
log.Errorf("Error in Go routine: %s", err)
|
||||
debug.PrintStack()
|
||||
}
|
30
integration/vendor/github.com/containous/traefik/safe/safe.go
generated
vendored
Normal file
30
integration/vendor/github.com/containous/traefik/safe/safe.go
generated
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
package safe
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Safe contains a thread-safe value
|
||||
type Safe struct {
|
||||
value interface{}
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
// New create a new Safe instance given a value
|
||||
func New(value interface{}) *Safe {
|
||||
return &Safe{value: value, lock: sync.RWMutex{}}
|
||||
}
|
||||
|
||||
// Get returns the value
|
||||
func (s *Safe) Get() interface{} {
|
||||
s.lock.RLock()
|
||||
defer s.lock.RUnlock()
|
||||
return s.value
|
||||
}
|
||||
|
||||
// Set sets a new value
|
||||
func (s *Safe) Set(value interface{}) {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
s.value = value
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue