1 #include <Elementary.h>
3 static Ecore_Thread *th = NULL;
5 static Evas_Object *win = NULL;
6 static Evas_Object *rect = NULL;
13 // BEGIN - code running in my custom pthread instance
16 th_do(void *data, Ecore_Thread *th)
20 // inside our "do" function for the ecore thread, lets do the real work
23 struct info *inf = malloc(sizeof(struct info));
27 inf->x = 200 + (200 * sin(t));
28 inf->y = 200 + (200 * cos(t));
29 // now we have recorded the timepoint we pass it as feedback
30 // back to the mainloop. it will free it when done
31 ecore_thread_feedback(th, inf);
36 // in case someone has asked us to cancel - then cancel this loop
37 // co-operatively (cancelling is co-operative)
38 if (ecore_thread_check(th)) break;
42 // END - code running in my custom pthread instance
44 static void // when mainloop gets feedback from worker
45 th_feedback(void *data, Ecore_Thread *th, void *msg)
47 struct info *inf = msg;
48 evas_object_move(rect, inf->x - 50, inf->y - 50);
52 // BONUS (optional): called after th_do returns and has NOT been cancelled
53 static void th_end(void *data, Ecore_Thread *th) { printf("thread ended\n"); }
54 // BONUS (optional): called in mainloop AFTER thread has finished cancelling
55 static void th_cancel(void *data, Ecore_Thread *th) { printf("thread cancelled\n"); }
57 // just test cancelling the thread worker
59 down(void *data, Evas *e, Evas_Object *obj, void *event_info)
61 ecore_thread_cancel(th);
65 elm_main(int argc, char **argv)
69 win = elm_win_add(NULL, "efl-thread-5", ELM_WIN_BASIC);
70 elm_win_title_set(win, "EFL Thread 5");
71 evas_object_resize(win, 400, 400);
72 evas_object_show(win);
75 elm_win_resize_object_add(win, bg);
76 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
79 o = evas_object_rectangle_add(evas_object_evas_get(win));
80 evas_object_color_set(o, 50, 80, 180, 255);
81 evas_object_resize(o, 100, 100);
83 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, down, NULL);
86 // explicitly create ecore thread to do some "work on the side" and pass
87 // in NULL as data ptr to callbacks and true at the end means to actually
88 // make a new thread and not use the thread pool (there is a thread pool
89 // with as many thread workers as there are cpu's so this means you do not
90 // overload the cpu's with more work than you actually have processing
91 // units *IF* your threads do actually spend their time doing actual
93 th = ecore_thread_feedback_run(th_do, th_feedback, th_end, th_cancel,