forked from labring/sealos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request labring#588 from oldthreefeng/develop
use channel to manage goroutine when upgrade nodes
- Loading branch information
Showing
6 changed files
with
68 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package install | ||
|
||
import "sync" | ||
|
||
|
||
type uPool struct { | ||
queue chan int | ||
wg *sync.WaitGroup | ||
} | ||
|
||
func NewPool (size int) *uPool { | ||
if size <= 1 { | ||
size = 1 | ||
} | ||
return &uPool{ | ||
queue: make(chan int, size), | ||
wg: &sync.WaitGroup{}, | ||
} | ||
} | ||
|
||
func (p *uPool) Add(delta int) { | ||
for i := 0; i < delta; i++ { | ||
p.queue <- 1 | ||
} | ||
for i := 0; i > delta; i-- { | ||
<-p.queue | ||
} | ||
p.wg.Add(delta) | ||
} | ||
|
||
func (p *uPool) Done() { | ||
<-p.queue | ||
p.wg.Done() | ||
} | ||
|
||
func (p *uPool) Wait() { | ||
p.wg.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters