On Thu, 9 Jun 2011, Enlightenment SVN wrote:
> Log: > ecore: add ecore_pipe_wait. > > > Author: cedric > Date: 2011-06-09 07:54:24 -0700 (Thu, 09 Jun 2011) > New Revision: 60135 > Trac: http://trac.enlightenment.org/e/changeset/60135 > > Modified: > trunk/ecore/ChangeLog trunk/ecore/src/lib/ecore/Ecore.h > trunk/ecore/src/lib/ecore/ecore_main.c trunk/ecore/src/lib/ecore/ecore_pipe.c > trunk/ecore/src/lib/ecore/ecore_private.h > > Modified: trunk/ecore/ChangeLog > =================================================================== > --- trunk/ecore/ChangeLog 2011-06-09 14:17:07 UTC (rev 60134) > +++ trunk/ecore/ChangeLog 2011-06-09 14:54:24 UTC (rev 60135) > @@ -210,3 +210,7 @@ > > * Add ecore_pipe_freeze/thaw to suspend and restart watching the pipe > inside the main loop. > + > +2011-06-09 Cedric Bail > + > + * Add ecore_pipe_wait (should only called from outside of the main > loop). > > Modified: trunk/ecore/src/lib/ecore/Ecore.h > =================================================================== > --- trunk/ecore/src/lib/ecore/Ecore.h 2011-06-09 14:17:07 UTC (rev 60134) > +++ trunk/ecore/src/lib/ecore/Ecore.h 2011-06-09 14:54:24 UTC (rev 60135) > @@ -788,6 +788,7 @@ > EAPI void ecore_pipe_read_close(Ecore_Pipe *p); > EAPI void ecore_pipe_thaw(Ecore_Pipe *p); > EAPI void ecore_pipe_freeze(Ecore_Pipe *p); > + EAPI int ecore_pipe_wait(Ecore_Pipe *p, int message_count, > double wait); > > /** > * @} > > Modified: trunk/ecore/src/lib/ecore/ecore_main.c > =================================================================== > --- trunk/ecore/src/lib/ecore/ecore_main.c 2011-06-09 14:17:07 UTC (rev > 60134) > +++ trunk/ecore/src/lib/ecore/ecore_main.c 2011-06-09 14:54:24 UTC (rev > 60135) > @@ -147,9 +147,9 @@ > #endif > > #ifdef _WIN32 > -static Ecore_Select_Function main_loop_select = _ecore_main_win32_select; > +Ecore_Select_Function main_loop_select = _ecore_main_win32_select; > #else > -static Ecore_Select_Function main_loop_select = select; > +Ecore_Select_Function main_loop_select = select; > #endif > > #ifndef USE_G_MAIN_LOOP > > Modified: trunk/ecore/src/lib/ecore/ecore_pipe.c > =================================================================== > --- trunk/ecore/src/lib/ecore/ecore_pipe.c 2011-06-09 14:17:07 UTC (rev > 60134) > +++ trunk/ecore/src/lib/ecore/ecore_pipe.c 2011-06-09 14:54:24 UTC (rev > 60135) > @@ -5,7 +5,29 @@ > #include <stdlib.h> > #include <stdio.h> > #include <errno.h> > +#include <math.h> > > +#ifdef HAVE_ISFINITE > +# define ECORE_FINITE(t) isfinite(t) > +#else > +# ifdef _MSC_VER > +# define ECORE_FINITE(t) _finite(t) > +# else > +# define ECORE_FINITE(t) finite(t) > +# endif > +#endif > + > +#define FIX_HZ 1 > + > +#ifdef FIX_HZ > +# ifndef _MSC_VER > +# include <sys/param.h> > +# endif > +# ifndef HZ > +# define HZ 100 > +# endif > +#endif > + > #ifdef HAVE_EVIL > # include <Evil.h> > #endif > @@ -60,6 +82,7 @@ > int handling; > size_t already_read; > void *passed_data; > + int message; > Eina_Bool delete_me : 1; > }; i can't read the code, but doesn't this break ABI ? and add @since in doc Vincent > > @@ -414,6 +437,94 @@ > } > > /** > + * @brief Wait from another thread on the read side of a pipe. > + * > + * @param p The pipe to watch on. > + * @param message_count The minimal number of message to wait before exiting. > + * @param wait The amount of time in second to wait before exiting. > + * @return the number of message catched during that wait call. > + * > + * Negative value for @p wait means infite wait. > + */ > +EAPI int > +ecore_pipe_wait(Ecore_Pipe *p, int message_count, double wait) > +{ > + struct timeval tv, *t; > + fd_set rset; > + double end = 0.0; > + double timeout; > + int ret; > + int total = 0; > + > + if (p->fd_read == PIPE_FD_INVALID) > + return -1; > + > + FD_ZERO(&rset); > + FD_SET(p->fd_read, &rset); > + > + if (wait >= 0.0) > + end = ecore_time_get() + wait; > + timeout = wait; > + > + while (message_count > 0 && (timeout > 0.0 || wait <= 0.0)) > + { > + if (wait >= 0.0) > + { > + /* finite() tests for NaN, too big, too small, and infinity. */ > + if ((!ECORE_FINITE(timeout)) || (timeout == 0.0)) > + { > + tv.tv_sec = 0; > + tv.tv_usec = 0; > + } > + else if (timeout > 0.0) > + { > + int sec, usec; > +#ifdef FIX_HZ > + timeout += (0.5 / HZ); > + sec = (int)timeout; > + usec = (int)((timeout - (double)sec) * 1000000); > +#else > + sec = (int)timeout; > + usec = (int)((timeout - (double)sec) * 1000000); > +#endif > + tv.tv_sec = sec; > + tv.tv_usec = usec; > + } > + t = &tv; > + } > + else > + { > + t = NULL; > + } > + > + ret = main_loop_select(p->fd_read + 1, &rset, NULL, NULL, t); > + > + if (ret > 0) > + { > + _ecore_pipe_read(p, NULL); > + message_count -= p->message; > + total += p->message; > + p->message = 0; > + } > + else if (ret == 0) > + { > + break; > + } > + else if (errno != EINTR) > + { > + close(p->fd_read); > + p->fd_read = PIPE_FD_INVALID; > + break; > + } > + > + if (wait >= 0.0) > + timeout = end - ecore_time_get(); > + } > + > + return total; > +} > + > +/** > * Close the write end of an Ecore_Pipe object created with ecore_pipe_add(). > * > * @param p The Ecore_Pipe object. > @@ -642,6 +753,7 @@ > p->passed_data = NULL; > p->already_read = 0; > p->len = 0; > + p->message++; > } > else if (ret >= 0) > { > > Modified: trunk/ecore/src/lib/ecore/ecore_private.h > =================================================================== > --- trunk/ecore/src/lib/ecore/ecore_private.h 2011-06-09 14:17:07 UTC (rev > 60134) > +++ trunk/ecore/src/lib/ecore/ecore_private.h 2011-06-09 14:54:24 UTC (rev > 60135) > @@ -198,5 +198,6 @@ > extern int _ecore_fps_debug; > extern double _ecore_time_loop_time; > extern Eina_Bool _ecore_glib_always_integrate; > +extern Ecore_Select_Function main_loop_select; > > #endif > > > ------------------------------------------------------------------------------ > EditLive Enterprise is the world's most technically advanced content > authoring tool. Experience the power of Track Changes, Inline Image > Editing and ensure content is compliant with Accessibility Checking. > http://p.sf.net/sfu/ephox-dev2dev > _______________________________________________ > enlightenment-svn mailing list > enlightenment-...@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/enlightenment-svn > > ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev _______________________________________________ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel