summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-05-23 18:41:57 +0000
committerCedric BAIL <cedric.bail@free.fr>2019-05-29 15:53:23 -0700
commita86a0931f16f6a9d5afbff71364048dc859e2dff (patch)
tree9412183d21dab63fb55e9157c95187b1cb46e571 /src/lib
parent343698f7eceb7cc3cfdb21da955abd401adc16a8 (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. We also add benchmarks for sharing (i.e. increasing the refcount) and them unsharing objects, in order to evaluate the performance impact of this patch. Reviewed-by: Cedric BAIL <cedric.bail@free.fr> Differential Revision: https://phab.enlightenment.org/D8678
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/eo/efl_object.eo5
-rw-r--r--src/lib/eo/eo.c7
-rw-r--r--src/lib/eo/eo_base_class.c6
-rw-r--r--src/lib/eo/eo_private.h1
4 files changed, 19 insertions, 0 deletions
diff --git a/src/lib/eo/efl_object.eo b/src/lib/eo/efl_object.eo
index 1ced422..bea9a0e 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 0113434..db96b24 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 (EINA_UNLIKELY(obj->ownership_track && 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 (EINA_UNLIKELY(obj->ownership_track && 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
diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c
index 2dc5efc..62a1caf 100644
--- a/src/lib/eo/eo_base_class.c
+++ b/src/lib/eo/eo_base_class.c
@@ -1179,6 +1179,12 @@ _special_event_count_inc(Eo *obj_id, Efl_Object_Data *pd, const Efl_Callback_Arr
1179 } 1179 }
1180 else if (it->desc == EFL_EVENT_DESTRUCT) 1180 else if (it->desc == EFL_EVENT_DESTRUCT)
1181 pd->has_destroyed_event_cb = EINA_TRUE; 1181 pd->has_destroyed_event_cb = EINA_TRUE;
1182 else if (it->desc == EFL_EVENT_OWNERSHIP_SHARED || it->desc == EFL_EVENT_OWNERSHIP_UNIQUE)
1183 {
1184 EO_OBJ_POINTER_RETURN(obj_id, obj);
1185 obj->ownership_track = EINA_TRUE;
1186 EO_OBJ_DONE(obj_id);
1187 }
1182} 1188}
1183 1189
1184static inline void 1190static inline void
diff --git a/src/lib/eo/eo_private.h b/src/lib/eo/eo_private.h
index 3b046bb..c64dee5 100644
--- a/src/lib/eo/eo_private.h
+++ b/src/lib/eo/eo_private.h
@@ -126,6 +126,7 @@ struct _Eo_Object
126 Eina_Bool destructed:1; 126 Eina_Bool destructed:1;
127 Eina_Bool manual_free:1; 127 Eina_Bool manual_free:1;
128 unsigned char auto_unref : 1; // unref after 1 call - hack for parts 128 unsigned char auto_unref : 1; // unref after 1 call - hack for parts
129 Eina_Bool ownership_track:1;
129}; 130};
130 131
131/* How we search and store the implementations in classes. */ 132/* How we search and store the implementations in classes. */