mirror of https://github.com/knative/pkg.git
Final sync/atomic removals (#1794)
There's one sync/atomic.Value, but value already is a wholesome type, so no need to change that one.
This commit is contained in:
parent
49103e3170
commit
ea1fd5a413
|
|
@ -20,9 +20,10 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.uber.org/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParallelismNoErrors(t *testing.T) {
|
func TestParallelismNoErrors(t *testing.T) {
|
||||||
|
|
@ -50,7 +51,7 @@ func TestParallelismNoErrors(t *testing.T) {
|
||||||
// m guards max.
|
// m guards max.
|
||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
max int32
|
max int32
|
||||||
active int32
|
active atomic.Int32
|
||||||
)
|
)
|
||||||
|
|
||||||
// Use our own waitgroup to ensure that the work
|
// Use our own waitgroup to ensure that the work
|
||||||
|
|
@ -60,14 +61,14 @@ func TestParallelismNoErrors(t *testing.T) {
|
||||||
|
|
||||||
worker := func() error {
|
worker := func() error {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
na := atomic.AddInt32(&active, 1)
|
active.Inc()
|
||||||
defer atomic.AddInt32(&active, -1)
|
defer active.Dec()
|
||||||
|
|
||||||
func() {
|
func() {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
if max < na {
|
if v := active.Load(); max < v {
|
||||||
max = na
|
max = v
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
@ -129,7 +130,7 @@ func TestParallelismWithErrors(t *testing.T) {
|
||||||
// m guards max.
|
// m guards max.
|
||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
max int32
|
max int32
|
||||||
active int32
|
active atomic.Int32
|
||||||
)
|
)
|
||||||
|
|
||||||
// Use our own waitgroup to ensure that the work
|
// Use our own waitgroup to ensure that the work
|
||||||
|
|
@ -145,14 +146,14 @@ func TestParallelismWithErrors(t *testing.T) {
|
||||||
workerFactory := func(err error) func() error {
|
workerFactory := func(err error) func() error {
|
||||||
return func() error {
|
return func() error {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
na := atomic.AddInt32(&active, 1)
|
active.Inc()
|
||||||
defer atomic.AddInt32(&active, -1)
|
defer active.Dec()
|
||||||
|
|
||||||
func() {
|
func() {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
if max < na {
|
if v := active.Load(); max < v {
|
||||||
max = na
|
max = v
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue