mirror of
https://github.com/panjf2000/ants.git
synced 2025-12-16 09:51:02 +00:00
feat: export the internal package sync (#349)
This commit is contained in:
parent
d4218913f7
commit
4f33c6ef27
13
.github/release-drafter.yml
vendored
13
.github/release-drafter.yml
vendored
@ -44,7 +44,7 @@ autolabeler:
|
|||||||
title:
|
title:
|
||||||
- /fix/i
|
- /fix/i
|
||||||
- /bug/i
|
- /bug/i
|
||||||
- /patch/i
|
- /resolve/i
|
||||||
- label: docs
|
- label: docs
|
||||||
files:
|
files:
|
||||||
- '*.md'
|
- '*.md'
|
||||||
@ -60,6 +60,15 @@ autolabeler:
|
|||||||
- /update/i
|
- /update/i
|
||||||
- /remove/i
|
- /remove/i
|
||||||
- /delete/i
|
- /delete/i
|
||||||
|
- label: optimization
|
||||||
|
title:
|
||||||
|
- /opt:/i
|
||||||
|
- /refactor/i
|
||||||
|
- /optimize/i
|
||||||
|
- /improve/i
|
||||||
|
- /update/i
|
||||||
|
- /remove/i
|
||||||
|
- /delete/i
|
||||||
- label: new feature
|
- label: new feature
|
||||||
title:
|
title:
|
||||||
- /feat:/i
|
- /feat:/i
|
||||||
@ -75,7 +84,7 @@ autolabeler:
|
|||||||
- label: chores
|
- label: chores
|
||||||
title:
|
title:
|
||||||
- /chore/i
|
- /chore/i
|
||||||
- /\bmisc\b/i
|
- /misc/i
|
||||||
- /cleanup/i
|
- /cleanup/i
|
||||||
- /clean up/i
|
- /clean up/i
|
||||||
- label: major
|
- label: major
|
||||||
|
|||||||
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -87,7 +87,7 @@ jobs:
|
|||||||
run: go test -v -race -coverprofile="codecov.report" -covermode=atomic
|
run: go test -v -race -coverprofile="codecov.report" -covermode=atomic
|
||||||
|
|
||||||
- name: Upload code coverage report to Codecov
|
- name: Upload code coverage report to Codecov
|
||||||
uses: codecov/codecov-action@v4
|
uses: codecov/codecov-action@v5
|
||||||
with:
|
with:
|
||||||
file: ./codecov.report
|
file: ./codecov.report
|
||||||
flags: unittests
|
flags: unittests
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
<a title="Release" target="_blank" href="https://github.com/panjf2000/ants/releases"><img src="https://img.shields.io/github/v/release/panjf2000/ants.svg?color=161823&style=flat-square&logo=smartthings" /></a>
|
<a title="Release" target="_blank" href="https://github.com/panjf2000/ants/releases"><img src="https://img.shields.io/github/v/release/panjf2000/ants.svg?color=161823&style=flat-square&logo=smartthings" /></a>
|
||||||
<a title="Tag" target="_blank" href="https://github.com/panjf2000/ants/tags"><img src="https://img.shields.io/github/v/tag/panjf2000/ants?color=%23ff8936&logo=fitbit&style=flat-square" /></a>
|
<a title="Tag" target="_blank" href="https://github.com/panjf2000/ants/tags"><img src="https://img.shields.io/github/v/tag/panjf2000/ants?color=%23ff8936&logo=fitbit&style=flat-square" /></a>
|
||||||
<br/>
|
<br/>
|
||||||
|
<a title="Minimum Go Version" target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://img.shields.io/badge/go-%3E%3D1.16-30dff3?style=flat-square&logo=go" /></a>
|
||||||
<a title="Go Report Card" target="_blank" href="https://goreportcard.com/report/github.com/panjf2000/ants"><img src="https://goreportcard.com/badge/github.com/panjf2000/ants?style=flat-square" /></a>
|
<a title="Go Report Card" target="_blank" href="https://goreportcard.com/report/github.com/panjf2000/ants"><img src="https://goreportcard.com/badge/github.com/panjf2000/ants?style=flat-square" /></a>
|
||||||
<a title="Doc for ants" target="_blank" href="https://pkg.go.dev/github.com/panjf2000/ants/v2?tab=doc"><img src="https://img.shields.io/badge/go.dev-doc-007d9c?style=flat-square&logo=read-the-docs" /></a>
|
<a title="Doc for ants" target="_blank" href="https://pkg.go.dev/github.com/panjf2000/ants/v2?tab=doc"><img src="https://img.shields.io/badge/go.dev-doc-007d9c?style=flat-square&logo=read-the-docs" /></a>
|
||||||
<a title="Mentioned in Awesome Go" target="_blank" href="https://github.com/avelino/awesome-go#goroutines"><img src="https://awesome.re/mentioned-badge-flat.svg" /></a>
|
<a title="Mentioned in Awesome Go" target="_blank" href="https://github.com/avelino/awesome-go#goroutines"><img src="https://awesome.re/mentioned-badge-flat.svg" /></a>
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
<a title="Release" target="_blank" href="https://github.com/panjf2000/ants/releases"><img src="https://img.shields.io/github/v/release/panjf2000/ants.svg?color=161823&style=flat-square&logo=smartthings" /></a>
|
<a title="Release" target="_blank" href="https://github.com/panjf2000/ants/releases"><img src="https://img.shields.io/github/v/release/panjf2000/ants.svg?color=161823&style=flat-square&logo=smartthings" /></a>
|
||||||
<a title="Tag" target="_blank" href="https://github.com/panjf2000/ants/tags"><img src="https://img.shields.io/github/v/tag/panjf2000/ants?color=%23ff8936&logo=fitbit&style=flat-square" /></a>
|
<a title="Tag" target="_blank" href="https://github.com/panjf2000/ants/tags"><img src="https://img.shields.io/github/v/tag/panjf2000/ants?color=%23ff8936&logo=fitbit&style=flat-square" /></a>
|
||||||
<br/>
|
<br/>
|
||||||
|
<a title="Minimum Go Version" target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://img.shields.io/badge/go-%3E%3D1.16-30dff3?style=flat-square&logo=go" /></a>
|
||||||
<a title="Go Report Card" target="_blank" href="https://goreportcard.com/report/github.com/panjf2000/ants"><img src="https://goreportcard.com/badge/github.com/panjf2000/ants?style=flat-square" /></a>
|
<a title="Go Report Card" target="_blank" href="https://goreportcard.com/report/github.com/panjf2000/ants"><img src="https://goreportcard.com/badge/github.com/panjf2000/ants?style=flat-square" /></a>
|
||||||
<a title="Doc for ants" target="_blank" href="https://pkg.go.dev/github.com/panjf2000/ants/v2?tab=doc"><img src="https://img.shields.io/badge/go.dev-doc-007d9c?style=flat-square&logo=read-the-docs" /></a>
|
<a title="Doc for ants" target="_blank" href="https://pkg.go.dev/github.com/panjf2000/ants/v2?tab=doc"><img src="https://img.shields.io/badge/go.dev-doc-007d9c?style=flat-square&logo=read-the-docs" /></a>
|
||||||
<a title="Mentioned in Awesome Go" target="_blank" href="https://github.com/avelino/awesome-go#goroutines"><img src="https://awesome.re/mentioned-badge-flat.svg" /></a>
|
<a title="Mentioned in Awesome Go" target="_blank" href="https://github.com/avelino/awesome-go#goroutines"><img src="https://awesome.re/mentioned-badge-flat.svg" /></a>
|
||||||
|
|||||||
7
ants.go
7
ants.go
@ -20,6 +20,13 @@
|
|||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
|
// Package ants implements an efficient and reliable goroutine pool for Go.
|
||||||
|
//
|
||||||
|
// With ants, Go applications are able to limit the number of active goroutines,
|
||||||
|
// recycle goroutines efficiently, and reduce the memory footprint significantly.
|
||||||
|
// Package ants is extremely useful in the scenarios where a massive number of
|
||||||
|
// goroutines are created and destroyed frequently, such as highly-concurrent
|
||||||
|
// batch processing systems, HTTP servers, services of asynchronous tasks, etc.
|
||||||
package ants
|
package ants
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@ -15,7 +15,7 @@ import (
|
|||||||
Benchmark result for three types of locks:
|
Benchmark result for three types of locks:
|
||||||
goos: darwin
|
goos: darwin
|
||||||
goarch: arm64
|
goarch: arm64
|
||||||
pkg: github.com/panjf2000/ants/v2/internal/sync
|
pkg: github.com/panjf2000/ants/v2/pkg/sync
|
||||||
BenchmarkMutex-10 10452573 111.1 ns/op 0 B/op 0 allocs/op
|
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
|
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
|
BenchmarkBackOffSpinLock-10 100000000 10.81 ns/op 0 B/op 0 allocs/op
|
||||||
25
pkg/sync/sync.go
Normal file
25
pkg/sync/sync.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025. Andy Pan. All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package sync provides some handy implementations for synchronization access.
|
||||||
|
// At the moment, there is only an implementation of spin-lock.
|
||||||
|
package sync
|
||||||
2
pool.go
2
pool.go
@ -28,7 +28,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
syncx "github.com/panjf2000/ants/v2/internal/sync"
|
syncx "github.com/panjf2000/ants/v2/pkg/sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type poolCommon struct {
|
type poolCommon struct {
|
||||||
|
|||||||
@ -28,7 +28,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
syncx "github.com/panjf2000/ants/v2/internal/sync"
|
syncx "github.com/panjf2000/ants/v2/pkg/sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PoolWithFunc accepts the tasks and process them concurrently,
|
// PoolWithFunc accepts the tasks and process them concurrently,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user