From 54678cf94b7df98c5e8ece8005f803ca117b1306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Sat, 2 Mar 2013 21:42:19 +0100 Subject: [PATCH] Convert iomux to use an UCoreClock --- include/ucore/iomux.h | 7 +++++++ include/ucore/iomux_impl.h | 8 +++++--- src/iomux_impl.c | 18 +++++++++++------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/include/ucore/iomux.h b/include/ucore/iomux.h index f270eb9..55b7d23 100644 --- a/include/ucore/iomux.h +++ b/include/ucore/iomux.h @@ -41,6 +41,13 @@ struct IOMuxFD { */ struct IOMux *iomux_create(enum IOMUX_TYPE type); +/** Creates a new IOMux with a user supplied clock + * + * The supplied clock is used for the UCTimers associated + * with the mux. + */ +struct IOMux *iomux_create_ex(enum IOMUX_TYPE type, struct UCoreClock *uclock); + /** Deletes the IOMux and frees its resources. * Can not be called from within a callback */ void iomux_delete(struct IOMux *mux); diff --git a/include/ucore/iomux_impl.h b/include/ucore/iomux_impl.h index ef65ad7..e63de01 100644 --- a/include/ucore/iomux_impl.h +++ b/include/ucore/iomux_impl.h @@ -9,10 +9,12 @@ struct IOMux { /* TImer instance */ struct UCTimers timers; - /* Current time. Updated before calling run_impl, and updated - * by iomux_timers_run + /** + * Clock used for driving timers, and + * providing timeouts for the mux */ - struct timeval now; + struct UCoreClock *uclock; + /* Used by mux implementations to hold their own data/instance */ void *instance; diff --git a/src/iomux_impl.c b/src/iomux_impl.c index 5f0aff5..fb203f7 100644 --- a/src/iomux_impl.c +++ b/src/iomux_impl.c @@ -3,11 +3,17 @@ #include #include #include +#include //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,