func (lock *Lock) setCount(l int64) { dict := newDict(C.PyThreadState_GetDict()) pl := NewLong(l) defer pl.Decref() err := dict.SetItemString("gopy.count", pl) if err != nil { panic(err) } }
func (lock *Lock) getCount() int64 { dict := newDict(C.PyThreadState_GetDict()) val, err := dict.GetItemString("gopy.count") if err != nil { return 0 } count, ok := val.(*Long) if !ok { return 0 } return count.Int64() }
func (lock *Lock) inc() { dict := newDict(C.PyThreadState_GetDict()) if dict == nil { panic("Nil dict") } if c, err := dict.GetItemString("gopy.count"); err == nil { if c2, ok := c.(*Long); ok { l := c2.Int64() l++ lock.setCount(l) } else { lock.setCount(1) } } else { lock.setCount(1) } }
func (lock *Lock) dec() bool { releaseOsThread := true dict := newDict(C.PyThreadState_GetDict()) if dict == nil { panic("Nil dict") } if c, err := dict.GetItemString("gopy.count"); err == nil { if c2, ok := c.(*Long); ok { l := c2.Int64() l-- if l != 0 { releaseOsThread = false } lock.setCount(l) } else { panic(c) } return releaseOsThread } else { panic(err) } }