lib: posix: clock: Add gettimeofday() call
Provide an implementation of gettimeofday(). This uses clock_gettime() with the CLOCK_REALTIME parameter, which is currently unimplemented, but will allow clients to call this function once this functionality has been implemented. Signed-off-by: David Brown <david.brown@linaro.org>
This commit is contained in:
parent
26c51c43d0
commit
e0dda1b4b0
3 changed files with 30 additions and 0 deletions
|
@ -26,6 +26,7 @@
|
|||
#ifdef CONFIG_PTHREAD_IPC
|
||||
|
||||
#define timespec zap_timespec
|
||||
#define timeval zap_timeval
|
||||
#define pthread_mutex_t zap_pthread_mutex_t
|
||||
#define pthread_mutexattr_t zap_pthread_mutexattr_t
|
||||
#define pthread_cond_t zap_pthread_cond_t
|
||||
|
@ -131,6 +132,7 @@
|
|||
/* Clock */
|
||||
#define clock_gettime(...) zap_clock_gettime(__VA_ARGS__)
|
||||
#define clock_settime(...) zap_clock_settime(__VA_ARGS__)
|
||||
#define gettimeofday(...) zap_clock_gettimeofday(__VA_ARGS__)
|
||||
|
||||
/* Timer */
|
||||
#define timer_create(...) zap_timer_create(__VA_ARGS__)
|
||||
|
|
|
@ -20,6 +20,11 @@ struct itimerspec {
|
|||
struct timespec it_value; /* Timer expiration */
|
||||
};
|
||||
|
||||
struct timeval {
|
||||
signed int tv_sec;
|
||||
signed int tv_usec;
|
||||
};
|
||||
|
||||
#include <kernel.h>
|
||||
#include <errno.h>
|
||||
#include "sys/types.h"
|
||||
|
@ -63,6 +68,8 @@ int timer_gettime(timer_t timerid, struct itimerspec *its);
|
|||
int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
|
||||
struct itimerspec *ovalue);
|
||||
|
||||
int gettimeofday(struct timeval *tv, const void *tz);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -29,3 +29,24 @@ int clock_gettime(clockid_t clock_id, struct timespec *ts)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get current real time.
|
||||
*
|
||||
* See IEEE 1003.1
|
||||
*/
|
||||
int gettimeofday(struct timeval *tv, const void *tz)
|
||||
{
|
||||
struct timespec ts;
|
||||
int res;
|
||||
|
||||
/* As per POSIX, "if tzp is not a null pointer, the behavior
|
||||
* is unspecified." "tzp" is the "tz" parameter above. */
|
||||
ARG_UNUSED(tv);
|
||||
|
||||
res = clock_gettime(CLOCK_REALTIME, &ts);
|
||||
tv->tv_sec = ts.tv_sec;
|
||||
tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue