aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-21 06:17:50 +0800
committerobscuren <geffobscura@gmail.com>2014-05-21 06:17:50 +0800
commit5ceb1620e93e1999c6f72e6164c7c65af63244ec (patch)
treee3185f8202dd3f3ebd065be5a1ea7e7ba08e6055 /ethutil
parente8b45852952138ac24dada1a70480d31d0886c27 (diff)
downloaddexon-5ceb1620e93e1999c6f72e6164c7c65af63244ec.tar
dexon-5ceb1620e93e1999c6f72e6164c7c65af63244ec.tar.gz
dexon-5ceb1620e93e1999c6f72e6164c7c65af63244ec.tar.bz2
dexon-5ceb1620e93e1999c6f72e6164c7c65af63244ec.tar.lz
dexon-5ceb1620e93e1999c6f72e6164c7c65af63244ec.tar.xz
dexon-5ceb1620e93e1999c6f72e6164c7c65af63244ec.tar.zst
dexon-5ceb1620e93e1999c6f72e6164c7c65af63244ec.zip
Fixed couple issues
* (imp) Lock / RLock tries * (fix) stack
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/trie.go8
1 files changed, 8 insertions, 0 deletions
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))