Skip to content

Commit

Permalink
chore: reorganize the structure of internal packages
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Feb 19, 2023
1 parent 88d2454 commit 711cad9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/spinlock.go → internal/sync/spinlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 6 additions & 7 deletions internal/spinlock_test.go → internal/sync/spinlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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{} {
Expand Down
4 changes: 2 additions & 2 deletions pool_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{} {
Expand Down

0 comments on commit 711cad9

Please sign in to comment.