From 5ceb1620e93e1999c6f72e6164c7c65af63244ec Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 21 May 2014 00:17:50 +0200 Subject: Fixed couple issues * (imp) Lock / RLock tries * (fix) stack --- ethutil/trie.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'ethutil') diff --git a/ethutil/trie.go b/ethutil/trie.go index 4d088ccff..1c7bd478d 100644 --- a/ethutil/trie.go +++ b/ethutil/trie.go @@ -3,6 +3,7 @@ package ethutil import ( "fmt" "reflect" + "sync" ) // TODO @@ -113,6 +114,7 @@ func (cache *Cache) Undo() { // Please note that the data isn't persisted unless `Sync` is // explicitly called. type Trie struct { + mut sync.RWMutex prevRoot interface{} Root interface{} //db Database @@ -157,12 +159,18 @@ func (t *Trie) Cache() *Cache { * Public (query) interface functions */ func (t *Trie) Update(key string, value string) { + t.mut.Lock() + defer t.mut.Unlock() + k := CompactHexDecode(key) t.Root = t.UpdateState(t.Root, k, value) } func (t *Trie) Get(key string) string { + t.mut.RLock() + defer t.mut.RUnlock() + k := CompactHexDecode(key) c := NewValue(t.GetState(t.Root, k)) -- cgit v1.2.3