Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
d11a9973
Unverified
Commit
d11a9973
authored
Jun 07, 2017
by
Mikhail Mazurskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve Start functions
parent
d7896159
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
13 deletions
+35
-13
wait.go
staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go
+28
-6
controller.go
staging/src/k8s.io/client-go/tools/cache/controller.go
+1
-1
shared_informer.go
staging/src/k8s.io/client-go/tools/cache/shared_informer.go
+6
-6
No files found.
staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go
View file @
d11a9973
...
...
@@ -17,9 +17,9 @@ limitations under the License.
package
wait
import
(
"context"
"errors"
"math/rand"
"sync"
"time"
"k8s.io/apimachinery/pkg/util/runtime"
...
...
@@ -37,12 +37,34 @@ var ForeverTestTimeout = time.Second * 30
// NeverStop may be passed to Until to make it never stop.
var
NeverStop
<-
chan
struct
{}
=
make
(
chan
struct
{})
// StartUntil starts f in a new goroutine and calls done once f has finished.
func
StartUntil
(
stopCh
<-
chan
struct
{},
wg
*
sync
.
WaitGroup
,
f
func
(
stopCh
<-
chan
struct
{}))
{
wg
.
Add
(
1
)
go
func
()
{
defer
wg
.
Done
()
// Group is an interface to decouple code from sync.WaitGroup.
type
Group
interface
{
Add
(
delta
int
)
Done
()
}
// StartWithChannelWithinGroup adds 1 to the group, starts f in a new goroutine and calls g.Done once f has finished.
// stopCh is passed to f as an argument. f should stop when stopCh is available.
func
StartWithChannelWithinGroup
(
stopCh
<-
chan
struct
{},
g
Group
,
f
func
(
stopCh
<-
chan
struct
{}))
{
StartWithinGroup
(
g
,
func
()
{
f
(
stopCh
)
})
}
// StartWithContextWithinGroup adds 1 to the group, starts f in a new goroutine and calls g.Done once f has finished.
// ctx is passed to f as an argument. f should stop when ctx.Done() is available.
func
StartWithContextWithinGroup
(
ctx
context
.
Context
,
g
Group
,
f
func
(
context
.
Context
))
{
StartWithinGroup
(
g
,
func
()
{
f
(
ctx
)
})
}
// StartWithinGroup adds 1 to the group, starts f in a new goroutine and calls g.Done once f has finished.
func
StartWithinGroup
(
g
Group
,
f
func
())
{
g
.
Add
(
1
)
go
func
()
{
defer
g
.
Done
()
f
()
}()
}
...
...
staging/src/k8s.io/client-go/tools/cache/controller.go
View file @
d11a9973
...
...
@@ -119,7 +119,7 @@ func (c *controller) Run(stopCh <-chan struct{}) {
var
wg
sync
.
WaitGroup
defer
wg
.
Wait
()
wait
.
Start
Until
(
stopCh
,
&
wg
,
r
.
Run
)
wait
.
Start
WithChannelWithinGroup
(
stopCh
,
&
wg
,
r
.
Run
)
wait
.
Until
(
c
.
processLoop
,
time
.
Second
,
stopCh
)
}
...
...
staging/src/k8s.io/client-go/tools/cache/shared_informer.go
View file @
d11a9973
...
...
@@ -211,8 +211,8 @@ func (s *sharedIndexInformer) Run(stopCh <-chan struct{}) {
defer
s
.
wg
.
Wait
()
wait
.
Start
Until
(
stopCh
,
&
s
.
wg
,
s
.
cacheMutationDetector
.
Run
)
wait
.
Start
Until
(
stopCh
,
&
s
.
wg
,
s
.
processor
.
run
)
wait
.
Start
WithChannelWithinGroup
(
stopCh
,
&
s
.
wg
,
s
.
cacheMutationDetector
.
Run
)
wait
.
Start
WithChannelWithinGroup
(
stopCh
,
&
s
.
wg
,
s
.
processor
.
run
)
s
.
controller
.
Run
(
stopCh
)
}
...
...
@@ -327,8 +327,8 @@ func (s *sharedIndexInformer) AddEventHandlerWithResyncPeriod(handler ResourceEv
s
.
processor
.
addListener
(
listener
)
wait
.
Start
Until
(
s
.
stopCh
,
&
s
.
wg
,
listener
.
run
)
wait
.
Start
Until
(
s
.
stopCh
,
&
s
.
wg
,
listener
.
pop
)
wait
.
Start
WithChannelWithinGroup
(
s
.
stopCh
,
&
s
.
wg
,
listener
.
run
)
wait
.
Start
WithChannelWithinGroup
(
s
.
stopCh
,
&
s
.
wg
,
listener
.
pop
)
items
:=
s
.
indexer
.
List
()
for
i
:=
range
items
{
...
...
@@ -403,8 +403,8 @@ func (p *sharedProcessor) run(stopCh <-chan struct{}) {
p
.
listenersLock
.
RLock
()
defer
p
.
listenersLock
.
RUnlock
()
for
_
,
listener
:=
range
p
.
listeners
{
wait
.
Start
Until
(
stopCh
,
&
wg
,
listener
.
run
)
wait
.
Start
Until
(
stopCh
,
&
wg
,
listener
.
pop
)
wait
.
Start
WithChannelWithinGroup
(
stopCh
,
&
wg
,
listener
.
run
)
wait
.
Start
WithChannelWithinGroup
(
stopCh
,
&
wg
,
listener
.
pop
)
}
}()
wg
.
Wait
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment