예제 #1
0
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)
	}
}
예제 #2
0
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()
}
예제 #3
0
파일: lock.go 프로젝트: gbbr/textmate
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)
	}
}
예제 #4
0
파일: lock.go 프로젝트: gbbr/textmate
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)
	}
}