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
+7
View File
@@ -41,6 +41,13 @@ struct IOMuxFD {
*/ */
struct IOMux *iomux_create(enum IOMUX_TYPE type); 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. /** Deletes the IOMux and frees its resources.
* Can not be called from within a callback */ * Can not be called from within a callback */
void iomux_delete(struct IOMux *mux); void iomux_delete(struct IOMux *mux);
+5 -3
View File
@@ -9,10 +9,12 @@ struct IOMux {
/* TImer instance */ /* TImer instance */
struct UCTimers timers; 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 */ /* Used by mux implementations to hold their own data/instance */
void *instance; void *instance;
+11 -7
View File
@@ -3,11 +3,17 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <ucore/iomux_impl.h> #include <ucore/iomux_impl.h>
#include <ucore/ucore_clock.h>
//dispatchers for the IOMux implementations */ //dispatchers for the IOMux implementations */
struct IOMux *iomux_create(enum IOMUX_TYPE type) 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); struct IOMux *mux = calloc(1, sizeof *mux);
int rc = -1; int rc = -1;
@@ -29,9 +35,8 @@ struct IOMux *iomux_create(enum IOMUX_TYPE type)
} }
if (rc == 0) { if (rc == 0) {
rc = gettimeofday(&mux->now, NULL); mux->uclock = uclock;
assert(rc == 0); uc_timers_init_ex(&mux->timers, mux->uclock);
uc_timers_init(&mux->timers);
} else { } else {
free(mux); free(mux);
mux = NULL; mux = NULL;
@@ -68,11 +73,10 @@ int iomux_run(struct IOMux *mux)
int has_timers = 0; int has_timers = 0;
rc = gettimeofday(&mux->now, NULL);
assert(rc == 0);
if (uc_timers_first(&mux->timers, &first_timer) == 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; timeoutp = &timeout;
/* TRACEF("now %d %d future %d %d interval %d %d\n", mux->now.tv_sec, mux->now.tv_usec, /* 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, first_timer.tv_sec, first_timer.tv_usec,