summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorUlisses Furquim <ulisses@profusion.mobi>2013-01-06 01:58:50 +0000
committerUlisses Furquim <ulisses@profusion.mobi>2013-01-06 01:58:50 +0000
commit7904f59248e0bce31d0807e4581c1839e1caf6e0 (patch)
tree12b1f3e95a4aba56c39a1e8a6d7a0416e9668000 /src
parenta8dc24710849e4bc282684c39b2bcbef237a0ad3 (diff)
evas/async_events: fix leak of events array and simplify code
Fixed leak of 'memory' array (now async_events_cache) and simplified code of evas_async_events_put(). SVN revision: 82295
Diffstat (limited to 'src')
-rw-r--r--src/lib/evas/canvas/evas_async_events.c117
1 files changed, 60 insertions, 57 deletions
diff --git a/src/lib/evas/canvas/evas_async_events.c b/src/lib/evas/canvas/evas_async_events.c
index 39f0f9f001..ebf81cdcfa 100644
--- a/src/lib/evas/canvas/evas_async_events.c
+++ b/src/lib/evas/canvas/evas_async_events.c
@@ -11,15 +11,6 @@
11#include "evas_common.h" 11#include "evas_common.h"
12#include "evas_private.h" 12#include "evas_private.h"
13 13
14static int _fd_write = -1;
15static int _fd_read = -1;
16static pid_t _fd_pid = 0;
17
18static Eina_Lock async_lock;
19static Eina_Inarray async_queue;
20
21static int _init_evas_event = 0;
22
23typedef struct _Evas_Event_Async Evas_Event_Async; 14typedef struct _Evas_Event_Async Evas_Event_Async;
24 15
25struct _Evas_Event_Async 16struct _Evas_Event_Async
@@ -30,6 +21,17 @@ struct _Evas_Event_Async
30 Evas_Callback_Type type; 21 Evas_Callback_Type type;
31}; 22};
32 23
24static int _fd_write = -1;
25static int _fd_read = -1;
26static pid_t _fd_pid = 0;
27
28static Eina_Lock async_lock;
29static Eina_Inarray async_queue;
30static Evas_Event_Async *async_queue_cache = NULL;
31static unsigned int async_queue_cache_max = 0;
32
33static int _init_evas_event = 0;
34
33Eina_Bool 35Eina_Bool
34_evas_fd_close_on_exec(int fd) 36_evas_fd_close_on_exec(int fd)
35{ 37{
@@ -59,7 +61,7 @@ evas_async_events_init(void)
59 if (_init_evas_event > 1) return _init_evas_event; 61 if (_init_evas_event > 1) return _init_evas_event;
60 62
61 _fd_pid = getpid(); 63 _fd_pid = getpid();
62 64
63 if (pipe(filedes) == -1) 65 if (pipe(filedes) == -1)
64 { 66 {
65 _init_evas_event = 0; 67 _init_evas_event = 0;
@@ -86,14 +88,15 @@ evas_async_events_shutdown(void)
86 _init_evas_event--; 88 _init_evas_event--;
87 if (_init_evas_event > 0) return _init_evas_event; 89 if (_init_evas_event > 0) return _init_evas_event;
88 90
91 eina_lock_free(&async_lock);
92 eina_inarray_flush(&async_queue);
93 free(async_queue_cache);
94
89 close(_fd_read); 95 close(_fd_read);
90 close(_fd_write); 96 close(_fd_write);
91 _fd_read = -1; 97 _fd_read = -1;
92 _fd_write = -1; 98 _fd_write = -1;
93 99
94 eina_lock_free(&async_lock);
95 eina_inarray_flush(&async_queue);
96
97 return _init_evas_event; 100 return _init_evas_event;
98} 101}
99 102
@@ -101,7 +104,7 @@ static void
101_evas_async_events_fork_handle(void) 104_evas_async_events_fork_handle(void)
102{ 105{
103 int i, count = _init_evas_event; 106 int i, count = _init_evas_event;
104 107
105 if (getpid() == _fd_pid) return; 108 if (getpid() == _fd_pid) return;
106 for (i = 0; i < count; i++) evas_async_events_shutdown(); 109 for (i = 0; i < count; i++) evas_async_events_shutdown();
107 for (i = 0; i < count; i++) evas_async_events_init(); 110 for (i = 0; i < count; i++) evas_async_events_init();
@@ -117,42 +120,42 @@ evas_async_events_fd_get(void)
117static int 120static int
118_evas_async_events_process_single(void) 121_evas_async_events_process_single(void)
119{ 122{
120 int wakeup; 123 int ret, wakeup;
121 int ret;
122 124
123 ret = read(_fd_read, &wakeup, sizeof(int)); 125 ret = read(_fd_read, &wakeup, sizeof(int));
124 if (ret == sizeof(int)) 126 if (ret == sizeof(int))
125 { 127 {
126 static Evas_Event_Async *memory = NULL;
127 static unsigned int memory_max = 0;
128 Evas_Event_Async *ev; 128 Evas_Event_Async *ev;
129 unsigned int len; 129 unsigned int len, max;
130 unsigned int max;
131 130
132 eina_lock_take(&async_lock); 131 eina_lock_take(&async_lock);
133 132
134 ev = async_queue.members; 133 ev = async_queue.members;
135 async_queue.members = memory; 134 async_queue.members = async_queue_cache;
136 memory = ev; 135 async_queue_cache = ev;
137 136
138 max = async_queue.max; 137 max = async_queue.max;
139 async_queue.max = memory_max; 138 async_queue.max = async_queue_cache_max;
140 memory_max = max; 139 async_queue_cache_max = max;
141 140
142 len = async_queue.len; 141 len = async_queue.len;
143 async_queue.len = 0; 142 async_queue.len = 0;
144 143
145 eina_lock_release(&async_lock); 144 eina_lock_release(&async_lock);
146 145
146 DBG("Evas async events queue length: %u", len);
147
147 while (len > 0) 148 while (len > 0)
148 { 149 {
149 if (ev->func) ev->func((void *)ev->target, ev->type, ev->event_info); 150 if (ev->func) ev->func((void *)ev->target, ev->type, ev->event_info);
150 ev++; 151 ev++;
151 len--; 152 len--;
152 } 153 }
153 ret = 1; 154
155 return 1;
154 } 156 }
155 else if (ret < 0) 157
158 if (ret < 0)
156 { 159 {
157 switch (errno) 160 switch (errno)
158 { 161 {
@@ -213,12 +216,11 @@ EAPI Eina_Bool
213evas_async_events_put(const void *target, Evas_Callback_Type type, void *event_info, Evas_Async_Events_Put_Cb func) 216evas_async_events_put(const void *target, Evas_Callback_Type type, void *event_info, Evas_Async_Events_Put_Cb func)
214{ 217{
215 Evas_Event_Async *ev; 218 Evas_Event_Async *ev;
216 ssize_t check = sizeof (int); 219 ssize_t check;
217 Eina_Bool result = EINA_FALSE;
218 int count; 220 int count;
219 221
220 if (!func) return 0; 222 if (!func) return EINA_FALSE;
221 if (_fd_write == -1) return 0; 223 if (_fd_write == -1) return EINA_FALSE;
222 224
223 _evas_async_events_fork_handle(); 225 _evas_async_events_fork_handle();
224 226
@@ -226,43 +228,44 @@ evas_async_events_put(const void *target, Evas_Callback_Type type, void *event_i
226 228
227 count = async_queue.len; 229 count = async_queue.len;
228 ev = eina_inarray_grow(&async_queue, 1); 230 ev = eina_inarray_grow(&async_queue, 1);
229 if (ev) 231 if (!ev)
230 { 232 {
231 ev->func = func; 233 eina_lock_release(&async_lock);
232 ev->target = target; 234 return EINA_FALSE;
233 ev->type = type;
234 ev->event_info = event_info;
235 } 235 }
236 236
237 ev->func = func;
238 ev->target = target;
239 ev->type = type;
240 ev->event_info = event_info;
241
237 eina_lock_release(&async_lock); 242 eina_lock_release(&async_lock);
238 243
239 if (count == 0 && ev) 244 if (count == 0)
240 { 245 {
241 int wakeup = 1; 246 int wakeup = 1;
242 247
243 do 248 do
244 { 249 {
245 check = write(_fd_write, &wakeup, sizeof (int)); 250 check = write(_fd_write, &wakeup, sizeof (int));
246 } 251 }
247 while ((check != sizeof (int)) && 252 while ((check != sizeof (int)) &&
248 ((errno == EINTR) || (errno == EAGAIN))); 253 ((errno == EINTR) || (errno == EAGAIN)));
249 } 254 }
250 255
251 evas_cache_image_wakeup(); 256 evas_cache_image_wakeup();
252 257
253 if (check == sizeof (int)) 258 if ((count > 0) || (check == sizeof (int)))
254 result = EINA_TRUE; 259 return EINA_TRUE;
255 else 260
261 switch (errno)
256 { 262 {
257 switch (errno) 263 case EBADF:
258 { 264 case EINVAL:
259 case EBADF: 265 case EIO:
260 case EINVAL: 266 case EPIPE:
261 case EIO: 267 _fd_write = -1;
262 case EPIPE:
263 _fd_write = -1;
264 }
265 } 268 }
266 269
267 return result; 270 return EINA_FALSE;
268} 271}