Compare commits

...

9 Commits

Author SHA1 Message Date
Avi Levin d8c44ee7f6 eo: working version that combines linear and ordered search
If we have less than 7 members we will use linear search.
@feature
2015-04-01 11:10:10 +03:00
Avi Levin 3f7c4978f3 changing to unordered array and normal search 2015-04-01 11:10:10 +03:00
Avi Levin c7b50e597e ordered callbacks by stringshared event_name 2015-04-01 11:10:10 +03:00
Avi Levin af71da5bec eo: removing unuseful sts data and adding others that are useful
@feature
2015-04-01 11:10:10 +03:00
Avi Levin d21634f9f8 eo: adding print for benchmarking/statitics
@feature
2015-04-01 11:10:10 +03:00
Avi Levin de066fc0b5 eo: fixing the annoying bug with the error in delting children
@fix
2015-04-01 11:10:10 +03:00
Daniel Zaoui b38b2df9a3 Eo: review + fixes
One Valgrind issue is solbed but the main is still there.
2015-04-01 11:10:10 +03:00
Avi Levin 24296c6527 eo: clean up from unsued code and fixing warnings
@fix
2015-04-01 11:10:10 +03:00
Avi Levin 5c78c1b415 eo: changing callbacks data sctructure
In the original code pd->callbacks was a simple list of callbacks
ordered by priority. now pd->callbacks is Eina_Inarray
of Eina_list's of callbacks. the Eina_Inarray is ordered by the
callbacks events and each Eina_List is ordered by priority.
That way is should be faster to call all callbacks of same event.
In elementary_test when press something that opens a window and close
that window we get: :ERR<15994>:evas_main
lib/evas/canvas/evas_object_box.c:130 _on_child_del() child removal
failed".

@feature
2015-04-01 11:10:10 +03:00
1 changed files with 323 additions and 128 deletions

View File

@ -21,11 +21,57 @@ typedef struct
Eina_Inlist *generic_data;
Eo ***wrefs;
Eo_Callback_Description *callbacks;
Eina_Inarray *callbacks;
unsigned short walking_list;
unsigned short event_freeze_count;
Eina_Bool deletions_waiting : 1;
//clock_t call_updated;
//for benchmark start
unsigned int called_counter;
unsigned int callbacks_counter;
unsigned int called_loop_counter;
unsigned int called_inner_loop_counter;
unsigned int arrays_counter;
clock_t called_sum_clocks ;
unsigned int events_counter;
unsigned long long int have_events;
//for benchmar endk
} Eo_Base_Data;
//for benchmark start
static unsigned int called_counter=0;
static unsigned int callbacks_counter=0;
static unsigned int called_loop_counter=0;
static unsigned int called_inner_loop_counter=0;
static unsigned int arrays_counter=0;
static unsigned int objects_counter=0;
static clock_t called_sum_clocks =0;
static clock_t start_clock =0;
static unsigned int events_counter=0;
static unsigned legacy_events_inserted=0;
static unsigned regular_events_inserted=0;
//for benchmark end
//static clock_t call_updated=0;
typedef struct {
const Eo_Event_Description *event;
Eina_Stringshare *event_name;
Eo_Callback_Description *callbacks;
}Eo_Event_Callbacks;
typedef struct
{
@ -436,27 +482,29 @@ _legacy_events_hash_free_cb(void *_desc)
struct _Eo_Callback_Description
{
Eo_Callback_Description *next;
union
{
Eo_Callback_Array_Item item;
const Eo_Callback_Array_Item *item_array;
} items;
const Eo_Callback_Array_Item *item_array;
void *func_data;
Eo_Callback_Priority priority;
Eina_Bool delete_me : 1;
Eina_Bool func_array : 1;
Eina_Bool is_legacy_counter : 1;
};
/* Actually remove, doesn't care about walking list, or delete_me */
static void
_eo_callback_remove(Eo_Base_Data *pd, Eo_Callback_Description *cb)
_eo_callback_remove(Eo_Event_Callbacks *ec, Eo_Callback_Description *cb)
{
Eo_Callback_Description *itr, *pitr = NULL;
itr = pd->callbacks;
itr = ec->callbacks;
for ( ; itr; )
{
@ -471,29 +519,32 @@ _eo_callback_remove(Eo_Base_Data *pd, Eo_Callback_Description *cb)
}
else
{
pd->callbacks = titr->next;
ec->callbacks = titr->next;
}
free(titr);
}
else
{
pitr = titr;
}
}
}
}
/* Actually remove, doesn't care about walking list, or delete_me */
static void
_eo_callback_remove_all(Eo_Base_Data *pd)
{
while (pd->callbacks)
Eo_Event_Callbacks *cbs;
EINA_INARRAY_FOREACH(pd->callbacks, cbs)
{
Eo_Callback_Description *next = pd->callbacks->next;
free(pd->callbacks);
pd->callbacks = next;
while (cbs->callbacks)
{
Eo_Callback_Description *next = cbs->callbacks->next;
free(cbs->callbacks);
cbs->callbacks = next;
}
}
}
static void
_eo_callbacks_clear(Eo_Base_Data *pd)
{
@ -508,24 +559,28 @@ _eo_callbacks_clear(Eo_Base_Data *pd)
return;
pd->deletions_waiting = EINA_FALSE;
Eo_Event_Callbacks *cbs;
for (cb = pd->callbacks; cb; )
EINA_INARRAY_FOREACH(pd->callbacks, cbs)
{
Eo_Callback_Description *titr = cb;
cb = cb->next;
if (titr->delete_me)
for (cb = cbs->callbacks; cb; )
{
_eo_callback_remove(pd, titr);
Eo_Callback_Description *titr = cb;
cb = cb->next;
if (titr->delete_me)
{
_eo_callback_remove(cbs, titr);
}
}
}
}
static void
_eo_callbacks_sorted_insert(Eo_Base_Data *pd, Eo_Callback_Description *cb)
_eo_callbacks_list_sorted_insert( Eo_Event_Callbacks *ec, Eo_Callback_Description *cb)
{
Eo_Callback_Description *itr, *itrp = NULL;
for (itr = pd->callbacks; itr && (itr->priority < cb->priority);
for (itr = ec->callbacks; itr && (itr->priority < cb->priority);
itr = itr->next)
{
itrp = itr;
@ -538,17 +593,87 @@ _eo_callbacks_sorted_insert(Eo_Base_Data *pd, Eo_Callback_Description *cb)
}
else
{
cb->next = pd->callbacks;
pd->callbacks = cb;
cb->next = ec->callbacks;
ec->callbacks = cb;
}
}
int
_eo_base_event_compare( const void* e1 , const void* e2){
EOLIAN static void
_eo_base_event_callback_priority_add(Eo *obj, Eo_Base_Data *pd,
const Eo_Event_Description *desc,
Eo_Callback_Priority priority,
Eo_Event_Cb func,
const void *user_data)
if( ((Eo_Event_Callbacks*)e1)->event_name == ((Eo_Event_Callbacks*)e2)->event_name)
return 0;
if( ((Eo_Event_Callbacks*)e1)->event_name > ((Eo_Event_Callbacks*)e2)->event_name)
return 1;
return -1;
}
static void
_eo_callbacks_sorted_insert(Eo_Base_Data *pd, Eo_Callback_Description *cb, const Eo_Event_Description *desc)
{
if (!desc)
{
DBG("sorted insert NULL event!\n");
return;
}
{
//adding to events conter - statistics
unsigned int index = ((unsigned long long int )desc)%63;
if( (pd->have_events & (1<<index) )==0){
pd->events_counter++;
pd->have_events |= 1<<index;
}
}
pd->callbacks_counter++;//avi debug
Eina_Stringshare *event_name;
if (desc->doc != _legacy_event_desc)
{
legacy_events_inserted++;
event_name = eina_stringshare_add(desc->name);
}
else{
event_name = desc->name;
regular_events_inserted++;
}
Eo_Event_Callbacks *cbs;
Eo_Event_Callbacks ec = { desc, event_name , cb };
cb->next=NULL;
int index = eina_inarray_search_sorted ( pd->callbacks, &ec , _eo_base_event_compare );
/* EINA_INARRAY_FOREACH(pd->callbacks, cbs)
{
// if(_cb_desc_match(desc, cbs->event))
if(event_name == cbs->event_name)
{
_eo_callbacks_list_sorted_insert(cbs, cb);
if (desc->doc != _legacy_event_desc)
eina_stringshare_del(event_name);
return;
}
}*/
if(index !=-1){
cbs =eina_inarray_nth(pd->callbacks , index );
_eo_callbacks_list_sorted_insert(cbs, cb);
if (desc->doc != _legacy_event_desc)
eina_stringshare_del(event_name);
return;
}
// eina_inarray_push(pd->callbacks, &ec);
eina_inarray_insert_sorted(pd->callbacks , &ec , _eo_base_event_compare );
}
EOLIAN static void _eo_base_event_callback_priority_add(Eo *obj, Eo_Base_Data *pd,
const Eo_Event_Description *desc, Eo_Callback_Priority priority, Eo_Event_Cb func, const void *data)
{
Eo_Callback_Description *cb;
@ -556,9 +681,12 @@ _eo_base_event_callback_priority_add(Eo *obj, Eo_Base_Data *pd,
if (!cb) return;
cb->items.item.desc = desc;
cb->items.item.func = func;
cb->func_data = (void *) user_data;
cb->func_data = (void *) data;
cb->priority = priority;
_eo_callbacks_sorted_insert(pd, cb);
cb->func_array = EINA_FALSE;
cb->delete_me = EINA_FALSE;
_eo_callbacks_sorted_insert(pd, cb, desc);
{
const Eo_Callback_Array_Item arr[] = { {desc, func}, {NULL, NULL}};
@ -568,24 +696,30 @@ _eo_base_event_callback_priority_add(Eo *obj, Eo_Base_Data *pd,
EOLIAN static void
_eo_base_event_callback_del(Eo *obj, Eo_Base_Data *pd,
const Eo_Event_Description *desc,
Eo_Event_Cb func,
const void *user_data)
const Eo_Event_Description *desc,
Eo_Event_Cb func,
const void *user_data)
{
Eo_Callback_Description *cb;
for (cb = pd->callbacks; cb; cb = cb->next)
{
if ((cb->items.item.desc == desc) && (cb->items.item.func == func) &&
(cb->func_data == user_data))
{
const Eo_Callback_Array_Item arr[] = { {desc, func}, {NULL, NULL}};
Eo_Event_Callbacks *cbs;
cb->delete_me = EINA_TRUE;
pd->deletions_waiting = EINA_TRUE;
_eo_callbacks_clear(pd);
eo_do(obj, eo_event_callback_call(EO_EV_CALLBACK_DEL, (void *)arr); );
return;
EINA_INARRAY_FOREACH(pd->callbacks, cbs)
{
for (cb = cbs->callbacks; cb; cb = cb->next)
{
if ((cb->items.item.desc == desc) && (cb->items.item.func == func) &&
(cb->func_data == user_data))
{
const Eo_Callback_Array_Item arr[] = { {desc, func}, {NULL, NULL}};
cb->delete_me = EINA_TRUE;
pd->deletions_waiting = EINA_TRUE;
_eo_callbacks_clear(pd);
eo_do(obj, eo_event_callback_call(EO_EV_CALLBACK_DEL, (void *)arr); );
return;
}
}
}
@ -598,18 +732,28 @@ _eo_base_event_callback_array_priority_add(Eo *obj, Eo_Base_Data *pd,
Eo_Callback_Priority priority,
const void *user_data)
{
Eo_Callback_Description *cb;
const Eo_Callback_Array_Item *it;
for (it = array; it->func; it++)
{
Eo_Callback_Description *cb;
cb = calloc(1, sizeof(*cb));
if (!cb) return;
cb->items.item.desc = it->desc;
cb->items.item.func = it->func;
cb->func_data = (void *) user_data;
cb->priority = priority;
cb->item_array = array;
cb->func_array = EINA_TRUE;
cb->delete_me = EINA_FALSE;
_eo_callbacks_sorted_insert(pd, cb,it->desc);
}
cb = calloc(1, sizeof(*cb));
if (!cb) return;
cb->func_data = (void *) user_data;
cb->priority = priority;
cb->items.item_array = array;
cb->func_array = EINA_TRUE;
_eo_callbacks_sorted_insert(pd, cb);
{
eo_do(obj, eo_event_callback_call(EO_EV_CALLBACK_ADD, (void *)array); );
eo_do(obj, eo_event_callback_call(EO_EV_CALLBACK_ADD, (void *)array) );
}
}
@ -620,108 +764,118 @@ _eo_base_event_callback_array_del(Eo *obj, Eo_Base_Data *pd,
{
Eo_Callback_Description *cb;
for (cb = pd->callbacks; cb; cb = cb->next)
Eo_Event_Callbacks *cbs;
int count = 0;
if (!pd->callbacks) goto end;
EINA_INARRAY_FOREACH(pd->callbacks, cbs)
{
if ((cb->items.item_array == array) && (cb->func_data == user_data))
{
cb->delete_me = EINA_TRUE;
pd->deletions_waiting = EINA_TRUE;
_eo_callbacks_clear(pd);
eo_do(obj, eo_event_callback_call(EO_EV_CALLBACK_DEL, (void *)array); );
return;
for (cb = cbs->callbacks; cb; cb = cb->next)
{
if ((cb->item_array == array) && (cb->func_data == user_data))
{
cb->delete_me = EINA_TRUE;
pd->deletions_waiting = EINA_TRUE;
count++;
}
}
}
if (count > 0)
{
_eo_callbacks_clear(pd);
eo_do(obj, eo_event_callback_call(EO_EV_CALLBACK_DEL, (void *)array) );
return;
}
end:
DBG("Callback of object %p with function array %p and data %p not found.", obj, array, user_data);
}
static Eina_Bool
_cb_desc_match(const Eo_Event_Description *a, const Eo_Event_Description *b)
{
if (!a)
return EINA_FALSE;
/* If either is legacy, fallback to string comparison. */
if ((a->doc == _legacy_event_desc) || (b->doc == _legacy_event_desc))
{
/* Take stringshare shortcut if both are legacy */
if (a->doc == b->doc)
{
return (a->name == b->name);
}
else
{
return !strcmp(a->name, b->name);
}
}
else
{
return (a == b);
}
}
EOLIAN static Eina_Bool
_eo_base_event_callback_call(Eo *obj_id, Eo_Base_Data *pd,
const Eo_Event_Description *desc,
void *event_info)
const Eo_Event_Description *desc,
void *event_info)
{
Eina_Bool ret;
Eo_Callback_Description *cb;
EO_OBJ_POINTER_RETURN_VAL(obj_id, obj, EINA_FALSE);
if(!desc){
printf("call bad event!");
return EINA_FALSE;
}
pd->called_counter++;//avi debug
clock_t start_time = clock();
Eo_Event_Callbacks *cbs;
Eina_Bool found = EINA_FALSE;
Eina_Stringshare *event_name;
if (desc->doc != _legacy_event_desc)
{
event_name = eina_stringshare_add(desc->name);
}
else{
event_name = desc->name;
}
Eo_Event_Callbacks ec = { desc,event_name , NULL };
if( pd->callbacks->len < 7 ){ //if small array simple search will be faster
EINA_INARRAY_FOREACH(pd->callbacks, cbs)
{
pd->called_loop_counter++;//avi debug
// if(_cb_desc_match(desc, cbs->event))
if(event_name == cbs->event_name)
{
found = EINA_TRUE;
break;
}
}
if(found==EINA_FALSE) {pd->called_sum_clocks +=clock()-start_time;//avi dbg
return EINA_FALSE;}
}
else{
int index = eina_inarray_search_sorted ( pd->callbacks, &ec , _eo_base_event_compare );
if(index==-1) {pd->called_sum_clocks +=clock()-start_time;//avi dbg
return EINA_FALSE;}
cbs =eina_inarray_nth(pd->callbacks , index );
}
ret = EINA_TRUE;
_eo_ref(obj);
pd->walking_list++;
for (cb = pd->callbacks; cb; cb = cb->next)
for (cb = cbs->callbacks; cb; cb = cb->next)
{
pd->called_loop_counter++;//avi debug
if (!cb->delete_me)
{
if (cb->func_array)
if (( !cb->items.item.desc->unfreezable) &&
(event_freeze_count || pd->event_freeze_count))
continue;
unsigned int before_func=clock();
/* Abort callback calling if the func says so. */
if (!cb->items.item.func((void *) cb->func_data, obj_id, desc,
(void *) event_info))
{
const Eo_Callback_Array_Item *it;
for (it = cb->items.item_array; it->func; it++)
{
if (!_cb_desc_match(it->desc, desc))
continue;
if (!it->desc->unfreezable &&
(event_freeze_count || pd->event_freeze_count))
continue;
/* Abort callback calling if the func says so. */
if (!it->func((void *) cb->func_data, obj_id, desc,
(void *) event_info))
{
ret = EINA_FALSE;
goto end;
}
}
}
else
{
if (!_cb_desc_match(cb->items.item.desc, desc))
continue;
if ((!cb->items.item.desc
|| !cb->items.item.desc->unfreezable) &&
(event_freeze_count || pd->event_freeze_count))
continue;
/* Abort callback calling if the func says so. */
if (!cb->items.item.func((void *) cb->func_data, obj_id, desc,
(void *) event_info))
{
ret = EINA_FALSE;
goto end;
}
ret = EINA_FALSE;
start_time+=clock()-before_func;
goto end;
}
start_time+=clock()-before_func;
}
}
end:
pd->called_sum_clocks +=clock()-start_time;//avi dbg
pd->walking_list--;
_eo_callbacks_clear(pd);
_eo_unref(obj);
@ -965,11 +1119,36 @@ EAPI const Eina_Value_Type *EO_DBG_INFO_TYPE = &_EO_DBG_INFO_TYPE;
/* EO_BASE_CLASS stuff */
#define MY_CLASS EO_BASE_CLASS
static __attribute__((destructor)) void finish(void)
{
printf("calbacks stats-All objects!: num objects=%u total time=%f \
called cal times= %u called loops=%u called clocks=%f called sec=%f \
callbacks count=%u events counter=%u legacy_events_inserted=%u regular_events_inserted=%u \n",
objects_counter,(double)(clock()-start_clock)/CLOCKS_PER_SEC, called_counter,
called_loop_counter,(double)called_sum_clocks,
(double)called_sum_clocks/CLOCKS_PER_SEC, callbacks_counter ,
events_counter, legacy_events_inserted, regular_events_inserted
);//avi debug
}
EOLIAN static void
_eo_base_constructor(Eo *obj, Eo_Base_Data *pd EINA_UNUSED)
{
DBG("%p - %s.", obj, eo_class_name_get(MY_CLASS));
pd->callbacks = eina_inarray_new(sizeof(Eo_Event_Callbacks), 10 );//added by avi
pd->called_counter=0;
pd->callbacks_counter=0;
pd-> called_loop_counter=0;
pd-> called_loop_counter=0;
pd-> called_sum_clocks =0;
pd->events_counter=0;
pd->have_events = 0;
_eo_condtor_done(obj);
}
@ -979,14 +1158,30 @@ _eo_base_destructor(Eo *obj, Eo_Base_Data *pd)
Eo *child;
DBG("%p - %s.", obj, eo_class_name_get(MY_CLASS));
if( pd->callbacks_counter>0 ){//only with atleast one calllbacks
called_counter+=pd->called_counter;
callbacks_counter+=pd->callbacks_counter;
called_loop_counter+= pd->called_loop_counter;
arrays_counter+=pd->arrays_counter;
called_inner_loop_counter+=pd->called_inner_loop_counter;
called_sum_clocks+=pd-> called_sum_clocks;
events_counter+=pd->events_counter;
objects_counter++;
}
EINA_LIST_FREE(pd->children, child)
eo_do(child, eo_parent_set(NULL));
_eo_generic_data_del_all(pd);
_wref_destruct(pd);
_eo_callback_remove_all(pd);
eina_inarray_free(pd->callbacks);//added by avi
pd->callbacks = NULL;
_eo_condtor_done(obj);
}