mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
accounts/keystore: Remove atomic from watch, not multithreaded
This commit is contained in:
parent
f29b7b04a5
commit
0490146aaf
1 changed files with 4 additions and 15 deletions
|
|
@ -23,7 +23,6 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/rjeczalik/notify"
|
"github.com/rjeczalik/notify"
|
||||||
"sync/atomic"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type watcher struct {
|
type watcher struct {
|
||||||
|
|
@ -84,8 +83,7 @@ func (w *watcher) loop() {
|
||||||
var (
|
var (
|
||||||
debounce = time.NewTimer(0)
|
debounce = time.NewTimer(0)
|
||||||
debounceDuration = 500 * time.Millisecond
|
debounceDuration = 500 * time.Millisecond
|
||||||
unHandledEvents = uint64(0)
|
rescanTriggered = false
|
||||||
inCycle = uint64(0)
|
|
||||||
)
|
)
|
||||||
defer debounce.Stop()
|
defer debounce.Stop()
|
||||||
for {
|
for {
|
||||||
|
|
@ -93,23 +91,14 @@ func (w *watcher) loop() {
|
||||||
case <-w.quit:
|
case <-w.quit:
|
||||||
return
|
return
|
||||||
case <-w.ev:
|
case <-w.ev:
|
||||||
// Count up the unhandled events
|
|
||||||
atomic.AddUint64(&unHandledEvents, 1)
|
|
||||||
// Trigger the scan (with delay), if not already triggered
|
// Trigger the scan (with delay), if not already triggered
|
||||||
if atomic.SwapUint64(&inCycle, 1) == 0 {
|
if !rescanTriggered{
|
||||||
debounce.Reset(debounceDuration)
|
debounce.Reset(debounceDuration)
|
||||||
|
rescanTriggered = true
|
||||||
}
|
}
|
||||||
case <-debounce.C:
|
case <-debounce.C:
|
||||||
//We're now handling the events, scan again as long as new
|
|
||||||
// events keep coming during our fs-scan
|
|
||||||
atomic.SwapUint64(&unHandledEvents, 0)
|
|
||||||
w.ac.scanAccounts()
|
w.ac.scanAccounts()
|
||||||
// Scan again if more events occurred during scan
|
rescanTriggered = false
|
||||||
for atomic.SwapUint64(&unHandledEvents, 0) > 0 {
|
|
||||||
w.ac.scanAccounts()
|
|
||||||
}
|
|
||||||
// Signal we're finished with cycle
|
|
||||||
atomic.SwapUint64(&inCycle, 0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue