CamelCase the Clock structs

This commit is contained in:
Nils O. Selåsdal
2013-03-02 20:31:26 +01:00
parent 9f22f7153b
commit 42269a8a91
3 changed files with 34 additions and 33 deletions
+16 -16
View File
@@ -11,7 +11,7 @@
* it is useful tp have a level of indirection to better facilitate * it is useful tp have a level of indirection to better facilitate
* testing and simulation of code that's dependent on time. * testing and simulation of code that's dependent on time.
*/ */
struct ucore_clock { struct UCoreClock {
/** /**
* Name of this clock * Name of this clock
*/ */
@@ -20,7 +20,7 @@ struct ucore_clock {
* Wrapper for getting the current time. * Wrapper for getting the current time.
* @param tv timeval that will be filled in * @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() * from the real_clock whenever ucore_cached_clock_update()
* is called. * is called.
*/ */
struct ucore_cached_clock { struct UCoreCachedClock {
/** The clock*/ /** The clock*/
struct ucore_clock clock; struct UCoreClock clock;
/** The underlying real clock*/ /** The underlying real clock*/
struct ucore_clock *real_clock; struct UCoreClock *real_clock;
/** cached value */ /** cached value */
struct timeval cache; struct timeval cache;
}; };
@@ -42,9 +42,9 @@ struct ucore_cached_clock {
* the user settable value. The user updates the clock * the user settable value. The user updates the clock
* with ucore_settable_clock_set(). * with ucore_settable_clock_set().
*/ */
struct ucore_settable_clock { struct UCoreSettableClock {
/** The clock*/ /** The clock*/
struct ucore_clock clock; struct UCoreClock clock;
/** The underlying real clock*/ /** The underlying real clock*/
/** Current value */ /** Current value */
struct timeval now; struct timeval now;
@@ -53,25 +53,25 @@ struct ucore_settable_clock {
/** A clock where now() calls gettimeofday() /** 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(). * 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(). * Initialize a cached clock where now() calls time().
* This clock will this just have seconds resolution. * This clock will this just have seconds resolution.
* @param clock clock to initialize * @param clock clock to initialize
*/ */
void ucore_cached_clock_init(struct ucore_cached_clock *uclock, void ucore_cached_clock_init(struct UCoreCachedClock *uclock,
struct ucore_clock *real_clock); struct UCoreClock *real_clock);
/** Update the cached clock from the 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. * This clock will this just have seconds resolution.
* @param clock clock to initialize * @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 * 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); 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 * Convenience function that takes seconds/microseconds as arguments
* instead of a struct timeval. * 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); time_t secs, suseconds_t usecs);
#endif #endif
+16 -15
View File
@@ -7,37 +7,37 @@
#define UNUSED #define UNUSED
#endif #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); 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_sec = time(NULL);
tv->tv_usec = 0; tv->tv_usec = 0;
} }
struct ucore_clock ucore_timeofday_clock = { struct UCoreClock ucore_timeofday_clock = {
.name = "gettimeofday", .name = "gettimeofday",
.now = ucore_timeofday_now, .now = ucore_timeofday_now,
}; };
struct ucore_clock ucore_time_clock = { struct UCoreClock ucore_time_clock = {
.name = "time", .name = "time",
.now = ucore_time_now, .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 timeval *tv)
{ {
struct ucore_cached_clock *cached_clock; struct UCoreCachedClock *cached_clock;
cached_clock = CONTAINER_OF(uclock, struct ucore_cached_clock, clock), cached_clock = CONTAINER_OF(uclock, struct UCoreCachedClock, clock),
*tv = cached_clock->cache; *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.name = "cached clock";
uclock->clock.now = ucore_cached_clock_now; 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); 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); 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; struct UCoreSettableClock *cached_clock;
cached_clock = CONTAINER_OF(uclock, struct ucore_settable_clock, clock), cached_clock = CONTAINER_OF(uclock, struct UCoreSettableClock, clock),
*tv = cached_clock->now; *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.name = "settable clock";
uclock->clock.now = ucore_settable_clock_now; 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; 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; 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_sec = secs;
uclock->now.tv_usec = usecs; uclock->now.tv_usec = usecs;
} }
+2 -2
View File
@@ -4,7 +4,7 @@
START_TEST (test_settable_clock) START_TEST (test_settable_clock)
struct ucore_settable_clock my_clock; struct UCoreSettableClock my_clock;
struct timeval tv; struct timeval tv;
struct timeval tv_tmp; struct timeval tv_tmp;
@@ -37,7 +37,7 @@ START_TEST (test_settable_clock)
END_TEST END_TEST
START_TEST (test_cached_clock) START_TEST (test_cached_clock)
struct ucore_cached_clock my_clock; struct UCoreCachedClock my_clock;
struct timeval tv1,tv2; struct timeval tv1,tv2;
ucore_cached_clock_init(&my_clock, &ucore_timeofday_clock); ucore_cached_clock_init(&my_clock, &ucore_timeofday_clock);