Commit 9a8313a9 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Deal with wrapping handles in portableHandleMap.

parent 22dcd8c5
...@@ -48,11 +48,23 @@ func (me *portableHandleMap) Register(obj *Handled, asInt interface{}) uint64 { ...@@ -48,11 +48,23 @@ func (me *portableHandleMap) Register(obj *Handled, asInt interface{}) uint64 {
} }
me.Lock() me.Lock()
defer me.Unlock() defer me.Unlock()
for {
h := uint64(me.nextFree) h := uint64(me.nextFree)
me.nextFree++ me.nextFree++
if h < 2 {
continue
}
old := me.handles[h]
if old != nil {
continue
}
me.handles[h] = obj me.handles[h] = obj
obj.check = 0xbaabbaab obj.check = 0xbaabbaab
return h return h
}
return 0
} }
func (me *portableHandleMap) Count() int { func (me *portableHandleMap) Count() int {
...@@ -154,7 +166,6 @@ func (me *int64HandleMap) verify() { ...@@ -154,7 +166,6 @@ func (me *int64HandleMap) verify() {
func NewHandleMap(portable bool) (hm HandleMap) { func NewHandleMap(portable bool) (hm HandleMap) {
if portable { if portable {
return &portableHandleMap{ return &portableHandleMap{
nextFree: 2,
handles: make(map[uint64]*Handled), handles: make(map[uint64]*Handled),
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment