core, internal: move workerpool into syncx

This commit is contained in:
Péter Szilágyi 2024-04-29 16:40:44 +03:00
parent 55ebf7bcdb
commit 385c7fb9fc
2 changed files with 7 additions and 8 deletions

View file

@ -33,7 +33,7 @@ import (
"github.com/ethereum/go-ethereum/core/tracing" "github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "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/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie" "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() code = s.db.DiskDB().NewBatch()
lock sync.Mutex 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 { func(obj *stateObject) error {
// Write any storage changes in the state object to its storage trie // Write any storage changes in the state object to its storage trie
set, err := obj.commit() set, err := obj.commit()

View file

@ -14,8 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License // 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/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Package workerpool implements a concurrent task processor. package syncx
package workerpool
import ( import (
"runtime" "runtime"
@ -30,10 +29,10 @@ type WorkerPool[T any, R any] struct {
working sync.WaitGroup // Waitgroup blocking on worker liveness working sync.WaitGroup // Waitgroup blocking on worker liveness
} }
// New creates a worker pool with the given number of max task capacity and an // NewWorkerPool creates a worker pool with the given number of max task capacity
// optional goroutine count to execute on. If 0 threads are requested, the pool // and an optional goroutine count to execute on. If 0 threads are requested, the
// will default to the number of (logical) CPUs. // 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] { func NewWorkerPool[T any, R any](tasks int, threads int, f func(T) R) *WorkerPool[T, R] {
// Create the worker pool // Create the worker pool
pool := &WorkerPool[T, R]{ pool := &WorkerPool[T, R]{
tasks: make(chan T, tasks), tasks: make(chan T, tasks),