forked from ethereum-optimism/op-geth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose method to force statedb to use singlethreaded mode even when m…
…ultiple CPUs are available. (ethereum-optimism#373)
- Loading branch information
1 parent
d4ff6e0
commit 65a1b18
Showing
2 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package state | ||
|
||
import ( | ||
"errors" | ||
|
||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
type workerGroup interface { | ||
Go(func() error) | ||
SetLimit(int) | ||
Wait() error | ||
} | ||
|
||
func newWorkerGroup(singlethreaded bool) workerGroup { | ||
if singlethreaded { | ||
return &inlineWorkerGroup{} | ||
} else { | ||
var grp errgroup.Group | ||
return &grp | ||
} | ||
} | ||
|
||
type inlineWorkerGroup struct { | ||
err error | ||
} | ||
|
||
func (i *inlineWorkerGroup) Go(action func() error) { | ||
i.err = errors.Join(i.err, action()) | ||
} | ||
|
||
func (i *inlineWorkerGroup) SetLimit(_ int) { | ||
} | ||
|
||
func (i *inlineWorkerGroup) Wait() error { | ||
return i.err | ||
} |