account/keystore : make fs watcher use not block account ops during fs scan

This commit is contained in:
Martin Holst Swende 2017-08-14 15:17:51 +02:00
parent a92d8a2654
commit ad11cf5100
2 changed files with 8 additions and 1 deletions

View file

@ -209,6 +209,12 @@ func (ac *accountCache) close() {
// Callers must hold ac.mu.
func (ac *accountCache) reload() {
accounts, err := ac.scan()
ac.handleScanResult(accounts, err)
}
// handleScanResult uses the result of a fs scan to update the account lists
// This can be used to perform un-mutexed fs scans
func (ac *accountCache) handleScanResult(accounts []accounts.Account, err error) {
if err != nil {
log.Debug("Failed to reload keystore contents", "err", err)
}

View file

@ -99,8 +99,9 @@ func (w *watcher) loop() {
hadEvent = true
}
case <-debounce.C:
accounts, err := w.ac.scan()
w.ac.mu.Lock()
w.ac.reload()
w.ac.handleScanResult(accounts, err)
w.ac.mu.Unlock()
if hadEvent {
debounce.Reset(debounceDuration)