From 846bde90e6b1001480016fa46a957a9e726af68a Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 19 Mar 2012 16:59:53 +0000 Subject: [time] Define an API for getting the current time Signed-off-by: Michael Brown --- src/include/ipxe/null_time.h | 23 ++++++++++++++++++ src/include/ipxe/time.h | 58 ++++++++++++++++++++++++++++++++++++++++++++ src/include/time.h | 16 ++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 src/include/ipxe/null_time.h create mode 100644 src/include/ipxe/time.h (limited to 'src/include') diff --git a/src/include/ipxe/null_time.h b/src/include/ipxe/null_time.h new file mode 100644 index 000000000..2b72cdf50 --- /dev/null +++ b/src/include/ipxe/null_time.h @@ -0,0 +1,23 @@ +#ifndef _IPXE_NULL_TIME_H +#define _IPXE_NULL_TIME_H + +/** @file + * + * Nonexistent time source + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#ifdef TIME_NULL +#define TIME_PREFIX_null +#else +#define TIME_PREFIX_null __null_ +#endif + +static inline __always_inline time_t +TIME_INLINE ( null, time_now ) ( void ) { + return 0; +} + +#endif /* _IPXE_NULL_TIME_H */ diff --git a/src/include/ipxe/time.h b/src/include/ipxe/time.h new file mode 100644 index 000000000..c74959f8e --- /dev/null +++ b/src/include/ipxe/time.h @@ -0,0 +1,58 @@ +#ifndef _IPXE_TIME_H +#define _IPXE_TIME_H + +/** @file + * + * Time source + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#include +#include +#include + +/** + * Calculate static inline time API function name + * + * @v _prefix Subsystem prefix + * @v _api_func API function + * @ret _subsys_func Subsystem API function + */ +#define TIME_INLINE( _subsys, _api_func ) \ + SINGLE_API_INLINE ( TIME_PREFIX_ ## _subsys, _api_func ) + +/** + * Provide a time API implementation + * + * @v _prefix Subsystem prefix + * @v _api_func API function + * @v _func Implementing function + */ +#define PROVIDE_TIME( _subsys, _api_func, _func ) \ + PROVIDE_SINGLE_API ( TIME_PREFIX_ ## _subsys, _api_func, _func ) + +/** + * Provide a static inline time API implementation + * + * @v _prefix Subsystem prefix + * @v _api_func API function + */ +#define PROVIDE_TIME_INLINE( _subsys, _api_func ) \ + PROVIDE_SINGLE_API_INLINE ( TIME_PREFIX_ ## _subsys, _api_func ) + +/* Include all architecture-independent time API headers */ +#include + +/* Include all architecture-dependent time API headers */ +#include + +/** + * Get current time in seconds + * + * @ret time Time, in seconds + */ +time_t time_now ( void ); + +#endif /* _IPXE_TIME_H */ diff --git a/src/include/time.h b/src/include/time.h index f33300ab3..bc73af4cd 100644 --- a/src/include/time.h +++ b/src/include/time.h @@ -7,6 +7,7 @@ */ #include +#include /** Broken-down time */ struct tm { @@ -30,6 +31,21 @@ struct tm { int tm_isdst; }; +/** + * Get current time in seconds since the Epoch + * + * @v t Time to fill in, or NULL + * @ret time Current time + */ +static inline time_t time ( time_t *t ) { + time_t now; + + now = time_now(); + if ( t ) + *t = now; + return now; +} + extern time_t mktime ( struct tm *tm ); #endif /* _TIME_H */ -- cgit v1.2.3-55-g7522