aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/elementary/src/examples/efl_thread_1.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/elementary/src/examples/efl_thread_1.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/libraries/elementary/src/examples/efl_thread_1.c b/libraries/elementary/src/examples/efl_thread_1.c
new file mode 100644
index 0000000..0f18539
--- /dev/null
+++ b/libraries/elementary/src/examples/efl_thread_1.c
@@ -0,0 +1,79 @@
1//Compile with:
2//gcc -o efl_thread_1 efl_thread_1.c -g `pkg-config --cflags --libs elementary`
3#include <Elementary.h>
4#include <pthread.h>
5
6static Evas_Object *win = NULL;
7static Evas_Object *rect = NULL;
8
9static pthread_t thread_id;
10
11// BEGIN - code running in my custom pthread instance
12//
13static void *
14my_thread_run(void *arg)
15{
16 double t = 0.0;
17
18 for (;;)
19 {
20 ecore_thread_main_loop_begin(); // begin critical
21 { // indented for illustration of "critical" block
22 Evas_Coord x, y;
23
24 x = 200 + (200 * sin(t));
25 y = 200 + (200 * cos(t));
26 evas_object_move(rect, x - 50, y - 50);
27 }
28 ecore_thread_main_loop_end(); // end critical
29 usleep(1000);
30 t += 0.02;
31 }
32 return NULL;
33}
34//
35// END - code running in my custom pthread instance
36
37static void
38my_thread_new(void)
39{
40 pthread_attr_t attr;
41
42 if (pthread_attr_init(&attr) != 0)
43 perror("pthread_attr_init");
44 if (pthread_create(&thread_id, &attr, my_thread_run, NULL) != 0)
45 perror("pthread_create");
46}
47
48EAPI_MAIN int
49elm_main(int argc, char **argv)
50{
51 Evas_Object *o, *bg;
52
53 win = elm_win_add(NULL, "efl-thread-1", ELM_WIN_BASIC);
54 elm_win_title_set(win, "EFL Thread 1");
55 elm_win_autodel_set(win, EINA_TRUE);
56 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
57 evas_object_resize(win, 400, 400);
58 evas_object_show(win);
59
60 bg = elm_bg_add(win);
61 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
62 elm_win_resize_object_add(win, bg);
63 evas_object_show(bg);
64
65 o = evas_object_rectangle_add(evas_object_evas_get(win));
66 evas_object_color_set(o, 50, 80, 180, 255);
67 evas_object_resize(o, 100, 100);
68 evas_object_show(o);
69 rect = o;
70
71 // create custom thread to do some "work on the side"
72 my_thread_new();
73
74 elm_run();
75 elm_shutdown();
76
77 return 0;
78}
79ELM_MAIN()