diff --git a/include/ucore/ucore_clock.h b/include/ucore/ucore_clock.h index c29812f..3d2c10f 100644 --- a/include/ucore/ucore_clock.h +++ b/include/ucore/ucore_clock.h @@ -11,7 +11,7 @@ * it is useful tp have a level of indirection to better facilitate * testing and simulation of code that's dependent on time. */ -struct ucore_clock { +struct UCoreClock { /** * Name of this clock */ @@ -20,7 +20,7 @@ struct ucore_clock { * Wrapper for getting the current time. * @param tv timeval that will be filled in */ - void (*now)(struct ucore_clock *clock, struct timeval *tv); + void (*now)(struct UCoreClock *clock, struct timeval *tv); }; @@ -29,11 +29,11 @@ struct ucore_clock { * from the real_clock whenever ucore_cached_clock_update() * is called. */ -struct ucore_cached_clock { +struct UCoreCachedClock { /** The clock*/ - struct ucore_clock clock; + struct UCoreClock clock; /** The underlying real clock*/ - struct ucore_clock *real_clock; + struct UCoreClock *real_clock; /** cached value */ struct timeval cache; }; @@ -42,9 +42,9 @@ struct ucore_cached_clock { * the user settable value. The user updates the clock * with ucore_settable_clock_set(). */ -struct ucore_settable_clock { +struct UCoreSettableClock { /** The clock*/ - struct ucore_clock clock; + struct UCoreClock clock; /** The underlying real clock*/ /** Current value */ struct timeval now; @@ -53,25 +53,25 @@ struct ucore_settable_clock { /** A clock where now() calls gettimeofday() */ -extern struct ucore_clock ucore_timeofday_clock; +extern struct UCoreClock ucore_timeofday_clock; /** * A clock where now() calls time(). - * This clock will this just have seconds resolution. + * This clock will just have seconds resolution. */ -extern struct ucore_clock ucore_time_clock; +extern struct UCoreClock ucore_time_clock; /** * Initialize a cached clock where now() calls time(). * This clock will this just have seconds resolution. * @param clock clock to initialize */ -void ucore_cached_clock_init(struct ucore_cached_clock *uclock, - struct ucore_clock *real_clock); +void ucore_cached_clock_init(struct UCoreCachedClock *uclock, + struct UCoreClock *real_clock); /** Update the cached clock from the real_clock */ -void ucore_cached_clock_update(struct ucore_cached_clock *uclock); +void ucore_cached_clock_update(struct UCoreCachedClock *uclock); /** @@ -79,12 +79,12 @@ void ucore_cached_clock_update(struct ucore_cached_clock *uclock); * This clock will this just have seconds resolution. * @param clock clock to initialize */ -void ucore_settable_clock_init(struct ucore_settable_clock *uclock); +void ucore_settable_clock_init(struct UCoreSettableClock *uclock); /** * Set the new timeval this clock will return **/ -void ucore_settable_clock_set_tv(struct ucore_settable_clock *uclock, +void ucore_settable_clock_set_tv(struct UCoreSettableClock *uclock, const struct timeval *tv); /** @@ -92,7 +92,7 @@ void ucore_settable_clock_set_tv(struct ucore_settable_clock *uclock, * Convenience function that takes seconds/microseconds as arguments * instead of a struct timeval. **/ -void ucore_settable_clock_set(struct ucore_settable_clock *uclock, +void ucore_settable_clock_set(struct UCoreSettableClock *uclock, time_t secs, suseconds_t usecs); #endif diff --git a/src/ucore_clock.c b/src/ucore_clock.c index 42a9085..c9ce354 100644 --- a/src/ucore_clock.c +++ b/src/ucore_clock.c @@ -7,37 +7,37 @@ #define UNUSED #endif -static void ucore_timeofday_now(struct ucore_clock *clock UNUSED, struct timeval *tv) +static void ucore_timeofday_now(struct UCoreClock *clock UNUSED, struct timeval *tv) { gettimeofday(tv, NULL); } -static void ucore_time_now(struct ucore_clock *clock UNUSED, struct timeval *tv) +static void ucore_time_now(struct UCoreClock *clock UNUSED, struct timeval *tv) { tv->tv_sec = time(NULL); tv->tv_usec = 0; } -struct ucore_clock ucore_timeofday_clock = { +struct UCoreClock ucore_timeofday_clock = { .name = "gettimeofday", .now = ucore_timeofday_now, }; -struct ucore_clock ucore_time_clock = { +struct UCoreClock ucore_time_clock = { .name = "time", .now = ucore_time_now, }; -static void ucore_cached_clock_now(struct ucore_clock *uclock UNUSED, +static void ucore_cached_clock_now(struct UCoreClock *uclock UNUSED, struct timeval *tv) { - struct ucore_cached_clock *cached_clock; - cached_clock = CONTAINER_OF(uclock, struct ucore_cached_clock, clock), + struct UCoreCachedClock *cached_clock; + cached_clock = CONTAINER_OF(uclock, struct UCoreCachedClock, clock), *tv = cached_clock->cache; } -void ucore_cached_clock_init(struct ucore_cached_clock *uclock, struct ucore_clock *real_clock) +void ucore_cached_clock_init(struct UCoreCachedClock *uclock, struct UCoreClock *real_clock) { uclock->clock.name = "cached clock"; uclock->clock.now = ucore_cached_clock_now; @@ -47,20 +47,20 @@ void ucore_cached_clock_init(struct ucore_cached_clock *uclock, struct ucore_clo ucore_cached_clock_update(uclock); } -void ucore_cached_clock_update(struct ucore_cached_clock *uclock) +void ucore_cached_clock_update(struct UCoreCachedClock *uclock) { uclock->real_clock->now(&uclock->clock, &uclock->cache); } -static void ucore_settable_clock_now(struct ucore_clock *uclock, struct timeval *tv) +static void ucore_settable_clock_now(struct UCoreClock *uclock, struct timeval *tv) { - struct ucore_settable_clock *cached_clock; - cached_clock = CONTAINER_OF(uclock, struct ucore_settable_clock, clock), + struct UCoreSettableClock *cached_clock; + cached_clock = CONTAINER_OF(uclock, struct UCoreSettableClock, clock), *tv = cached_clock->now; } -void ucore_settable_clock_init(struct ucore_settable_clock *uclock) +void ucore_settable_clock_init(struct UCoreSettableClock *uclock) { uclock->clock.name = "settable clock"; uclock->clock.now = ucore_settable_clock_now; @@ -69,13 +69,14 @@ void ucore_settable_clock_init(struct ucore_settable_clock *uclock) uclock->now.tv_usec = 0; } -void ucore_settable_clock_set_tv(struct ucore_settable_clock *uclock, const struct timeval *tv) +void ucore_settable_clock_set_tv(struct UCoreSettableClock *uclock, const struct timeval *tv) { uclock->now = *tv; } -void ucore_settable_clock_set(struct ucore_settable_clock *uclock, time_t secs, suseconds_t usecs) +void ucore_settable_clock_set(struct UCoreSettableClock *uclock, time_t secs, suseconds_t usecs) { uclock->now.tv_sec = secs; uclock->now.tv_usec = usecs; } + diff --git a/test/test_clock.c b/test/test_clock.c index b83e31a..b7c824b 100644 --- a/test/test_clock.c +++ b/test/test_clock.c @@ -4,7 +4,7 @@ START_TEST (test_settable_clock) - struct ucore_settable_clock my_clock; + struct UCoreSettableClock my_clock; struct timeval tv; struct timeval tv_tmp; @@ -37,7 +37,7 @@ START_TEST (test_settable_clock) END_TEST START_TEST (test_cached_clock) - struct ucore_cached_clock my_clock; + struct UCoreCachedClock my_clock; struct timeval tv1,tv2; ucore_cached_clock_init(&my_clock, &ucore_timeofday_clock);