efl/src/lib/ecore/ecore_idle_enterer.c

314 lines
9.1 KiB
C
Raw Normal View History

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <Eo.h>
#include "Ecore.h"
#include "ecore_private.h"
#define MY_CLASS ECORE_IDLE_ENTERER_CLASS
#define MY_CLASS_NAME "ecore_idle_enterer"
EAPI Eo_Op ECORE_IDLE_ENTERER_BASE_ID = EO_NOOP;
struct _Ecore_Idle_Enterer_Private_Data
{
EINA_INLIST;
Ecore_Idle_Enterer *obj;
Ecore_Task_Cb func;
void *data;
int references;
Eina_Bool delete_me : 1;
};
typedef struct _Ecore_Idle_Enterer_Private_Data Ecore_Idle_Enterer_Private_Data;
static Ecore_Idle_Enterer_Private_Data *idle_enterers = NULL;
static Ecore_Idle_Enterer_Private_Data *idle_enterer_current = NULL;
static int idle_enterers_delete_me = 0;
static void *
_ecore_idle_enterer_del(Ecore_Idle_Enterer *idle_enterer);
2010-10-17 00:03:28 -07:00
/**
* @addtogroup Ecore_Idle_Group
2010-10-17 00:03:28 -07:00
*
* @{
*/
static Eina_Bool
_ecore_idle_enterer_add(Ecore_Idle_Enterer *obj,
Ecore_Idle_Enterer_Private_Data *ie,
Ecore_Task_Cb func,
const void *data)
{
if (EINA_UNLIKELY(!eina_main_loop_is()))
{
eo_error_set(obj);
EINA_MAIN_LOOP_CHECK_RETURN_VAL(EINA_FALSE);
}
ie->obj = obj;
eo_do_super(obj, eo_constructor());
eo_manual_free_set(obj, EINA_TRUE);
if (!func)
{
eo_error_set(obj);
ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
return EINA_FALSE;
}
ie->func = func;
ie->data = (void *)data;
return EINA_TRUE;
}
/**
* Add an idle enterer handler.
2004-05-07 21:44:04 -07:00
* @param func The function to call when entering an idle state.
* @param data The data to be passed to the @p func call
* @return A handle to the idle enterer callback if successful. Otherwise,
* NULL is returned.
* @note The function func will be called every time the main loop is entering
* idle state, as long as it returns 1 (or ECORE_CALLBACK_RENEW). A return of 0
* (or ECORE_CALLBACK_CANCEL) deletes the idle enterer.
*/
EAPI Ecore_Idle_Enterer *
ecore_idle_enterer_add(Ecore_Task_Cb func,
const void *data)
{
Ecore_Idle_Enterer *ie = NULL;
ie = eo_add_custom(MY_CLASS, _ecore_parent, ecore_idle_enterer_after_constructor(func, data));
eo_unref(ie);
return ie;
}
static void
_idle_enterer_after_constructor(Eo *obj, void *_pd, va_list *list)
{
Ecore_Task_Cb func = va_arg(*list, Ecore_Task_Cb);
const void *data = va_arg(*list, const void *);
_ecore_lock();
Ecore_Idle_Enterer_Private_Data *ie = _pd;
if (!_ecore_idle_enterer_add(obj, ie, func, data)) goto unlock;
idle_enterers = (Ecore_Idle_Enterer_Private_Data *)eina_inlist_append(EINA_INLIST_GET(idle_enterers), EINA_INLIST_GET(ie));
unlock:
_ecore_unlock();
}
e: 1. configure/build changes to allow cross-compiling painlessly 2. pager module namespace changes - this was still dirty afdter the namespace cleanup, so clean it up 3. add a powersave subsystem - doesnt have an "automatic" way to turn on and off right now, this i think is best provided by modules (that do things like monitor acpi status's (eg close lid of laptop), AC power status etc. etc. this allows e to nicely defer "power" expensive actions to avoid disk spinups etc. 4. move to use the new ecore poller system - discussed long ago as part of power management/saving issues. now it exists 5. add a canvas idle flush call that helsp cope with the new shm greedy software x11 engine stuff 6. use the new powersave subsystem where appropriate 7. fix non-zeroed/initted memory access in e_fm_main 8. fix mem leak for e menus 9. remove ipc handlers for changed/removed config values 10. use animaotr not timer for menu scrolls - then menu scrolls obey the fps config 11. fix up timer/poll happienss of cursor idle stuff 12. remove avoid damage from popups for now - causing problems 13. change battery and temp readouts to b e shorter so they fit 14. pager can emit signals on focus change for mini-windows now 15. temperature module now uses a slave process and uses stdin/out to talk to it and get output - this makes e smoother as in my expereicne i found getting the temp on my laptop actually took like 200ms so e "hang" for 200ms while reading the acpi files - so now the subprocess does it and just writesa back to e when it gets it. ecore: 1. add ecore_pollers. see the documentation on them in doxygen comments :) 2. fix timers to only go off when they have to - bug there that made e's select time out a LOT more than it needed to. defensive coding hid the problem. now fixed. e should be much more power friendly now. 3. formatting/niceness in ecore_exe stuff 4. some comments on comments with SIGIO ideas vs. select 5. add call to be able to add an idle enterer at the start of the list of them, not just the end (as has been the default) 6. fix ecore_evas to support auto evas idler calls after 0.5 secs of idle in all canvases - and to do it right 7. if argb destination - set the shape EVENT shape (to mask out events in transparent regions much like shape does withotu translucency) 8. in ecore_x add support for the event shape evas: 1. fix cache to work properly and not just always fill up (as it seemed to like to think cahce useage dropped below 0 when it didnt and thus just over-fill) 2. software x11 engine now ONLY uses shm segments - no ximages over the socket. this ximage hack was there to avoid the 2 round trips involved in setting up an shm image - now i mitigated that wih an shm image cache pool. it keeps shm images around and repurposes them for new update regions if appropriate. this means many fewer shm creates (about 1/100th the number) and since we recycle the memory less 0 memory page filling by the kernel - in the end, i recorded about a 10-20% speedup over the old software x11 engine. simple tests i have seen up to 120% speedups. idle flush now does something - it frees all the cached shm segments. it has a hard-coded limit of 4mb worth of shm segments (or 32 segments - whichever comes first) to keep around. once can never complain much about speedups methinks :). also evas will defer sync until the NEXT frame is written - this means evas can calculate the next frame of data while x dma's/copies the images to the screen at the same time (if you hve a dual core or multi-cpu machnike or your xserver is able to use DMA to copy image data to the screen/video ram then this should see a decent speedup). SVN revision: 33448
2008-01-10 23:33:57 -08:00
/**
* Add an idle enterer handler at the start of the list so it gets called earlier than others.
* @param func The function to call when entering an idle state.
* @param data The data to be passed to the @p func call
* @return A handle to the idle enterer callback if successful. Otherwise,
* NULL is returned.
* @note The function func will be called every time the main loop is entering
* idle state, as long as it returns 1 (or ECORE_CALLBACK_RENEW). A return of 0
* (or ECORE_CALLBACK_CANCEL) deletes the idle enterer.
e: 1. configure/build changes to allow cross-compiling painlessly 2. pager module namespace changes - this was still dirty afdter the namespace cleanup, so clean it up 3. add a powersave subsystem - doesnt have an "automatic" way to turn on and off right now, this i think is best provided by modules (that do things like monitor acpi status's (eg close lid of laptop), AC power status etc. etc. this allows e to nicely defer "power" expensive actions to avoid disk spinups etc. 4. move to use the new ecore poller system - discussed long ago as part of power management/saving issues. now it exists 5. add a canvas idle flush call that helsp cope with the new shm greedy software x11 engine stuff 6. use the new powersave subsystem where appropriate 7. fix non-zeroed/initted memory access in e_fm_main 8. fix mem leak for e menus 9. remove ipc handlers for changed/removed config values 10. use animaotr not timer for menu scrolls - then menu scrolls obey the fps config 11. fix up timer/poll happienss of cursor idle stuff 12. remove avoid damage from popups for now - causing problems 13. change battery and temp readouts to b e shorter so they fit 14. pager can emit signals on focus change for mini-windows now 15. temperature module now uses a slave process and uses stdin/out to talk to it and get output - this makes e smoother as in my expereicne i found getting the temp on my laptop actually took like 200ms so e "hang" for 200ms while reading the acpi files - so now the subprocess does it and just writesa back to e when it gets it. ecore: 1. add ecore_pollers. see the documentation on them in doxygen comments :) 2. fix timers to only go off when they have to - bug there that made e's select time out a LOT more than it needed to. defensive coding hid the problem. now fixed. e should be much more power friendly now. 3. formatting/niceness in ecore_exe stuff 4. some comments on comments with SIGIO ideas vs. select 5. add call to be able to add an idle enterer at the start of the list of them, not just the end (as has been the default) 6. fix ecore_evas to support auto evas idler calls after 0.5 secs of idle in all canvases - and to do it right 7. if argb destination - set the shape EVENT shape (to mask out events in transparent regions much like shape does withotu translucency) 8. in ecore_x add support for the event shape evas: 1. fix cache to work properly and not just always fill up (as it seemed to like to think cahce useage dropped below 0 when it didnt and thus just over-fill) 2. software x11 engine now ONLY uses shm segments - no ximages over the socket. this ximage hack was there to avoid the 2 round trips involved in setting up an shm image - now i mitigated that wih an shm image cache pool. it keeps shm images around and repurposes them for new update regions if appropriate. this means many fewer shm creates (about 1/100th the number) and since we recycle the memory less 0 memory page filling by the kernel - in the end, i recorded about a 10-20% speedup over the old software x11 engine. simple tests i have seen up to 120% speedups. idle flush now does something - it frees all the cached shm segments. it has a hard-coded limit of 4mb worth of shm segments (or 32 segments - whichever comes first) to keep around. once can never complain much about speedups methinks :). also evas will defer sync until the NEXT frame is written - this means evas can calculate the next frame of data while x dma's/copies the images to the screen at the same time (if you hve a dual core or multi-cpu machnike or your xserver is able to use DMA to copy image data to the screen/video ram then this should see a decent speedup). SVN revision: 33448
2008-01-10 23:33:57 -08:00
*/
EAPI Ecore_Idle_Enterer *
ecore_idle_enterer_before_add(Ecore_Task_Cb func,
const void *data)
e: 1. configure/build changes to allow cross-compiling painlessly 2. pager module namespace changes - this was still dirty afdter the namespace cleanup, so clean it up 3. add a powersave subsystem - doesnt have an "automatic" way to turn on and off right now, this i think is best provided by modules (that do things like monitor acpi status's (eg close lid of laptop), AC power status etc. etc. this allows e to nicely defer "power" expensive actions to avoid disk spinups etc. 4. move to use the new ecore poller system - discussed long ago as part of power management/saving issues. now it exists 5. add a canvas idle flush call that helsp cope with the new shm greedy software x11 engine stuff 6. use the new powersave subsystem where appropriate 7. fix non-zeroed/initted memory access in e_fm_main 8. fix mem leak for e menus 9. remove ipc handlers for changed/removed config values 10. use animaotr not timer for menu scrolls - then menu scrolls obey the fps config 11. fix up timer/poll happienss of cursor idle stuff 12. remove avoid damage from popups for now - causing problems 13. change battery and temp readouts to b e shorter so they fit 14. pager can emit signals on focus change for mini-windows now 15. temperature module now uses a slave process and uses stdin/out to talk to it and get output - this makes e smoother as in my expereicne i found getting the temp on my laptop actually took like 200ms so e "hang" for 200ms while reading the acpi files - so now the subprocess does it and just writesa back to e when it gets it. ecore: 1. add ecore_pollers. see the documentation on them in doxygen comments :) 2. fix timers to only go off when they have to - bug there that made e's select time out a LOT more than it needed to. defensive coding hid the problem. now fixed. e should be much more power friendly now. 3. formatting/niceness in ecore_exe stuff 4. some comments on comments with SIGIO ideas vs. select 5. add call to be able to add an idle enterer at the start of the list of them, not just the end (as has been the default) 6. fix ecore_evas to support auto evas idler calls after 0.5 secs of idle in all canvases - and to do it right 7. if argb destination - set the shape EVENT shape (to mask out events in transparent regions much like shape does withotu translucency) 8. in ecore_x add support for the event shape evas: 1. fix cache to work properly and not just always fill up (as it seemed to like to think cahce useage dropped below 0 when it didnt and thus just over-fill) 2. software x11 engine now ONLY uses shm segments - no ximages over the socket. this ximage hack was there to avoid the 2 round trips involved in setting up an shm image - now i mitigated that wih an shm image cache pool. it keeps shm images around and repurposes them for new update regions if appropriate. this means many fewer shm creates (about 1/100th the number) and since we recycle the memory less 0 memory page filling by the kernel - in the end, i recorded about a 10-20% speedup over the old software x11 engine. simple tests i have seen up to 120% speedups. idle flush now does something - it frees all the cached shm segments. it has a hard-coded limit of 4mb worth of shm segments (or 32 segments - whichever comes first) to keep around. once can never complain much about speedups methinks :). also evas will defer sync until the NEXT frame is written - this means evas can calculate the next frame of data while x dma's/copies the images to the screen at the same time (if you hve a dual core or multi-cpu machnike or your xserver is able to use DMA to copy image data to the screen/video ram then this should see a decent speedup). SVN revision: 33448
2008-01-10 23:33:57 -08:00
{
Ecore_Idle_Enterer *ie = NULL;
ie = eo_add_custom(MY_CLASS, _ecore_parent, ecore_idle_enterer_before_constructor(func, data));
eo_unref(ie);
return ie;
}
static void
_idle_enterer_before_constructor(Eo *obj, void *_pd, va_list *list)
{
Ecore_Task_Cb func = va_arg(*list, Ecore_Task_Cb);
const void *data = va_arg(*list, const void *);
e: 1. configure/build changes to allow cross-compiling painlessly 2. pager module namespace changes - this was still dirty afdter the namespace cleanup, so clean it up 3. add a powersave subsystem - doesnt have an "automatic" way to turn on and off right now, this i think is best provided by modules (that do things like monitor acpi status's (eg close lid of laptop), AC power status etc. etc. this allows e to nicely defer "power" expensive actions to avoid disk spinups etc. 4. move to use the new ecore poller system - discussed long ago as part of power management/saving issues. now it exists 5. add a canvas idle flush call that helsp cope with the new shm greedy software x11 engine stuff 6. use the new powersave subsystem where appropriate 7. fix non-zeroed/initted memory access in e_fm_main 8. fix mem leak for e menus 9. remove ipc handlers for changed/removed config values 10. use animaotr not timer for menu scrolls - then menu scrolls obey the fps config 11. fix up timer/poll happienss of cursor idle stuff 12. remove avoid damage from popups for now - causing problems 13. change battery and temp readouts to b e shorter so they fit 14. pager can emit signals on focus change for mini-windows now 15. temperature module now uses a slave process and uses stdin/out to talk to it and get output - this makes e smoother as in my expereicne i found getting the temp on my laptop actually took like 200ms so e "hang" for 200ms while reading the acpi files - so now the subprocess does it and just writesa back to e when it gets it. ecore: 1. add ecore_pollers. see the documentation on them in doxygen comments :) 2. fix timers to only go off when they have to - bug there that made e's select time out a LOT more than it needed to. defensive coding hid the problem. now fixed. e should be much more power friendly now. 3. formatting/niceness in ecore_exe stuff 4. some comments on comments with SIGIO ideas vs. select 5. add call to be able to add an idle enterer at the start of the list of them, not just the end (as has been the default) 6. fix ecore_evas to support auto evas idler calls after 0.5 secs of idle in all canvases - and to do it right 7. if argb destination - set the shape EVENT shape (to mask out events in transparent regions much like shape does withotu translucency) 8. in ecore_x add support for the event shape evas: 1. fix cache to work properly and not just always fill up (as it seemed to like to think cahce useage dropped below 0 when it didnt and thus just over-fill) 2. software x11 engine now ONLY uses shm segments - no ximages over the socket. this ximage hack was there to avoid the 2 round trips involved in setting up an shm image - now i mitigated that wih an shm image cache pool. it keeps shm images around and repurposes them for new update regions if appropriate. this means many fewer shm creates (about 1/100th the number) and since we recycle the memory less 0 memory page filling by the kernel - in the end, i recorded about a 10-20% speedup over the old software x11 engine. simple tests i have seen up to 120% speedups. idle flush now does something - it frees all the cached shm segments. it has a hard-coded limit of 4mb worth of shm segments (or 32 segments - whichever comes first) to keep around. once can never complain much about speedups methinks :). also evas will defer sync until the NEXT frame is written - this means evas can calculate the next frame of data while x dma's/copies the images to the screen at the same time (if you hve a dual core or multi-cpu machnike or your xserver is able to use DMA to copy image data to the screen/video ram then this should see a decent speedup). SVN revision: 33448
2008-01-10 23:33:57 -08:00
_ecore_lock();
Ecore_Idle_Enterer_Private_Data *ie = _pd;
if (!_ecore_idle_enterer_add(obj, ie, func, data)) goto unlock;
idle_enterers = (Ecore_Idle_Enterer_Private_Data *)eina_inlist_prepend(EINA_INLIST_GET(idle_enterers), EINA_INLIST_GET(ie));
unlock:
_ecore_unlock();
}
static void
_constructor(Eo *obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED)
{
eo_error_set(obj);
ERR("only custom constructor can be used with '%s' class", MY_CLASS_NAME);
e: 1. configure/build changes to allow cross-compiling painlessly 2. pager module namespace changes - this was still dirty afdter the namespace cleanup, so clean it up 3. add a powersave subsystem - doesnt have an "automatic" way to turn on and off right now, this i think is best provided by modules (that do things like monitor acpi status's (eg close lid of laptop), AC power status etc. etc. this allows e to nicely defer "power" expensive actions to avoid disk spinups etc. 4. move to use the new ecore poller system - discussed long ago as part of power management/saving issues. now it exists 5. add a canvas idle flush call that helsp cope with the new shm greedy software x11 engine stuff 6. use the new powersave subsystem where appropriate 7. fix non-zeroed/initted memory access in e_fm_main 8. fix mem leak for e menus 9. remove ipc handlers for changed/removed config values 10. use animaotr not timer for menu scrolls - then menu scrolls obey the fps config 11. fix up timer/poll happienss of cursor idle stuff 12. remove avoid damage from popups for now - causing problems 13. change battery and temp readouts to b e shorter so they fit 14. pager can emit signals on focus change for mini-windows now 15. temperature module now uses a slave process and uses stdin/out to talk to it and get output - this makes e smoother as in my expereicne i found getting the temp on my laptop actually took like 200ms so e "hang" for 200ms while reading the acpi files - so now the subprocess does it and just writesa back to e when it gets it. ecore: 1. add ecore_pollers. see the documentation on them in doxygen comments :) 2. fix timers to only go off when they have to - bug there that made e's select time out a LOT more than it needed to. defensive coding hid the problem. now fixed. e should be much more power friendly now. 3. formatting/niceness in ecore_exe stuff 4. some comments on comments with SIGIO ideas vs. select 5. add call to be able to add an idle enterer at the start of the list of them, not just the end (as has been the default) 6. fix ecore_evas to support auto evas idler calls after 0.5 secs of idle in all canvases - and to do it right 7. if argb destination - set the shape EVENT shape (to mask out events in transparent regions much like shape does withotu translucency) 8. in ecore_x add support for the event shape evas: 1. fix cache to work properly and not just always fill up (as it seemed to like to think cahce useage dropped below 0 when it didnt and thus just over-fill) 2. software x11 engine now ONLY uses shm segments - no ximages over the socket. this ximage hack was there to avoid the 2 round trips involved in setting up an shm image - now i mitigated that wih an shm image cache pool. it keeps shm images around and repurposes them for new update regions if appropriate. this means many fewer shm creates (about 1/100th the number) and since we recycle the memory less 0 memory page filling by the kernel - in the end, i recorded about a 10-20% speedup over the old software x11 engine. simple tests i have seen up to 120% speedups. idle flush now does something - it frees all the cached shm segments. it has a hard-coded limit of 4mb worth of shm segments (or 32 segments - whichever comes first) to keep around. once can never complain much about speedups methinks :). also evas will defer sync until the NEXT frame is written - this means evas can calculate the next frame of data while x dma's/copies the images to the screen at the same time (if you hve a dual core or multi-cpu machnike or your xserver is able to use DMA to copy image data to the screen/video ram then this should see a decent speedup). SVN revision: 33448
2008-01-10 23:33:57 -08:00
}
/**
2004-05-07 21:44:04 -07:00
* Delete an idle enterer callback.
* @param idle_enterer The idle enterer to delete
* @return The data pointer passed to the idler enterer callback on success.
* NULL otherwise.
*/
EAPI void *
ecore_idle_enterer_del(Ecore_Idle_Enterer *idle_enterer)
{
void *data = NULL;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
_ecore_lock();
data = _ecore_idle_enterer_del(idle_enterer);
_ecore_unlock();
return data;
}
2010-10-17 00:03:28 -07:00
/**
* @}
*/
static void *
_ecore_idle_enterer_del(Ecore_Idle_Enterer *obj)
{
Ecore_Idle_Enterer_Private_Data *idle_enterer = eo_data_get(obj, MY_CLASS);
EINA_SAFETY_ON_TRUE_RETURN_VAL(idle_enterer->delete_me, NULL);
idle_enterer->delete_me = 1;
idle_enterers_delete_me = 1;
return idle_enterer->data;
}
static void
_destructor(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
{
Ecore_Idle_Enterer_Private_Data *idle_enterer = _pd;
idle_enterer->delete_me = 1;
idle_enterers_delete_me = 1;
eo_do_super(obj, eo_destructor());
}
void
_ecore_idle_enterer_shutdown(void)
{
Ecore_Idle_Enterer_Private_Data *ie;
while ((ie = idle_enterers))
{
idle_enterers = (Ecore_Idle_Enterer_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(idle_enterers), EINA_INLIST_GET(idle_enterers));
eo_parent_set(ie->obj, NULL);
if (eo_destructed_is(ie->obj))
eo_manual_free(ie->obj);
else
eo_manual_free_set(ie->obj, EINA_FALSE);
}
idle_enterers_delete_me = 0;
Fix idle_enterers when using recursive main loops. If an idle_enterer created a recursive main loop (just called ecore_main_loop_begin()), then this recursive main loop should continue to process idle_enterers from there and on, thus idle_enterer_current was added. When going back from recursion, the current iterator should be updated properly. This patch also fixes the deletion of idle_enterers from recursive main loops by reference counting them. This way, the node will not be free()d inside inner loop cleanups and then crash when going back to outer loop. The following test case used to crash but not anymore: #include <Ecore.h> #include <Eina.h> static int _log_dom; #define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__) static Ecore_Idle_Enterer *handle; static int idler(void *data) { INF("idler"); return 1; } static int cb2(void *data) { INF("cb2 - delete cb1 handle"); ecore_idle_enterer_del(handle); ecore_main_loop_quit(); /* quits inner main loop */ return 0; } static int cb1(void *data) { INF("cb1: begin"); INF(" add cb2"); ecore_idle_enterer_add(cb2, NULL); INF(" inner main loop begin (recurse)"); ecore_main_loop_begin(); /* will it crash due ecore_idle_enterer_del(handle) * inside cb2()? It used to! */ INF("cb1: end"); ecore_main_loop_quit(); /* quits outer main loop */ return 0; } int main(void) { ecore_init(); _log_dom = eina_log_domain_register("test", EINA_COLOR_CYAN); /* * Creating a new main loop from inside an idle_enterer callback, * and inside this new (inner) main loop deleting the caller * callback used to crash since the handle would be effectively * free()d, but when the recursion is over the pointer would be * used. */ INF("main: begin"); handle = ecore_idle_enterer_add(cb1, NULL); ecore_idler_add(idler, NULL); ecore_main_loop_begin(); INF("main: end"); return 0; } SVN revision: 46408
2010-02-23 14:13:42 -08:00
idle_enterer_current = NULL;
}
void
_ecore_idle_enterer_call(void)
{
Fix idle_enterers when using recursive main loops. If an idle_enterer created a recursive main loop (just called ecore_main_loop_begin()), then this recursive main loop should continue to process idle_enterers from there and on, thus idle_enterer_current was added. When going back from recursion, the current iterator should be updated properly. This patch also fixes the deletion of idle_enterers from recursive main loops by reference counting them. This way, the node will not be free()d inside inner loop cleanups and then crash when going back to outer loop. The following test case used to crash but not anymore: #include <Ecore.h> #include <Eina.h> static int _log_dom; #define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__) static Ecore_Idle_Enterer *handle; static int idler(void *data) { INF("idler"); return 1; } static int cb2(void *data) { INF("cb2 - delete cb1 handle"); ecore_idle_enterer_del(handle); ecore_main_loop_quit(); /* quits inner main loop */ return 0; } static int cb1(void *data) { INF("cb1: begin"); INF(" add cb2"); ecore_idle_enterer_add(cb2, NULL); INF(" inner main loop begin (recurse)"); ecore_main_loop_begin(); /* will it crash due ecore_idle_enterer_del(handle) * inside cb2()? It used to! */ INF("cb1: end"); ecore_main_loop_quit(); /* quits outer main loop */ return 0; } int main(void) { ecore_init(); _log_dom = eina_log_domain_register("test", EINA_COLOR_CYAN); /* * Creating a new main loop from inside an idle_enterer callback, * and inside this new (inner) main loop deleting the caller * callback used to crash since the handle would be effectively * free()d, but when the recursion is over the pointer would be * used. */ INF("main: begin"); handle = ecore_idle_enterer_add(cb1, NULL); ecore_idler_add(idler, NULL); ecore_main_loop_begin(); INF("main: end"); return 0; } SVN revision: 46408
2010-02-23 14:13:42 -08:00
if (!idle_enterer_current)
{
2010-09-29 23:09:20 -07:00
/* regular main loop, start from head */
idle_enterer_current = idle_enterers;
Fix idle_enterers when using recursive main loops. If an idle_enterer created a recursive main loop (just called ecore_main_loop_begin()), then this recursive main loop should continue to process idle_enterers from there and on, thus idle_enterer_current was added. When going back from recursion, the current iterator should be updated properly. This patch also fixes the deletion of idle_enterers from recursive main loops by reference counting them. This way, the node will not be free()d inside inner loop cleanups and then crash when going back to outer loop. The following test case used to crash but not anymore: #include <Ecore.h> #include <Eina.h> static int _log_dom; #define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__) static Ecore_Idle_Enterer *handle; static int idler(void *data) { INF("idler"); return 1; } static int cb2(void *data) { INF("cb2 - delete cb1 handle"); ecore_idle_enterer_del(handle); ecore_main_loop_quit(); /* quits inner main loop */ return 0; } static int cb1(void *data) { INF("cb1: begin"); INF(" add cb2"); ecore_idle_enterer_add(cb2, NULL); INF(" inner main loop begin (recurse)"); ecore_main_loop_begin(); /* will it crash due ecore_idle_enterer_del(handle) * inside cb2()? It used to! */ INF("cb1: end"); ecore_main_loop_quit(); /* quits outer main loop */ return 0; } int main(void) { ecore_init(); _log_dom = eina_log_domain_register("test", EINA_COLOR_CYAN); /* * Creating a new main loop from inside an idle_enterer callback, * and inside this new (inner) main loop deleting the caller * callback used to crash since the handle would be effectively * free()d, but when the recursion is over the pointer would be * used. */ INF("main: begin"); handle = ecore_idle_enterer_add(cb1, NULL); ecore_idler_add(idler, NULL); ecore_main_loop_begin(); INF("main: end"); return 0; } SVN revision: 46408
2010-02-23 14:13:42 -08:00
}
else
{
2010-09-29 23:09:20 -07:00
/* recursive main loop, continue from where we were */
idle_enterer_current =
(Ecore_Idle_Enterer_Private_Data *)EINA_INLIST_GET(idle_enterer_current)->next;
Fix idle_enterers when using recursive main loops. If an idle_enterer created a recursive main loop (just called ecore_main_loop_begin()), then this recursive main loop should continue to process idle_enterers from there and on, thus idle_enterer_current was added. When going back from recursion, the current iterator should be updated properly. This patch also fixes the deletion of idle_enterers from recursive main loops by reference counting them. This way, the node will not be free()d inside inner loop cleanups and then crash when going back to outer loop. The following test case used to crash but not anymore: #include <Ecore.h> #include <Eina.h> static int _log_dom; #define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__) static Ecore_Idle_Enterer *handle; static int idler(void *data) { INF("idler"); return 1; } static int cb2(void *data) { INF("cb2 - delete cb1 handle"); ecore_idle_enterer_del(handle); ecore_main_loop_quit(); /* quits inner main loop */ return 0; } static int cb1(void *data) { INF("cb1: begin"); INF(" add cb2"); ecore_idle_enterer_add(cb2, NULL); INF(" inner main loop begin (recurse)"); ecore_main_loop_begin(); /* will it crash due ecore_idle_enterer_del(handle) * inside cb2()? It used to! */ INF("cb1: end"); ecore_main_loop_quit(); /* quits outer main loop */ return 0; } int main(void) { ecore_init(); _log_dom = eina_log_domain_register("test", EINA_COLOR_CYAN); /* * Creating a new main loop from inside an idle_enterer callback, * and inside this new (inner) main loop deleting the caller * callback used to crash since the handle would be effectively * free()d, but when the recursion is over the pointer would be * used. */ INF("main: begin"); handle = ecore_idle_enterer_add(cb1, NULL); ecore_idler_add(idler, NULL); ecore_main_loop_begin(); INF("main: end"); return 0; } SVN revision: 46408
2010-02-23 14:13:42 -08:00
}
Fix idle_enterers when using recursive main loops. If an idle_enterer created a recursive main loop (just called ecore_main_loop_begin()), then this recursive main loop should continue to process idle_enterers from there and on, thus idle_enterer_current was added. When going back from recursion, the current iterator should be updated properly. This patch also fixes the deletion of idle_enterers from recursive main loops by reference counting them. This way, the node will not be free()d inside inner loop cleanups and then crash when going back to outer loop. The following test case used to crash but not anymore: #include <Ecore.h> #include <Eina.h> static int _log_dom; #define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__) static Ecore_Idle_Enterer *handle; static int idler(void *data) { INF("idler"); return 1; } static int cb2(void *data) { INF("cb2 - delete cb1 handle"); ecore_idle_enterer_del(handle); ecore_main_loop_quit(); /* quits inner main loop */ return 0; } static int cb1(void *data) { INF("cb1: begin"); INF(" add cb2"); ecore_idle_enterer_add(cb2, NULL); INF(" inner main loop begin (recurse)"); ecore_main_loop_begin(); /* will it crash due ecore_idle_enterer_del(handle) * inside cb2()? It used to! */ INF("cb1: end"); ecore_main_loop_quit(); /* quits outer main loop */ return 0; } int main(void) { ecore_init(); _log_dom = eina_log_domain_register("test", EINA_COLOR_CYAN); /* * Creating a new main loop from inside an idle_enterer callback, * and inside this new (inner) main loop deleting the caller * callback used to crash since the handle would be effectively * free()d, but when the recursion is over the pointer would be * used. */ INF("main: begin"); handle = ecore_idle_enterer_add(cb1, NULL); ecore_idler_add(idler, NULL); ecore_main_loop_begin(); INF("main: end"); return 0; } SVN revision: 46408
2010-02-23 14:13:42 -08:00
while (idle_enterer_current)
{
Ecore_Idle_Enterer_Private_Data *ie = (Ecore_Idle_Enterer_Private_Data *)idle_enterer_current;
2010-09-29 23:09:20 -07:00
if (!ie->delete_me)
{
ie->references++;
if (!_ecore_call_task_cb(ie->func, ie->data))
2010-09-29 23:09:20 -07:00
{
if (!ie->delete_me) _ecore_idle_enterer_del(ie->obj);
2010-09-29 23:09:20 -07:00
}
ie->references--;
}
if (idle_enterer_current) /* may have changed in recursive main loops */
idle_enterer_current =
(Ecore_Idle_Enterer_Private_Data *)EINA_INLIST_GET(idle_enterer_current)->next;
}
if (idle_enterers_delete_me)
{
Ecore_Idle_Enterer_Private_Data *l;
2010-09-29 23:09:20 -07:00
int deleted_idler_enterers_in_use = 0;
for (l = idle_enterers; l; )
2010-09-29 23:09:20 -07:00
{
Ecore_Idle_Enterer_Private_Data *ie = l;
l = (Ecore_Idle_Enterer_Private_Data *)EINA_INLIST_GET(l)->next;
2010-09-29 23:09:20 -07:00
if (ie->delete_me)
{
if (ie->references)
{
deleted_idler_enterers_in_use++;
continue;
}
idle_enterers = (Ecore_Idle_Enterer_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(idle_enterers), EINA_INLIST_GET(ie));
eo_parent_set(ie->obj, NULL);
if (eo_destructed_is(ie->obj))
eo_manual_free(ie->obj);
else
eo_manual_free_set(ie->obj, EINA_FALSE);
2010-09-29 23:09:20 -07:00
}
}
if (!deleted_idler_enterers_in_use)
idle_enterers_delete_me = 0;
}
}
int
_ecore_idle_enterer_exist(void)
{
if (idle_enterers) return 1;
return 0;
}
static void
_class_constructor(Eo_Class *klass)
{
const Eo_Op_Func_Description func_desc[] = {
EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
EO_OP_FUNC(ECORE_IDLE_ENTERER_ID(ECORE_IDLE_ENTERER_SUB_ID_AFTER_CONSTRUCTOR), _idle_enterer_after_constructor),
EO_OP_FUNC(ECORE_IDLE_ENTERER_ID(ECORE_IDLE_ENTERER_SUB_ID_BEFORE_CONSTRUCTOR), _idle_enterer_before_constructor),
EO_OP_FUNC_SENTINEL
};
eo_class_funcs_set(klass, func_desc);
}
static const Eo_Op_Description op_desc[] = {
EO_OP_DESCRIPTION(ECORE_IDLE_ENTERER_SUB_ID_AFTER_CONSTRUCTOR, "Add an idle enterer handler."),
EO_OP_DESCRIPTION(ECORE_IDLE_ENTERER_SUB_ID_BEFORE_CONSTRUCTOR, "Add an idle enterer handler at the start of the list so it gets called earlier than others."),
EO_OP_DESCRIPTION_SENTINEL
};
static const Eo_Class_Description class_desc = {
EO_VERSION,
MY_CLASS_NAME,
EO_CLASS_TYPE_REGULAR,
EO_CLASS_DESCRIPTION_OPS(&ECORE_IDLE_ENTERER_BASE_ID, op_desc, ECORE_IDLE_ENTERER_SUB_ID_LAST),
NULL,
sizeof(Ecore_Idle_Enterer_Private_Data),
_class_constructor,
NULL
};
EO_DEFINE_CLASS(ecore_idle_enterer_class_get, &class_desc, EO_BASE_CLASS, NULL)