From 711cad96247f796614bca29f0bcfb3f49b6d95bd Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sun, 19 Feb 2023 22:46:33 +0800 Subject: [PATCH] chore: reorganize the structure of internal packages --- internal/{ => sync}/spinlock.go | 2 +- internal/{ => sync}/spinlock_test.go | 13 ++++++------- pool.go | 4 ++-- pool_func.go | 4 ++-- 4 files changed, 11 insertions(+), 12 deletions(-) rename internal/{ => sync}/spinlock.go (97%) rename internal/{ => sync}/spinlock_test.go (75%) 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{} {