mirror of https://github.com/panjf2000/ants.git
chore: reorganize the structure of internal packages
This commit is contained in:
parent
88d2454bbb
commit
711cad9624
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by an MIT-style
|
// Use of this source code is governed by an MIT-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package internal
|
package sync
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
"runtime"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by an MIT-style
|
// Use of this source code is governed by an MIT-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package internal
|
package sync
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -14,12 +14,11 @@ import (
|
||||||
/*
|
/*
|
||||||
Benchmark result for three types of locks:
|
Benchmark result for three types of locks:
|
||||||
goos: darwin
|
goos: darwin
|
||||||
goarch: amd64
|
goarch: arm64
|
||||||
pkg: github.com/panjf2000/ants/v2/internal
|
pkg: github.com/panjf2000/ants/v2/internal/sync
|
||||||
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
|
BenchmarkMutex-10 10452573 111.1 ns/op 0 B/op 0 allocs/op
|
||||||
BenchmarkMutex-12 20549502 71.84 ns/op 0 B/op 0 allocs/op
|
BenchmarkSpinLock-10 58953211 18.01 ns/op 0 B/op 0 allocs/op
|
||||||
BenchmarkSpinLock-12 58629697 20.02 ns/op 0 B/op 0 allocs/op
|
BenchmarkBackOffSpinLock-10 100000000 10.81 ns/op 0 B/op 0 allocs/op
|
||||||
BenchmarkBackOffSpinLock-12 72523454 15.74 ns/op 0 B/op 0 allocs/op
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
type originSpinLock uint32
|
type originSpinLock uint32
|
4
pool.go
4
pool.go
|
@ -28,7 +28,7 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"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.
|
// 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{
|
p := &Pool{
|
||||||
capacity: int32(size),
|
capacity: int32(size),
|
||||||
lock: internal.NewSpinLock(),
|
lock: syncx.NewSpinLock(),
|
||||||
options: opts,
|
options: opts,
|
||||||
}
|
}
|
||||||
p.workerCache.New = func() interface{} {
|
p.workerCache.New = func() interface{} {
|
||||||
|
|
|
@ -28,7 +28,7 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/panjf2000/ants/v2/internal"
|
syncx "github.com/panjf2000/ants/v2/internal/sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PoolWithFunc accepts the tasks from client,
|
// PoolWithFunc accepts the tasks from client,
|
||||||
|
@ -208,7 +208,7 @@ func NewPoolWithFunc(size int, pf func(interface{}), options ...Option) (*PoolWi
|
||||||
p := &PoolWithFunc{
|
p := &PoolWithFunc{
|
||||||
capacity: int32(size),
|
capacity: int32(size),
|
||||||
poolFunc: pf,
|
poolFunc: pf,
|
||||||
lock: internal.NewSpinLock(),
|
lock: syncx.NewSpinLock(),
|
||||||
options: opts,
|
options: opts,
|
||||||
}
|
}
|
||||||
p.workerCache.New = func() interface{} {
|
p.workerCache.New = func() interface{} {
|
||||||
|
|
Loading…
Reference in New Issue