From 4f33c6ef273c3785965a21e63f9f5accbc47b16d Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sun, 12 Jan 2025 10:38:09 +0800 Subject: [PATCH] feat: export the internal package sync (#349) --- .github/release-drafter.yml | 13 +++++++++++-- .github/workflows/test.yml | 2 +- README.md | 1 + README_ZH.md | 1 + ants.go | 7 +++++++ {internal => pkg}/sync/spinlock.go | 0 {internal => pkg}/sync/spinlock_test.go | 2 +- pkg/sync/sync.go | 25 +++++++++++++++++++++++++ pool.go | 2 +- pool_func.go | 2 +- 10 files changed, 49 insertions(+), 6 deletions(-) rename {internal => pkg}/sync/spinlock.go (100%) rename {internal => pkg}/sync/spinlock_test.go (96%) create mode 100644 pkg/sync/sync.go diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 78f55b9..cfea99b 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -44,7 +44,7 @@ autolabeler: title: - /fix/i - /bug/i - - /patch/i + - /resolve/i - label: docs files: - '*.md' @@ -60,6 +60,15 @@ autolabeler: - /update/i - /remove/i - /delete/i + - label: optimization + title: + - /opt:/i + - /refactor/i + - /optimize/i + - /improve/i + - /update/i + - /remove/i + - /delete/i - label: new feature title: - /feat:/i @@ -75,7 +84,7 @@ autolabeler: - label: chores title: - /chore/i - - /\bmisc\b/i + - /misc/i - /cleanup/i - /clean up/i - label: major diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c4989a9..8a560b7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -87,7 +87,7 @@ jobs: run: go test -v -race -coverprofile="codecov.report" -covermode=atomic - name: Upload code coverage report to Codecov - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v5 with: file: ./codecov.report flags: unittests diff --git a/README.md b/README.md index 40f1ca8..78c77e4 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@
+ diff --git a/README_ZH.md b/README_ZH.md index 20e03ff..e422f74 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -7,6 +7,7 @@
+ diff --git a/ants.go b/ants.go index dd170a6..fa68482 100644 --- a/ants.go +++ b/ants.go @@ -20,6 +20,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // 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 import ( diff --git a/internal/sync/spinlock.go b/pkg/sync/spinlock.go similarity index 100% rename from internal/sync/spinlock.go rename to pkg/sync/spinlock.go diff --git a/internal/sync/spinlock_test.go b/pkg/sync/spinlock_test.go similarity index 96% rename from internal/sync/spinlock_test.go rename to pkg/sync/spinlock_test.go index fa20401..3934ec8 100644 --- a/internal/sync/spinlock_test.go +++ b/pkg/sync/spinlock_test.go @@ -15,7 +15,7 @@ import ( Benchmark result for three types of locks: goos: darwin 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 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 diff --git a/pkg/sync/sync.go b/pkg/sync/sync.go new file mode 100644 index 0000000..d66192f --- /dev/null +++ b/pkg/sync/sync.go @@ -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 diff --git a/pool.go b/pool.go index 2106e83..8361928 100644 --- a/pool.go +++ b/pool.go @@ -28,7 +28,7 @@ import ( "sync/atomic" "time" - syncx "github.com/panjf2000/ants/v2/internal/sync" + syncx "github.com/panjf2000/ants/v2/pkg/sync" ) type poolCommon struct { diff --git a/pool_func.go b/pool_func.go index 2954106..f3d341d 100644 --- a/pool_func.go +++ b/pool_func.go @@ -28,7 +28,7 @@ import ( "sync/atomic" "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,