From 617ba23c393a386f3dc3bbfa8b2f2437a570f03f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Tue, 10 Feb 2015 11:03:44 +0100 Subject: [PATCH] Make the clock_now interface const --- include/ucore/clock.h | 2 +- src/clock.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/ucore/clock.h b/include/ucore/clock.h index 7014c63..26aba2e 100644 --- a/include/ucore/clock.h +++ b/include/ucore/clock.h @@ -26,7 +26,7 @@ struct UCoreClock { * Wrapper for getting the current time. * @param tv timeval that will be filled in */ - void (*now)(struct UCoreClock *clock, struct timeval *tv); + void (*now)(const struct UCoreClock *clock, struct timeval *tv); }; /** Convenience macro for geting the time from a UCoreClock diff --git a/src/clock.c b/src/clock.c index aeb0538..bfdbcb7 100644 --- a/src/clock.c +++ b/src/clock.c @@ -7,12 +7,12 @@ #define UNUSED #endif -static void uc_timeofday_now(struct UCoreClock *uclock UNUSED, struct timeval *tv) +static void uc_timeofday_now(const struct UCoreClock *uclock UNUSED, struct timeval *tv) { gettimeofday(tv, NULL); } -static void uc_time_now(struct UCoreClock *uclock UNUSED, struct timeval *tv) +static void uc_time_now(const struct UCoreClock *uclock UNUSED, struct timeval *tv) { tv->tv_sec = time(NULL); tv->tv_usec = 0; @@ -28,11 +28,11 @@ struct UCoreClock uc_time_clock = { .now = uc_time_now, }; -static void uc_cached_clock_now(struct UCoreClock *uclock, +static void uc_cached_clock_now(const struct UCoreClock *uclock, struct timeval *tv) { - struct UCoreCachedClock *cached_clock; - cached_clock = UC_CONTAINER_OF(uclock, struct UCoreCachedClock, clock), + const struct UCoreCachedClock *cached_clock; + cached_clock = UC_CONST_CONTAINER_OF(uclock, const struct UCoreCachedClock, clock), *tv = cached_clock->cache; } @@ -52,10 +52,10 @@ void uc_cached_clock_update(struct UCoreCachedClock *uclock) uclock->real_clock->now(&uclock->clock, &uclock->cache); } -static void uc_settable_clock_now(struct UCoreClock *uclock, struct timeval *tv) +static void uc_settable_clock_now(const struct UCoreClock *uclock, struct timeval *tv) { - struct UCoreSettableClock *cached_clock; - cached_clock = UC_CONTAINER_OF(uclock, struct UCoreSettableClock, clock), + const struct UCoreSettableClock *cached_clock; + cached_clock = UC_CONST_CONTAINER_OF(uclock, const struct UCoreSettableClock, clock), *tv = cached_clock->now; }