mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
make lifecycle signal thread safe
This commit is contained in:
parent
38746752af
commit
d3e2e9ede2
@ -16,6 +16,10 @@ limitations under the License.
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
/*
|
||||
We make an attempt here to identify the events that take place during
|
||||
lifecycle of the apiserver.
|
||||
@ -143,22 +147,21 @@ func newLifecycleSignals() lifecycleSignals {
|
||||
func newNamedChannelWrapper(name string) lifecycleSignal {
|
||||
return &namedChannelWrapper{
|
||||
name: name,
|
||||
once: sync.Once{},
|
||||
ch: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
type namedChannelWrapper struct {
|
||||
name string
|
||||
once sync.Once
|
||||
ch chan struct{}
|
||||
}
|
||||
|
||||
func (e *namedChannelWrapper) Signal() {
|
||||
select {
|
||||
case <-e.ch:
|
||||
// already closed, don't close again.
|
||||
default:
|
||||
e.once.Do(func() {
|
||||
close(e.ch)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (e *namedChannelWrapper) Signaled() <-chan struct{} {
|
||||
|
Loading…
Reference in New Issue
Block a user