mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
core, internal: move workerpool into syncx
This commit is contained in:
parent
55ebf7bcdb
commit
385c7fb9fc
2 changed files with 7 additions and 8 deletions
|
|
@ -33,7 +33,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/tracing"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/internal/workerpool"
|
||||
"github.com/ethereum/go-ethereum/internal/syncx"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
|
|
@ -1162,7 +1162,7 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
|
|||
code = s.db.DiskDB().NewBatch()
|
||||
lock sync.Mutex
|
||||
)
|
||||
workers := workerpool.New[*stateObject, error](len(s.mutations), min(len(s.mutations), runtime.NumCPU()),
|
||||
workers := syncx.NewWorkerPool[*stateObject, error](len(s.mutations), min(len(s.mutations), runtime.NumCPU()),
|
||||
func(obj *stateObject) error {
|
||||
// Write any storage changes in the state object to its storage trie
|
||||
set, err := obj.commit()
|
||||
|
|
|
|||
|
|
@ -14,8 +14,7 @@
|
|||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Package workerpool implements a concurrent task processor.
|
||||
package workerpool
|
||||
package syncx
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
|
@ -30,10 +29,10 @@ type WorkerPool[T any, R any] struct {
|
|||
working sync.WaitGroup // Waitgroup blocking on worker liveness
|
||||
}
|
||||
|
||||
// New creates a worker pool with the given number of max task capacity and an
|
||||
// optional goroutine count to execute on. If 0 threads are requested, the pool
|
||||
// will default to the number of (logical) CPUs.
|
||||
func New[T any, R any](tasks int, threads int, f func(T) R) *WorkerPool[T, R] {
|
||||
// NewWorkerPool creates a worker pool with the given number of max task capacity
|
||||
// and an optional goroutine count to execute on. If 0 threads are requested, the
|
||||
// pool will default to the number of (logical) CPUs.
|
||||
func NewWorkerPool[T any, R any](tasks int, threads int, f func(T) R) *WorkerPool[T, R] {
|
||||
// Create the worker pool
|
||||
pool := &WorkerPool[T, R]{
|
||||
tasks: make(chan T, tasks),
|
||||
Loading…
Reference in a new issue