add functions to get monotonic timestamps (needs kernel 2.6)

git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@1251 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
seife
2011-03-06 15:33:59 +00:00
parent d4b483155c
commit 4f09c0c22a
3 changed files with 40 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ INCLUDES = \
noinst_LIBRARIES = libneutrino_driver.a libneutrino_driver_netfile.a
libneutrino_driver_a_SOURCES = \
abstime.c \
encoding.cpp \
fontrenderer.cpp \
framebuffer.cpp \

27
src/driver/abstime.c Normal file
View File

@@ -0,0 +1,27 @@
#include <stdio.h> /* for perror */
#include <time.h>
time_t time_monotonic_ms(void)
{
struct timespec t;
time_t ret;
if (clock_gettime(CLOCK_MONOTONIC, &t))
{
perror("time_monotonic_ms clock_gettime");
return -1;
}
ret = (t.tv_sec & 0x01FFFFF) * 1000; /* avoid overflow */
ret += t.tv_nsec / 1000000;
return ret;
}
time_t time_monotonic(void)
{
struct timespec t;
if (clock_gettime(CLOCK_MONOTONIC, &t))
{
perror("time_monotonic clock_gettime");
return -1;
}
return t.tv_sec;
}

12
src/driver/abstime.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef _ABS_TIME_H_
#define _ABS_TIME_H_
#ifdef __cplusplus
extern "C"
{
#endif
extern time_t time_monotonic_ms(void);
extern time_t time_monotonic(void);
#ifdef __cplusplus
}
#endif
#endif