summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-03-28 17:18:08 -0700
committerCedric BAIL <cedric.bail@free.fr>2019-04-23 12:40:55 -0700
commit1ec4ad155688df9b1cec8e608481d64e776feae8 (patch)
tree4bf9a809c2b2af4485501f73cee641da5a1d561d /src/lib/ecore
parentafd4e6bd5bf4e06358fe7147b21fc638897c8931 (diff)
ecore: rely on event instead of creating one Eo object per future that need resolving.
This was a terrible oversight, but the point of having a small native type for future was for making them efficient. Still we were using one Eo object for dispatching per future to dispatch new value. I could have gathered all the dispatch with just one object, but at the end we do have one object that notify us of the loop iteration... the loop object! And we have event on that object that we can rely to trigger the dispatching of future without requiring any additional object. So let's do that instead. Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D8567
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/ecore_events.c105
-rw-r--r--src/lib/ecore/ecore_private.h2
2 files changed, 48 insertions, 59 deletions
diff --git a/src/lib/ecore/ecore_events.c b/src/lib/ecore/ecore_events.c
index 15667e9bd9..01a4c3d019 100644
--- a/src/lib/ecore/ecore_events.c
+++ b/src/lib/ecore/ecore_events.c
@@ -12,16 +12,13 @@ typedef struct _Ecore_Future_Schedule_Entry
12 Eina_Future_Schedule_Entry base; 12 Eina_Future_Schedule_Entry base;
13 Eina_Future_Scheduler_Cb cb; 13 Eina_Future_Scheduler_Cb cb;
14 Eina_Future *future; 14 Eina_Future *future;
15 Eo *event;
16 Eina_Value value; 15 Eina_Value value;
17} Ecore_Future_Schedule_Entry; 16} Ecore_Future_Schedule_Entry;
18 17
19////// 18//////
20// XXX: still using legacy ecore events 19// XXX: still using legacy ecore events
21//static Ecore_Event_Handler *future_handler = NULL;
22static Eina_Bool shutting_down = EINA_FALSE; 20static Eina_Bool shutting_down = EINA_FALSE;
23static Eina_Mempool *mp_future_schedule_entry = NULL; 21static Eina_Mempool *mp_future_schedule_entry = NULL;
24//static int ECORE_EV_FUTURE_ID = -1;
25// 22//
26////// 23//////
27 24
@@ -129,52 +126,47 @@ ecore_event_current_event_get(void)
129 return ecore_event_message_handler_current_event_get(_event_msg_handler); 126 return ecore_event_message_handler_current_event_get(_event_msg_handler);
130} 127}
131 128
132/* XXX: 129static void _future_dispatch_cb(void *data, const Efl_Event *ev EINA_UNUSED);
133static Eina_Bool 130static void _event_del_cb(void *data, const Efl_Event *ev);
134ecore_future_dispatched(void *data EINA_UNUSED,
135 int type EINA_UNUSED,
136 void *event)
137{
138 Ecore_Future_Schedule_Entry *entry = event;
139 EINA_SAFETY_ON_NULL_RETURN_VAL(entry, EINA_FALSE);
140 131
141 entry->event = NULL; 132EFL_CALLBACKS_ARRAY_DEFINE(ecore_future_callbacks,
142 entry->cb(entry->future, entry->value); 133 { EFL_LOOP_EVENT_IDLE_ENTER, _future_dispatch_cb },
143 return EINA_FALSE; 134 { EFL_LOOP_EVENT_IDLE, _future_dispatch_cb },
144} 135 { EFL_EVENT_DEL, _event_del_cb });
145 136
146static void 137static void
147ecore_future_free(void *user_data, 138_future_dispatch_cb(void *data, const Efl_Event *ev EINA_UNUSED)
148 void *func_data EINA_UNUSED)
149{ 139{
150 Ecore_Future_Schedule_Entry *entry = user_data; 140 Efl_Loop_Future_Scheduler *loopsched = data;
151 if (entry->event) 141 Eina_List *entries = loopsched->future_entries;
142 Ecore_Future_Schedule_Entry *entry;
143
144 loopsched->future_entries = NULL;
145 efl_event_callback_array_del((Eo *) loopsched->loop, ecore_future_callbacks(), loopsched);
146
147 EINA_LIST_FREE(entries, entry)
152 { 148 {
153 eina_future_cancel(entry->future); 149 entry->cb(entry->future, entry->value);
154 eina_value_flush(&entry->value); 150 eina_mempool_free(mp_future_schedule_entry, entry);
155 } 151 }
156 eina_mempool_free(mp_future_schedule_entry, entry);
157} 152}
158*/
159 153
160static void 154static void
161_future_dispatch_cb(void *data, const Efl_Event *ev EINA_UNUSED) 155_event_del_cb(void *data, const Efl_Event *ev EINA_UNUSED)
162{ 156{
163 Ecore_Future_Schedule_Entry *entry = data; 157 Efl_Loop_Future_Scheduler *loopsched = data;
164 entry->event = NULL; 158 Eina_List *entries = loopsched->future_entries;
165 entry->cb(entry->future, entry->value); 159 Ecore_Future_Schedule_Entry *entry;
166}
167 160
168static void 161 loopsched->future_entries = NULL;
169_event_del_cb(void *data, const Efl_Event *ev) 162 efl_event_callback_array_del((Eo *) loopsched->loop, ecore_future_callbacks(), loopsched);
170{ 163
171 Ecore_Future_Schedule_Entry *entry = data; 164 EINA_LIST_FREE(entries, entry)
172 if ((ev->object == (Eo *) entry->event) && entry->future)
173 { 165 {
174 eina_future_cancel(entry->future); 166 eina_future_cancel(entry->future);
175 eina_value_flush(&entry->value); 167 eina_value_flush(&entry->value);
168 eina_mempool_free(mp_future_schedule_entry, entry);
176 } 169 }
177 eina_mempool_free(mp_future_schedule_entry, entry);
178} 170}
179 171
180static Eina_Future_Schedule_Entry * 172static Eina_Future_Schedule_Entry *
@@ -192,40 +184,35 @@ ecore_future_schedule(Eina_Future_Scheduler *sched,
192 entry->cb = cb; 184 entry->cb = cb;
193 entry->future = future; 185 entry->future = future;
194 entry->value = value; 186 entry->value = value;
195 entry->event = efl_loop_message_future_handler_message_type_add
196 (loopsched->loop_data->future_message_handler);
197 EINA_SAFETY_ON_NULL_GOTO(entry->event, err);
198 efl_loop_message_future_data_set(entry->event, entry);
199 efl_loop_message_handler_message_send
200 (loopsched->loop_data->future_message_handler, entry->event);
201// XXX:
202// entry->event = ecore_event_add(ECORE_EV_FUTURE_ID, entry,
203// ecore_future_free, entry);
204 efl_event_callback_add((Eo *)entry->event, EFL_LOOP_MESSAGE_EVENT_MESSAGE,
205 _future_dispatch_cb, entry);
206 efl_event_callback_add((Eo *)entry->event, EFL_EVENT_DEL,
207 _event_del_cb, entry);
208 return &entry->base;
209 187
210 err: 188 if (!loopsched->future_entries)
211 eina_mempool_free(mp_future_schedule_entry, entry); 189 efl_event_callback_array_add((Eo *) loopsched->loop, ecore_future_callbacks(), loopsched);
212 return NULL; 190
191 loopsched->future_entries = eina_list_append(loopsched->future_entries, entry);
192 return &entry->base;
213} 193}
214 194
215static void 195static void
216ecore_future_recall(Eina_Future_Schedule_Entry *s_entry) 196ecore_future_recall(Eina_Future_Schedule_Entry *s_entry)
217{ 197{
218 Eo *msg; 198 Ecore_Future_Schedule_Entry *entry = (Ecore_Future_Schedule_Entry *)s_entry;
199 Efl_Loop_Future_Scheduler *loopsched;
200 Eina_List *lookup;
219 201
220 if (shutting_down) return; 202 if (shutting_down) return;
221 Ecore_Future_Schedule_Entry *entry = (Ecore_Future_Schedule_Entry *)s_entry; 203
222 EINA_SAFETY_ON_NULL_RETURN(entry->event); 204 loopsched = (Efl_Loop_Future_Scheduler *) entry->base.scheduler;
223// XXX: 205
224// ecore_event_del(entry->event); 206 lookup = eina_list_data_find_list(loopsched->future_entries, entry);
225 msg = entry->event; 207 if (!lookup) return;
208
209 loopsched->future_entries = eina_list_remove_list(loopsched->future_entries, lookup);
210 if (!loopsched->future_entries)
211 efl_event_callback_array_del((Eo *) loopsched->loop, ecore_future_callbacks(), loopsched);
212
226 eina_value_flush(&entry->value); 213 eina_value_flush(&entry->value);
227 entry->event = NULL; 214 eina_mempool_free(mp_future_schedule_entry, entry);
228 efl_del(msg); 215
229} 216}
230 217
231static Eina_Future_Scheduler ecore_future_scheduler = { 218static Eina_Future_Scheduler ecore_future_scheduler = {
diff --git a/src/lib/ecore/ecore_private.h b/src/lib/ecore/ecore_private.h
index 2022526182..9bd3c3eb0e 100644
--- a/src/lib/ecore/ecore_private.h
+++ b/src/lib/ecore/ecore_private.h
@@ -109,6 +109,8 @@ struct _Efl_Loop_Future_Scheduler
109 Eina_Future_Scheduler eina_future_scheduler; 109 Eina_Future_Scheduler eina_future_scheduler;
110 const Eo *loop; 110 const Eo *loop;
111 Efl_Loop_Data *loop_data; 111 Efl_Loop_Data *loop_data;
112
113 Eina_List *future_entries;
112}; 114};
113 115
114struct _Efl_Loop_Data 116struct _Efl_Loop_Data