summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-04-17 18:44:40 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-04-17 18:45:24 -0300
commit9843304279135069e903f8c881f53a4ea38a9695 (patch)
tree298acaaa910e31757d8b96c9272282d0d2c22f04
parent7404904a43992e008ef8f186216a9aba8006404c (diff)
eo: add events to track the ownership status of an Eo object
Some user code may want to track an object ownership in regard to whether it is kept by just one owner or shared between many owners. This is specially true for code provided by bindings to other programming languages, where different kinds of resource management may take place. The event `ownership,unique` is triggered whenever the object refcount goes from two to one, as a signal that it has just one owner from now on. The event `ownership,shared` is triggered whenever the object refcount goes from one to two, as a signal that it has multiple owners from now on. It will not trigger when further increasing the refcount to any value beyond two.
-rw-r--r--src/lib/eo/efl_object.eo5
-rw-r--r--src/lib/eo/eo.c7
2 files changed, 12 insertions, 0 deletions
diff --git a/src/lib/eo/efl_object.eo b/src/lib/eo/efl_object.eo
index cb0a92e70c..680554c9a8 100644
--- a/src/lib/eo/efl_object.eo
+++ b/src/lib/eo/efl_object.eo
@@ -411,6 +411,11 @@ abstract Efl.Object
411 del @hot: void; [[Object is being deleted. See @.destructor.]] 411 del @hot: void; [[Object is being deleted. See @.destructor.]]
412 invalidate @hot: void; [[Object is being invalidated and losing its parent. See @.invalidate.]] 412 invalidate @hot: void; [[Object is being invalidated and losing its parent. See @.invalidate.]]
413 noref @hot: void; [[Object has lost its last reference, only parent relationship is keeping it alive. Advanced usage.]] 413 noref @hot: void; [[Object has lost its last reference, only parent relationship is keeping it alive. Advanced usage.]]
414 ownership,unique @hot: void; [[Object has lost a reference and only one is left. It has just one owner now.
415 Triggered whenever the refcount goes from two to one.]]
416 ownership,shared @hot: void; [[Object has acquired a second reference. It has multiple owners now.
417 Triggered whenever increasing the refcount from one to two,
418 it will not trigger by further increasing the refcount beyond two.]]
414 destruct @hot: void; [[Object has been fully destroyed. It can not be used 419 destruct @hot: void; [[Object has been fully destroyed. It can not be used
415 beyond this point. This event should only serve to clean up any 420 beyond this point. This event should only serve to clean up any
416 reference you keep to the object.]] 421 reference you keep to the object.]]
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index c16c021ef2..3ce21695de 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -1933,6 +1933,9 @@ efl_ref(const Eo *obj_id)
1933 ++(obj->user_refcount); 1933 ++(obj->user_refcount);
1934 if (EINA_UNLIKELY(obj->user_refcount == 1)) 1934 if (EINA_UNLIKELY(obj->user_refcount == 1))
1935 _efl_ref(obj); 1935 _efl_ref(obj);
1936 else if (!obj->auto_unref && obj->user_refcount == 2)
1937 efl_event_callback_call((Eo *) obj_id, EFL_EVENT_OWNERSHIP_SHARED, NULL);
1938
1936#ifdef EO_DEBUG 1939#ifdef EO_DEBUG
1937 _eo_log_obj_ref_op(obj, EO_REF_OP_REF); 1940 _eo_log_obj_ref_op(obj, EO_REF_OP_REF);
1938#endif 1941#endif
@@ -1991,6 +1994,10 @@ efl_unref(const Eo *obj_id)
1991 } 1994 }
1992 _efl_unref(obj); 1995 _efl_unref(obj);
1993 } 1996 }
1997 else if (obj->user_refcount == 1)
1998 {
1999 efl_event_callback_call((Eo *) obj_id, EFL_EVENT_OWNERSHIP_UNIQUE, NULL);
2000 }
1994 2001
1995 _apply_auto_unref(obj, obj_id); 2002 _apply_auto_unref(obj, obj_id);
1996 2003