
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile with:}}
\DoxyCodeLine{\textcolor{comment}{//gcc -\/o efl\_thread\_4 efl\_thread\_4.c -\/g `pkg-\/config -\/-\/cflags -\/-\/libs elementary`}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <Elementary.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <pthread.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *win = NULL;}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *rect = NULL;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{struct }info}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keywordtype}{double} x, y;}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void} my\_thread\_mainloop\_code(\textcolor{keywordtype}{void} *data);}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} pthread\_t thread\_id;}
\DoxyCodeLine{\textcolor{keyword}{static} pthread\_mutex\_t th\_lock;}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{int} th\_exit = 0;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{// BEGIN -\/ code running in my custom pthread instance}}
\DoxyCodeLine{\textcolor{comment}{//}}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void} *}
\DoxyCodeLine{my\_thread\_run(\textcolor{keywordtype}{void} *arg \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keywordtype}{double} t = 0.0;}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{comment}{// inside the pthread function lets loop forever incrementing a time point}}
\DoxyCodeLine{   \textcolor{keywordflow}{for} (;;)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \textcolor{keyword}{struct }info *inf = malloc(\textcolor{keyword}{sizeof}(\textcolor{keyword}{struct} info));}
\DoxyCodeLine{        \textcolor{keywordtype}{int} do\_exit;}
\DoxyCodeLine{}
\DoxyCodeLine{        \textcolor{keywordflow}{if} (inf)}
\DoxyCodeLine{          \{}
\DoxyCodeLine{             inf-\/>x = 200 + (200 * sin(t));}
\DoxyCodeLine{             inf-\/>y = 200 + (200 * cos(t));}
\DoxyCodeLine{             \textcolor{comment}{// now call a function in the mainloop and pass it our allocated}}
\DoxyCodeLine{             \textcolor{comment}{// data that it will free when it gets it}}
\DoxyCodeLine{             \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga12c98ccc13eb136ed62f8177d12a8fc0}{ecore\_main\_loop\_thread\_safe\_call\_async}}}
\DoxyCodeLine{                (my\_thread\_mainloop\_code, inf);}
\DoxyCodeLine{          \}}
\DoxyCodeLine{        \textcolor{comment}{// and sleep and loop}}
\DoxyCodeLine{        usleep(1000);}
\DoxyCodeLine{        t += 0.02;}
\DoxyCodeLine{        \textcolor{comment}{// in case someone has asked us to cancel -\/ then cancel this loop}}
\DoxyCodeLine{        \textcolor{comment}{// co-\/operatively (cancelling is co-\/operative)}}
\DoxyCodeLine{        pthread\_mutex\_lock(\&th\_lock);}
\DoxyCodeLine{        do\_exit = th\_exit;}
\DoxyCodeLine{        pthread\_mutex\_unlock(\&th\_lock);}
\DoxyCodeLine{        \textcolor{keywordflow}{if} (do\_exit) \textcolor{keywordflow}{break};}
\DoxyCodeLine{     \}}
\DoxyCodeLine{   \textcolor{keywordflow}{return} NULL;}
\DoxyCodeLine{\}}
\DoxyCodeLine{\textcolor{comment}{//}}
\DoxyCodeLine{\textcolor{comment}{// END -\/ code running in my custom pthread instance}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{my\_thread\_new(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   pthread\_attr\_t attr;}
\DoxyCodeLine{}
\DoxyCodeLine{   pthread\_mutex\_init(\&th\_lock, NULL);}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (pthread\_attr\_init(\&attr) != 0)}
\DoxyCodeLine{     perror(\textcolor{stringliteral}{"{}pthread\_attr\_init"{}});}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (pthread\_create(\&thread\_id, \&attr, my\_thread\_run, NULL) != 0)}
\DoxyCodeLine{     perror(\textcolor{stringliteral}{"{}pthread\_create"{}});}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{my\_thread\_mainloop\_code(\textcolor{keywordtype}{void} *data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keyword}{struct }info *inf = data;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga02da8091bbac768b8e86c7b74b2a94f9}{evas\_object\_move}}(rect, inf-\/>x -\/ 50, inf-\/>y -\/ 50);}
\DoxyCodeLine{   free(inf);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{// just test cancelling the thread}}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{down(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \mbox{\hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas}} *e \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{void} *event\_info \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   pthread\_mutex\_lock(\&th\_lock);}
\DoxyCodeLine{   th\_exit = 1;}
\DoxyCodeLine{   pthread\_mutex\_unlock(\&th\_lock);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{// on window delete -\/ cancel thread then delete window and exit mainloop}}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{del(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj, \textcolor{keywordtype}{void} *event\_info \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   pthread\_mutex\_lock(\&th\_lock);}
\DoxyCodeLine{   th\_exit = 1;}
\DoxyCodeLine{   pthread\_mutex\_unlock(\&th\_lock);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga7e7a625dab7a3890532aa13b43117076}{evas\_object\_del}}(obj);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_gabada1ccecc6a712df48e90cbf9915c35}{elm\_exit}}();}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{EAPI\_MAIN \textcolor{keywordtype}{int}}
\DoxyCodeLine{elm\_main(\textcolor{keywordtype}{int} argc \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{char} **argv \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *o;}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_ga7a05f37fd3a019da5e26c5fc91fcd937}{elm\_policy\_set}}(\mbox{\hyperlink{group__Elm__General_ggaa16f3378ecdbf660fa378402e3c5a0a9a02fadb6faada04b19d0fa42c11a8d32a}{ELM\_POLICY\_QUIT}}, \mbox{\hyperlink{group__Elm__General_gga46af37e6ac2c406321060be827117196abbe0962d88ae12afe1a173da881f56cd}{ELM\_POLICY\_QUIT\_LAST\_WINDOW\_CLOSED}});}
\DoxyCodeLine{}
\DoxyCodeLine{   win = \mbox{\hyperlink{group__Elm__Win__Group_gac75d7752662fab73d6420706ce5be996}{elm\_win\_util\_standard\_add}}(\textcolor{stringliteral}{"{}efl-\/thread-\/4"{}}, \textcolor{stringliteral}{"{}EFL Thread 4"{}});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Smart__Object__Group_ga18a8b179f94d21b2b09e19db11741061}{evas\_object\_smart\_callback\_add}}(win, \textcolor{stringliteral}{"{}delete,request"{}}, del, NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{   o = \mbox{\hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}}(\mbox{\hyperlink{group__Evas__Object__Group_gae1058082dae7b97590c41f43405dfdbf}{evas\_object\_evas\_get}}(win));}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}}(o, 50, 80, 180, 255);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga21e8604c0e4a93e469bff4bd069e82b5}{evas\_object\_resize}}(o, 100, 100);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(o);}
\DoxyCodeLine{   \textcolor{comment}{// new in the examples -\/ we have a mouse down on the blue box cancel}}
\DoxyCodeLine{   \textcolor{comment}{// the thread}}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Events_ga23be30ac5cdfb780f1ff82e9108ec26b}{evas\_object\_event\_callback\_add}}(o, \mbox{\hyperlink{Evas__Common_8h_ad64cde0da38a60e7cb7905b3ab216968a9fa52651ccf7e47cd3b7785fc4cf393f}{EVAS\_CALLBACK\_MOUSE\_DOWN}}, down, NULL);}
\DoxyCodeLine{   rect = o;}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{comment}{// create custom thread to do some "{}work on the side"{}}}
\DoxyCodeLine{   my\_thread\_new();}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga21e8604c0e4a93e469bff4bd069e82b5}{evas\_object\_resize}}(win, 400, 400);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(win);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_gadf2553f83e6b0b9c7fbe054019a664a1}{elm\_run}}();}
\DoxyCodeLine{   pthread\_mutex\_lock(\&th\_lock);}
\DoxyCodeLine{   th\_exit = 1;}
\DoxyCodeLine{   pthread\_mutex\_unlock(\&th\_lock);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{\}}
\DoxyCodeLine{\mbox{\hyperlink{group__Elm__General_ga50fe52d513f7e89c9c770afd76de7ad9}{ELM\_MAIN}}()}

\end{DoxyCodeInclude}
 