Enlightenment CVS committal Author : kwo Project : e16 Module : e
Dir : e16/e/src Modified Files: events.c timers.c timers.h Log Message: Tweak timer event handling (run all expired timers at once). =================================================================== RCS file: /cvs/e/e16/e/src/events.c,v retrieving revision 1.133 retrieving revision 1.134 diff -u -3 -r1.133 -r1.134 --- events.c 17 Jan 2007 01:10:43 -0000 1.133 +++ events.c 29 Jan 2007 01:26:12 -0000 1.134 @@ -636,10 +636,6 @@ pfetch = 0; count = EventsProcess(&evq_ptr, &evq_alloc, &pfetch); - if (EDebug(EDBUG_TYPE_EVENTS)) - Eprintf("EventsMain - Idlers\n"); - IdlersRun(); - if (pfetch) { evq_fetch = @@ -655,6 +651,21 @@ } } + run_idlers: + /* Run idlers */ + IdlersRun(); + + /* time2 = current time */ + time2 = GetTime(); + dt = time2 - time1; + time1 = time2; + /* dt = time spent since we last were here */ + + /* Run all expired timers, get time to first non-expired (0. means none) */ + time2 = TimersRun(time2); + if (XPending(disp)) + continue; + FD_ZERO(&fdset); xfd = ConnectionNumber(disp); FD_SET(xfd, &fdset); @@ -663,35 +674,14 @@ FD_SET(smfd, &fdset); fdsize = MAX(xfd, smfd) + 1; - /* time2 = current time */ - time2 = GetTime(); - dt = time2 - time1; - time1 = time2; - if (dt < 0.0) - dt = 0.0; - /* dt = time spent since we last were here */ - - count = TimersPending(&time2); - if (count >= 0) + if (time2 > 0.) { - if (count > 0) - { - if (XPending(disp)) - continue; - tval.tv_sec = (long)time2; - tval.tv_usec = - (long)((time2 - ((double)tval.tv_sec)) * 1000000); - count = select(fdsize, &fdset, NULL, NULL, &tval); - } - if (count == 0) - { - TimersRun(); - } + tval.tv_sec = (long)time2; + tval.tv_usec = (long)((time2 - ((double)tval.tv_sec)) * 1000000); + count = select(fdsize, &fdset, NULL, NULL, &tval); } else { - if (XPending(disp)) - continue; count = select(fdsize, &fdset, NULL, NULL, NULL); } @@ -701,7 +691,13 @@ count, xfd, FD_ISSET(xfd, &fdset), smfd, (smfd >= 0) ? FD_ISSET(smfd, &fdset) : 0, dt, time2); - if (count > 0) + if (count == 0) + { + /* We can only get here by timeout in select */ + TimersRun(0.); + goto run_idlers; + } + else if (count > 0) { if ((smfd >= 0) && (FD_ISSET(smfd, &fdset))) { =================================================================== RCS file: /cvs/e/e16/e/src/timers.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -3 -r1.27 -r1.28 --- timers.c 28 Jan 2007 04:59:46 -0000 1.27 +++ timers.c 29 Jan 2007 01:26:12 -0000 1.28 @@ -59,6 +59,9 @@ if (!qe) return; + if (in_time < 0.) /* No negative in-times */ + in_time = 0.; + if (EDebug(EDBUG_TYPE_EVENTS)) Eprintf("DoIn %8.3f: %s\n", in_time, name); @@ -90,51 +93,57 @@ } } -/* - * Returns: - * -1: No timers pending - * 0: Expired timer pending - * 1: Non-expired timers pending - */ -int -TimersPending(double *t) +double +TimersRun(double tt) { Qentry *qe; - double dt; + double t; qe = q_first; - if (!qe) - return -1; + if (!q_first) + return 0.; /* No timers pending */ - dt = qe->at_time - *t; - *t = dt; + t = tt; + if (t <= 0.) + t = qe->at_time; - return (dt > 0.) ? 1 : 0; -} + for (; qe; qe = q_first) + { + if (qe->at_time > t + 200e-6) /* Within 200 us is close enough */ + break; -void -TimersRun(void) -{ - Qentry *qe; + if (EDebug(EDBUG_TYPE_EVENTS)) + Eprintf("TimersRun - run %8.3lf: %s\n", qe->at_time - t, qe->name); - qe = q_first; - if (!q_first) - return; + /* remove it */ + q_first = qe->next; - if (EDebug(EDBUG_TYPE_EVENTS)) - Eprintf("EventsMain - Timers (%s)\n", qe->name); + /* run this callback */ + qe->func(qe->runtime_val, qe->runtime_data); - /* remove it */ - q_first = q_first->next; + /* free the timer */ + if (qe->name) + Efree(qe->name); + Efree(qe); + } + + if (tt <= 0.) /* Avoid some redundant debug output */ + return tt; + + if (EDebug(EDBUG_TYPE_EVENTS) > 1) + { + Qentry *qp; - /* run this callback */ - qe->func(qe->runtime_val, qe->runtime_data); + for (qp = qe; qp; qp = qp->next) + Eprintf("TimersRun - pend %8.3lf: %s\n", qp->at_time - t, qp->name); + } + + t = (qe) ? qe->at_time - t : 0.; + + if (EDebug(EDBUG_TYPE_EVENTS)) + Eprintf("TimersRun - next in %8.3lf\n", t); - /* free the timer */ - if (qe->name) - Efree(qe->name); - if (qe) - Efree(qe); + return t; } int @@ -212,6 +221,9 @@ IdlersRun(void) { Idler *id; + + if (EDebug(EDBUG_TYPE_EVENTS)) + Eprintf("IdlersRun\n"); ECORE_LIST_FOR_EACH(idler_list, id) id->func(id->data); } =================================================================== RCS file: /cvs/e/e16/e/src/timers.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- timers.h 28 Jan 2007 04:59:46 -0000 1.3 +++ timers.h 29 Jan 2007 01:26:12 -0000 1.4 @@ -31,8 +31,7 @@ void (*func) (int val, void *data), int runtime_val, void *runtime_data); int RemoveTimerEvent(const char *name); -int TimersPending(double *t); -void TimersRun(void); +double TimersRun(double t); typedef struct _idler Idler; Idler *IdlerAdd(int order, void (*func) (void *data), void *data); ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs