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
e853f3e7
Commit
e853f3e7
authored
Nov 13, 2017
by
hzxuzhonghu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug: without Unlock in error case, and remove unrelated test cases
parent
bfe581d9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
120 deletions
+2
-120
waitgroup.go
...g/src/k8s.io/apimachinery/pkg/util/waitgroup/waitgroup.go
+2
-2
waitgroup_test.go
.../k8s.io/apimachinery/pkg/util/waitgroup/waitgroup_test.go
+0
-118
No files found.
staging/src/k8s.io/apimachinery/pkg/util/waitgroup/waitgroup.go
View file @
e853f3e7
...
...
@@ -35,10 +35,10 @@ type SafeWaitGroup struct {
// which prevent unsafe Add.
func
(
wg
*
SafeWaitGroup
)
Add
(
delta
int
)
error
{
wg
.
mu
.
RLock
()
defer
wg
.
mu
.
RUnlock
()
if
wg
.
wait
&&
delta
>
0
{
return
fmt
.
Errorf
(
"
A
dd with postive delta after Wait is forbidden"
)
return
fmt
.
Errorf
(
"
a
dd with postive delta after Wait is forbidden"
)
}
wg
.
mu
.
RUnlock
()
wg
.
wg
.
Add
(
delta
)
return
nil
}
...
...
staging/src/k8s.io/apimachinery/pkg/util/waitgroup/waitgroup_test.go
View file @
e853f3e7
...
...
@@ -18,8 +18,6 @@ limitations under the License.
package
waitgroup
import
(
"runtime"
"sync/atomic"
"testing"
)
...
...
@@ -51,20 +49,6 @@ func TestWaitGroup(t *testing.T) {
}
}
func
TestWaitGroupNegativeCounter
(
t
*
testing
.
T
)
{
defer
func
()
{
err
:=
recover
()
if
err
!=
"sync: negative WaitGroup counter"
{
t
.
Fatalf
(
"Unexpected panic: %#v"
,
err
)
}
}()
wg
:=
&
SafeWaitGroup
{}
wg
.
Add
(
1
)
wg
.
Done
()
wg
.
Done
()
t
.
Fatal
(
"Should panic"
)
}
func
TestWaitGroupAddFail
(
t
*
testing
.
T
)
{
wg
:=
&
SafeWaitGroup
{}
wg
.
Add
(
1
)
...
...
@@ -74,105 +58,3 @@ func TestWaitGroupAddFail(t *testing.T) {
t
.
Errorf
(
"Should return error when add positive after Wait"
)
}
}
func
BenchmarkWaitGroupUncontended
(
b
*
testing
.
B
)
{
type
PaddedWaitGroup
struct
{
SafeWaitGroup
pad
[
128
]
uint8
}
const
CallsPerSched
=
1000
procs
:=
runtime
.
GOMAXPROCS
(
-
1
)
N
:=
int32
(
b
.
N
/
CallsPerSched
)
c
:=
make
(
chan
bool
,
procs
)
for
p
:=
0
;
p
<
procs
;
p
++
{
go
func
()
{
var
wg
PaddedWaitGroup
for
atomic
.
AddInt32
(
&
N
,
-
1
)
>=
0
{
runtime
.
Gosched
()
for
g
:=
0
;
g
<
CallsPerSched
;
g
++
{
wg
.
Add
(
1
)
wg
.
Done
()
}
}
c
<-
true
}()
}
for
p
:=
0
;
p
<
procs
;
p
++
{
<-
c
}
}
func
benchmarkWaitGroupAddDone
(
b
*
testing
.
B
,
localWork
int
)
{
const
CallsPerSched
=
1000
procs
:=
runtime
.
GOMAXPROCS
(
-
1
)
N
:=
int32
(
b
.
N
/
CallsPerSched
)
c
:=
make
(
chan
bool
,
procs
)
var
wg
SafeWaitGroup
for
p
:=
0
;
p
<
procs
;
p
++
{
go
func
()
{
foo
:=
0
for
atomic
.
AddInt32
(
&
N
,
-
1
)
>=
0
{
runtime
.
Gosched
()
for
g
:=
0
;
g
<
CallsPerSched
;
g
++
{
wg
.
Add
(
1
)
for
i
:=
0
;
i
<
localWork
;
i
++
{
foo
*=
2
foo
/=
2
}
wg
.
Done
()
}
}
c
<-
foo
==
42
}()
}
for
p
:=
0
;
p
<
procs
;
p
++
{
<-
c
}
}
func
BenchmarkWaitGroupAddDone
(
b
*
testing
.
B
)
{
benchmarkWaitGroupAddDone
(
b
,
0
)
}
func
BenchmarkWaitGroupAddDoneWork
(
b
*
testing
.
B
)
{
benchmarkWaitGroupAddDone
(
b
,
100
)
}
func
benchmarkWaitGroupWait
(
b
*
testing
.
B
,
localWork
int
)
{
const
CallsPerSched
=
1000
procs
:=
runtime
.
GOMAXPROCS
(
-
1
)
N
:=
int32
(
b
.
N
/
CallsPerSched
)
c
:=
make
(
chan
bool
,
procs
)
var
wg
SafeWaitGroup
wg
.
Add
(
procs
)
for
p
:=
0
;
p
<
procs
;
p
++
{
go
wg
.
Done
()
}
for
p
:=
0
;
p
<
procs
;
p
++
{
go
func
()
{
foo
:=
0
for
atomic
.
AddInt32
(
&
N
,
-
1
)
>=
0
{
runtime
.
Gosched
()
for
g
:=
0
;
g
<
CallsPerSched
;
g
++
{
wg
.
Wait
()
for
i
:=
0
;
i
<
localWork
;
i
++
{
foo
*=
2
foo
/=
2
}
}
}
c
<-
foo
==
42
}()
}
for
p
:=
0
;
p
<
procs
;
p
++
{
<-
c
}
}
func
BenchmarkWaitGroupWait
(
b
*
testing
.
B
)
{
benchmarkWaitGroupWait
(
b
,
0
)
}
func
BenchmarkWaitGroupWaitWork
(
b
*
testing
.
B
)
{
benchmarkWaitGroupWait
(
b
,
100
)
}
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