summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/scheduler/scheduler.cc
diff options
context:
space:
mode:
Diffstat (limited to '2005/i/robert/src/scheduler/scheduler.cc')
-rw-r--r--2005/i/robert/src/scheduler/scheduler.cc31
1 files changed, 19 insertions, 12 deletions
diff --git a/2005/i/robert/src/scheduler/scheduler.cc b/2005/i/robert/src/scheduler/scheduler.cc
index e37504f..4ef3ade 100644
--- a/2005/i/robert/src/scheduler/scheduler.cc
+++ b/2005/i/robert/src/scheduler/scheduler.cc
@@ -23,8 +23,8 @@
// }}}
#include "scheduler.hh"
#include "utils/fd_set.hh"
+#include "timer/timer.hh"
-#include <stdlib.h> //XXX
#include <sys/types.h>
#include <sys/time.h>
@@ -58,7 +58,7 @@ bool
Scheduler::schedule (int timeout/*-1*/, bool returnOnEvent/*false*/)
{
bool event = false;
- int t = time (0) * 1000; //XXX
+ int t = Timer::getProgramTime ();
int start = t;
do
{
@@ -71,24 +71,31 @@ Scheduler::schedule (int timeout/*-1*/, bool returnOnEvent/*false*/)
{
int top = -1;
(*i)->setup (*this, t, readFds, top);
+ // Si le timeout est plus court, retient ce timeout.
if (to == -1 || top != -1 && top < to)
- {
to = top;
- }
}
// Select.
- timeval tv;
- tv.tv_sec = to / 1000;
- tv.tv_usec = to % 1000 * 1000;
- select (FD_SETSIZE, readFds.get (), 0, 0, &tv);
+ if (to != -1)
+ {
+ timeval tv;
+ tv.tv_sec = to / 1000;
+ tv.tv_usec = to % 1000 * 1000;
+ select (FD_SETSIZE, readFds.get (), 0, 0, &tv);
+ }
+ else
+ {
+ select (FD_SETSIZE, readFds.get (), 0, 0, 0);
+ }
// Run.
- t = time (0) * 1000; //XXX
+ t = Timer::getProgramTime ();
for (Schedulables::const_iterator i = schedulables_.begin ();
i != schedulables_.end ();
++i)
- event |= (*i)->run (*this, t, readFds);
- t = time (0) * 1000; //XXX
- } while (!(returnOnEvent && event) && start + timeout > t); //XXX
+ event = (*i)->run (*this, t, readFds) || event;
+ t = Timer::getProgramTime ();
+ } while (!(returnOnEvent && event)
+ && (timeout == -1 || start + timeout > t));
return event;
}