diff options
author | obscuren <geffobscura@gmail.com> | 2014-10-07 17:18:46 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-10-07 17:18:46 +0800 |
commit | 0015ce1e353f52cca818d11f566b9a656fb85f24 (patch) | |
tree | cb14b0d81b0418e990276982b7f1ccf293ba1508 /ethutil | |
parent | 677836cbee1105043335c672b41dc4402e98c227 (diff) | |
download | dexon-0015ce1e353f52cca818d11f566b9a656fb85f24.tar.gz dexon-0015ce1e353f52cca818d11f566b9a656fb85f24.tar.zst dexon-0015ce1e353f52cca818d11f566b9a656fb85f24.zip |
kick of bad peers
Diffstat (limited to 'ethutil')
-rw-r--r-- | ethutil/list.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/ethutil/list.go b/ethutil/list.go index 4fb36224f..6919a02f5 100644 --- a/ethutil/list.go +++ b/ethutil/list.go @@ -3,12 +3,14 @@ package ethutil import ( "encoding/json" "reflect" + "sync" ) // The list type is an anonymous slice handler which can be used // for containing any slice type to use in an environment which // does not support slice types (e.g., JavaScript, QML) type List struct { + mut sync.Mutex val interface{} list reflect.Value Length int @@ -21,7 +23,7 @@ func NewList(t interface{}) *List { panic("list container initialized with a non-slice type") } - return &List{t, list, list.Len()} + return &List{sync.Mutex{}, t, list, list.Len()} } func EmptyList() *List { @@ -30,8 +32,10 @@ func EmptyList() *List { // Get N element from the embedded slice. Returns nil if OOB. func (self *List) Get(i int) interface{} { - if self.list.Len() > i { + self.mut.Lock() + defer self.mut.Unlock() + i := self.list.Index(i).Interface() return i @@ -51,6 +55,9 @@ func (self *List) GetAsJson(i int) interface{} { // Appends value at the end of the slice. Panics when incompatible value // is given. func (self *List) Append(v interface{}) { + self.mut.Lock() + defer self.mut.Unlock() + self.list = reflect.Append(self.list, reflect.ValueOf(v)) self.Length = self.list.Len() } |