Commit 0290d904 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 39e27aa5
......@@ -437,71 +437,7 @@ func (d *dummyPyInstance) PySetState(pystate interface{}) error {
}
// ----------------------------------------
// object's activate & friends that only manage base activation state, without actually loading data.
// XXX ^^^ still relevant?
/*
// activate increments object reference counter.
//
// it returns whether object data needs to be loaded.
// the caller must adjust .state after loading is complete.
//
// must be called with .mu held.
func (obj *object) activate() (load bool) {
obj.refcnt++
return (obj.refcnt == 1 && obj.state == GHOST)
}
*/
// deactivate decrements object reference counter.
//
// it returns whether object data needs to be discarded.
// must be called with .mu held.
func (obj *object) deactivate() (drop bool) {
//nuse := atomic.AddInt32(&obj.refcnt, -1)
obj.refcnt--
if obj.refcnt < 0 {
panic("deactivate: refcnt < 0")
}
if obj.refcnt > 0 {
return false // users still left
}
// no users left. Let's see whether we should transition this object to ghost.
if obj.state >= CHANGED {
return false
}
// XXX -> pyObject?
if cc := obj.jar.cacheControl; cc != nil {
if !cc.WantEvict(obj.instance) {
return false
}
}
obj.serial = 0
obj.instance.DropState()
obj.state = GHOST
return true
}
// invalidate XXX
//
// must be called with .mu held.
func (obj *object) invalidate() {
if obj.refcnt != 0 {
// object is currently in use
panic("invalidate: refcnt != 0")
}
obj.serial = 0
obj.instance.DropState()
obj.state = GHOST
}
// ---- activate/deactivate/invalidate ----
// PActivate implements Object.
func (obj *object) PActivate(ctx context.Context) (err error) {
......@@ -571,21 +507,47 @@ func (obj *object) PActivate(ctx context.Context) (err error) {
// PDeactivate implements Object.
func (pyobj *pyObject) PDeactivate() {
pyobj.mu.Lock()
defer pyobj.mu.Unlock()
func (obj *Object) PDeactivate() {
obj.mu.Lock()
defer obj.mu.Unlock()
obj.refcnt--
if obj.refcnt < 0 {
panic("deactivate: refcnt < 0")
}
if obj.refcnt > 0 {
return // users still left
}
drop := pyobj.deactivate()
if drop {
pyobj.loading = nil
// no users left. Let's see whether we should transition this object to ghost.
if obj.state >= CHANGED {
return
}
if cc := obj.jar.cacheControl; cc != nil {
if !cc.WantEvict(obj.instance) {
return
}
}
obj.serial = 0
obj.instance.DropState()
obj.state = GHOST
obj.loading = nil
}
// PInvalidate() implements Object.
func (pyobj *pyObject) PInvalidate() {
pyobj.mu.Lock()
defer pyobj.mu.Unlock()
func (obj *pyObject) PInvalidate() {
obj.mu.Lock()
defer obj.mu.Unlock()
pyobj.invalidate()
pyobj.loading = nil
if obj.refcnt != 0 {
// object is currently in use
panic("invalidate: refcnt != 0")
}
obj.serial = 0
obj.instance.DropState()
obj.state = GHOST
obj.loading = nil
}
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