1 #include "evas_common.h"
2 #include "evas_private.h"
4 #ifdef BUILD_ASYNC_EVENTS
11 static int _fd_write = -1;
12 static int _fd_read = -1;
14 static int _init_evas_event = 0;
15 static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
17 typedef struct _Evas_Event_Async Evas_Event_Async;
18 struct _Evas_Event_Async
20 void (*func)(void *target, Evas_Callback_Type type, void *event_info);
22 Evas_Callback_Type type;
29 evas_async_events_init(void)
31 #ifdef BUILD_ASYNC_EVENTS
35 if (_init_evas_event > 1) return _init_evas_event;
37 if (pipe(filedes) == -1)
43 _fd_read = filedes[0];
44 _fd_write = filedes[1];
46 fcntl(_fd_read, F_SETFL, O_NONBLOCK);
48 return _init_evas_event;
55 evas_async_events_shutdown(void)
57 #ifdef BUILD_ASYNC_EVENTS
59 if (_init_evas_event > 0) return _init_evas_event;
66 return _init_evas_event;
73 evas_async_events_fd_get(void)
75 #ifdef BUILD_ASYNC_EVENTS
83 evas_async_events_process(void)
85 #ifdef BUILD_ASYNC_EVENTS
86 static Evas_Event_Async current;
91 if (_fd_read == -1) return 0;
95 check = read(_fd_read, ((char*) ¤t) + size, sizeof(current) - size);
100 if (size == sizeof(current))
102 if (current.func) current.func(current.target, current.type, current.event_info);
127 evas_async_events_put(void *target, Evas_Callback_Type type, void *event_info, void (*func)(void *target, Evas_Callback_Type type, void *event_info))
129 #ifdef BUILD_ASYNC_EVENTS
130 Evas_Event_Async new;
133 Evas_Bool result = 0;
136 if (_fd_write == -1) return 0;
141 new.event_info = event_info;
143 pthread_mutex_lock(&_mutex);
146 check = write(_fd_write, ((char*)&new) + offset, sizeof(new) - offset);
148 } while (offset != sizeof(new) && (errno == EINTR || errno == EAGAIN));
150 if (offset == sizeof(new))
162 pthread_mutex_unlock(&_mutex);