efl/src/lib/ecore/ecore_idler.c

120 lines
2.6 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"
struct _Ecore_Factorized_Idle
{
Ecore_Task_Cb func;
void *data;
const Efl_Callback_Array_Item *desc;
short references;
Eina_Bool delete_me : 1;
};
void
_ecore_factorized_idle_event_del(void *data, const Efl_Event *event EINA_UNUSED)
{
_ecore_factorized_idle_del(data);
}
void
_ecore_factorized_idle_process(void *data, const Efl_Event *event EINA_UNUSED)
{
Ecore_Factorized_Idle *idler = data;
idler->references++;
if (!_ecore_call_task_cb(idler->func, idler->data))
idler->delete_me = EINA_TRUE;
idler->references--;
if (idler->delete_me &&
idler->references == 0)
_ecore_factorized_idle_del(idler);
}
static Eina_Mempool *idler_mp = NULL;
void *
_ecore_factorized_idle_del(Ecore_Idler *idler)
{
void *data;
2015-03-27 23:43:50 -07:00
if (!idler) return NULL;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
if (idler->references > 0)
{
idler->delete_me = EINA_TRUE;
return idler->data;
}
efl_event_callback_array_del(_mainloop_singleton, idler->desc, idler);
data = idler->data;
eina_mempool_free(idler_mp, idler);
return data;
}
Ecore_Factorized_Idle *
_ecore_factorized_idle_add(const Efl_Callback_Array_Item *desc,
Ecore_Task_Cb func,
const void *data)
{
Ecore_Factorized_Idle *ret;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
if (!func)
{
ERR("callback function must be set up for an object of Ecore_Idler.");
return NULL;
}
if (!idler_mp)
{
idler_mp = eina_mempool_add("chained_mempool", "Ecore_Idle*", NULL, sizeof (Ecore_Factorized_Idle), 23);
if (!idler_mp) return NULL;
}
ret = eina_mempool_malloc(idler_mp, sizeof (Ecore_Factorized_Idle));
if (!ret) return NULL;
ret->func = func;
ret->data = (void*) data;
ret->desc = desc;
ret->references = 0;
ret->delete_me = EINA_FALSE;
efl_event_callback_array_add(_mainloop_singleton, desc, ret);
return ret;
}
/* Specific to Ecore_Idler implementation */
EFL_CALLBACKS_ARRAY_DEFINE(ecore_idler_callbacks,
{ EFL_LOOP_EVENT_IDLE, _ecore_factorized_idle_process },
{ EFL_EVENT_DEL, _ecore_factorized_idle_event_del });
ecore: Rename EAPI macro to ECORE_API in Ecore library Summary: = The Rationale = EAPI was designed to be able to pass `__attribute__ ((visibility ("default")))` for symbols with GCC, which would mean that even if -fvisibility=hidden was used when compiling the library, the needed symbols would get exported. MSVC __almost__ works like GCC (or mingw) in which you can declare everything as export and it will just work (slower, but it will work). But there's a caveat: global variables will not work the same way for MSVC, but works for mingw and GCC. For global variables (as opposed to functions), MSVC requires correct DSO visibility for MSVC: instead of declaring a symbol as export for everything, you need to declare it as import when importing from another DSO and export when defining it locally. With current EAPI definitions, we get the following example working in mingw and MSVC (observe it doesn't define any global variables as exported symbols). Example 1: dll1: ``` EAPI void foo(void); EAPI void bar() { foo(); } ``` dll2: ``` EAPI void foo() { printf ("foo\n"); } ``` This works fine with API defined as __declspec(dllexport) in both cases and for gcc defining as `__atttribute__((visibility("default")))`. However, the following: Example 2: dll1: ``` EAPI extern int foo; EAPI void foobar(void); EAPI void bar() { foo = 5; foobar(); } ``` dll2: ``` EAPI int foo = 0; EAPI void foobar() { printf ("foo %d\n", foo); } ``` This will work on mingw but will not work for MSVC. And that's why EAPI is the only solution that worked for MSVC. Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com> Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev> Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com> Reviewers: vtorri, raster Reviewed By: raster Subscribers: raster, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D12271
2021-05-23 12:08:05 -07:00
ECORE_API Ecore_Idler *
ecore_idler_add(Ecore_Task_Cb func,
const void *data)
{
return _ecore_factorized_idle_add(ecore_idler_callbacks(), func, data);
}
ecore: Rename EAPI macro to ECORE_API in Ecore library Summary: = The Rationale = EAPI was designed to be able to pass `__attribute__ ((visibility ("default")))` for symbols with GCC, which would mean that even if -fvisibility=hidden was used when compiling the library, the needed symbols would get exported. MSVC __almost__ works like GCC (or mingw) in which you can declare everything as export and it will just work (slower, but it will work). But there's a caveat: global variables will not work the same way for MSVC, but works for mingw and GCC. For global variables (as opposed to functions), MSVC requires correct DSO visibility for MSVC: instead of declaring a symbol as export for everything, you need to declare it as import when importing from another DSO and export when defining it locally. With current EAPI definitions, we get the following example working in mingw and MSVC (observe it doesn't define any global variables as exported symbols). Example 1: dll1: ``` EAPI void foo(void); EAPI void bar() { foo(); } ``` dll2: ``` EAPI void foo() { printf ("foo\n"); } ``` This works fine with API defined as __declspec(dllexport) in both cases and for gcc defining as `__atttribute__((visibility("default")))`. However, the following: Example 2: dll1: ``` EAPI extern int foo; EAPI void foobar(void); EAPI void bar() { foo = 5; foobar(); } ``` dll2: ``` EAPI int foo = 0; EAPI void foobar() { printf ("foo %d\n", foo); } ``` This will work on mingw but will not work for MSVC. And that's why EAPI is the only solution that worked for MSVC. Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com> Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev> Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com> Reviewers: vtorri, raster Reviewed By: raster Subscribers: raster, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D12271
2021-05-23 12:08:05 -07:00
ECORE_API void *
ecore_idler_del(Ecore_Idler *idler)
{
return _ecore_factorized_idle_del(idler);
}