mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
Update core/sender_cacher.go
Co-authored-by: jwasinger <j-wasinger@hotmail.com>
This commit is contained in:
parent
e9b9afece4
commit
f76f30d4b6
1 changed files with 6 additions and 13 deletions
|
|
@ -23,22 +23,15 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
// senderCacherOnce is used to ensure that the SenderCacher is initialized only once.
|
||||||
// senderCacherOnce is used to ensure that the SenderCacher is initialized only once.
|
var senderCacherOnce = sync.OnceValue(func() *txSenderCacher {
|
||||||
// It leverages sync.Once to provide thread-safe lazy initialization.
|
return newTxSenderCacher(runtime.NumCPU())
|
||||||
senderCacherOnce sync.Once
|
})
|
||||||
// senderCacherInstance is a concurrent transaction sender recoverer and cacher.
|
|
||||||
senderCacherInstance *txSenderCacher
|
|
||||||
)
|
|
||||||
|
|
||||||
// SenderCacher returns the singleton instance of SenderCacher.
|
// SenderCacher returns the singleton instance of SenderCacher, initializing it if called for the first time.
|
||||||
// If the instance has not been initialized yet, it will be created using newTxSenderCacher.
|
|
||||||
// This function is thread-safe and ensures that initialization happens only once.
|
// This function is thread-safe and ensures that initialization happens only once.
|
||||||
func SenderCacher() *txSenderCacher {
|
func SenderCacher() *txSenderCacher {
|
||||||
senderCacherOnce.Do(func() {
|
return senderCacherOnce()
|
||||||
senderCacherInstance = newTxSenderCacher(runtime.NumCPU())
|
|
||||||
})
|
|
||||||
return senderCacherInstance
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// txSenderCacherRequest is a request for recovering transaction senders with a
|
// txSenderCacherRequest is a request for recovering transaction senders with a
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue