Convert iomux to use an UCoreClock

This commit is contained in:
Nils O. Selåsdal
2013-03-02 21:42:19 +01:00
parent b0e9988aa5
commit 54678cf94b
3 changed files with 23 additions and 10 deletions
+11 -7
View File
@@ -3,11 +3,17 @@
#include <string.h>
#include <assert.h>
#include <ucore/iomux_impl.h>
#include <ucore/ucore_clock.h>
//dispatchers for the IOMux implementations */
struct IOMux *iomux_create(enum IOMUX_TYPE type)
{
return iomux_create_ex(type, &ucore_timeofday_clock);
}
struct IOMux *iomux_create_ex(enum IOMUX_TYPE type, struct UCoreClock *uclock)
{
struct IOMux *mux = calloc(1, sizeof *mux);
int rc = -1;
@@ -29,9 +35,8 @@ struct IOMux *iomux_create(enum IOMUX_TYPE type)
}
if (rc == 0) {
rc = gettimeofday(&mux->now, NULL);
assert(rc == 0);
uc_timers_init(&mux->timers);
mux->uclock = uclock;
uc_timers_init_ex(&mux->timers, mux->uclock);
} else {
free(mux);
mux = NULL;
@@ -68,11 +73,10 @@ int iomux_run(struct IOMux *mux)
int has_timers = 0;
rc = gettimeofday(&mux->now, NULL);
assert(rc == 0);
if (uc_timers_first(&mux->timers, &first_timer) == 0) {
future_to_interval(&first_timer, &mux->now, &timeout);
struct timeval now;
mux->uclock->now(mux->uclock, &now);
future_to_interval(&first_timer, &now, &timeout);
timeoutp = &timeout;
/* TRACEF("now %d %d future %d %d interval %d %d\n", mux->now.tv_sec, mux->now.tv_usec,
first_timer.tv_sec, first_timer.tv_usec,