diff --git a/internal/spinlock.go b/internal/sync/spinlock.go similarity index 97% rename from internal/spinlock.go rename to internal/sync/spinlock.go index 6261f74..3f985f4 100644 --- a/internal/spinlock.go +++ b/internal/sync/spinlock.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -package internal +package sync import ( "runtime" diff --git a/internal/spinlock_test.go b/internal/sync/spinlock_test.go similarity index 75% rename from internal/spinlock_test.go rename to internal/sync/spinlock_test.go index cabf5e7..fa20401 100644 --- a/internal/spinlock_test.go +++ b/internal/sync/spinlock_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -package internal +package sync import ( "runtime" @@ -14,12 +14,11 @@ import ( /* Benchmark result for three types of locks: goos: darwin - goarch: amd64 - pkg: github.com/panjf2000/ants/v2/internal - cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz - BenchmarkMutex-12 20549502 71.84 ns/op 0 B/op 0 allocs/op - BenchmarkSpinLock-12 58629697 20.02 ns/op 0 B/op 0 allocs/op - BenchmarkBackOffSpinLock-12 72523454 15.74 ns/op 0 B/op 0 allocs/op + goarch: arm64 + pkg: github.com/panjf2000/ants/v2/internal/sync + BenchmarkMutex-10 10452573 111.1 ns/op 0 B/op 0 allocs/op + BenchmarkSpinLock-10 58953211 18.01 ns/op 0 B/op 0 allocs/op + BenchmarkBackOffSpinLock-10 100000000 10.81 ns/op 0 B/op 0 allocs/op */ type originSpinLock uint32 diff --git a/pool.go b/pool.go index 7b2bd36..d281a1c 100644 --- a/pool.go +++ b/pool.go @@ -28,7 +28,7 @@ import ( "sync/atomic" "time" - "github.com/panjf2000/ants/v2/internal" + syncx "github.com/panjf2000/ants/v2/internal/sync" ) // Pool accepts the tasks from client, it limits the total of goroutines to a given number by recycling goroutines. @@ -180,7 +180,7 @@ func NewPool(size int, options ...Option) (*Pool, error) { p := &Pool{ capacity: int32(size), - lock: internal.NewSpinLock(), + lock: syncx.NewSpinLock(), options: opts, } p.workerCache.New = func() interface{} { diff --git a/pool_func.go b/pool_func.go index 8c48b7d..40227db 100644 --- a/pool_func.go +++ b/pool_func.go @@ -28,7 +28,7 @@ import ( "sync/atomic" "time" - "github.com/panjf2000/ants/v2/internal" + syncx "github.com/panjf2000/ants/v2/internal/sync" ) // PoolWithFunc accepts the tasks from client, @@ -208,7 +208,7 @@ func NewPoolWithFunc(size int, pf func(interface{}), options ...Option) (*PoolWi p := &PoolWithFunc{ capacity: int32(size), poolFunc: pf, - lock: internal.NewSpinLock(), + lock: syncx.NewSpinLock(), options: opts, } p.workerCache.New = func() interface{} {