2 //gcc -o efl_thread_4 efl_thread_4.c -g `pkg-config --cflags --libs elementary`
3 #include <Elementary.h>
6 static Evas_Object *win = NULL;
7 static Evas_Object *rect = NULL;
14 static void my_thread_mainloop_code(void *data);
16 static pthread_t thread_id;
17 static pthread_mutex_t th_lock;
18 static int th_exit = 0;
20 // BEGIN - code running in my custom pthread instance
23 my_thread_run(void *arg)
27 // inside the pthread function lets loop forever incrimenting a time point
30 struct info *inf = malloc(sizeof(struct info));
35 inf->x = 200 + (200 * sin(t));
36 inf->y = 200 + (200 * cos(t));
37 // now call a function in the mainloop and pass it our allocated
38 // data that it will free when it gets it
39 ecore_main_loop_thread_safe_call_async
40 (my_thread_mainloop_code, inf);
45 // in case someone has asked us to cancel - then cancel this loop
46 // co-operatively (cancelling is co-operative)
47 pthread_mutex_lock(&th_lock);
49 pthread_mutex_unlock(&th_lock);
55 // END - code running in my custom pthread instance
62 pthread_mutex_init(&th_lock, NULL);
63 if (pthread_attr_init(&attr) != 0)
64 perror("pthread_attr_init");
65 if (pthread_create(&thread_id, &attr, my_thread_run, NULL) != 0)
66 perror("pthread_create");
70 my_thread_mainloop_code(void *data)
72 struct info *inf = data;
73 evas_object_move(rect, inf->x - 50, inf->y - 50);
77 // just test cancelling the thread
79 down(void *data, Evas *e, Evas_Object *obj, void *event_info)
81 pthread_mutex_lock(&th_lock);
83 pthread_mutex_unlock(&th_lock);
87 elm_main(int argc, char **argv)
91 win = elm_win_add(NULL, "efl-thread-4", ELM_WIN_BASIC);
92 elm_win_title_set(win, "EFL Thread 4");
93 elm_win_autodel_set(win, EINA_TRUE);
94 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
95 evas_object_resize(win, 400, 400);
96 evas_object_show(win);
99 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
100 elm_win_resize_object_add(win, bg);
101 evas_object_show(bg);
103 o = evas_object_rectangle_add(evas_object_evas_get(win));
104 evas_object_color_set(o, 50, 80, 180, 255);
105 evas_object_resize(o, 100, 100);
107 // new in the examples - we have a mouse down on the blue box cancel
109 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, down, NULL);
112 // create custom thread to do some "work on the side"