1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

added new function to get current time

This commit is contained in:
Steffen Vogel 2015-10-11 14:50:08 +02:00
parent 0b5358ed4b
commit b1c1d77597
3 changed files with 14 additions and 4 deletions

View file

@ -39,6 +39,9 @@ struct timespec time_diff(struct timespec *start, struct timespec *end);
/** Get sum of two timespec structs */
struct timespec time_add(struct timespec *start, struct timespec *end);
/** Return current time as a struct timespec. */
struct timespec time_now();
/** Return the diffrence off two timestamps as double value in seconds. */
double time_delta(struct timespec *start, struct timespec *end);

View file

@ -65,8 +65,7 @@ char * file_print(struct node *n)
if ((f->first.tv_sec || f->first.tv_nsec) &&
(f->offset.tv_sec || f->offset.tv_nsec)) {
struct timespec eta, now;
clock_gettime(CLOCK_REALTIME, &now);
struct timespec eta, now = time_now();
eta = time_add(&f->first, &f->offset);
eta = time_diff(&now, &eta);
@ -145,8 +144,7 @@ int file_open(struct node *n)
serror("Failed to create timer");
/* Get current time */
struct timespec now, eta;
clock_gettime(CLOCK_REALTIME, &now);
struct timespec now = time_now();
/* Get timestamp of first line */
struct msg m;

View file

@ -31,6 +31,15 @@ uint64_t timerfd_wait_until(int fd, struct timespec *until)
return timerfd_wait(fd);
}
struct timespec time_now()
{
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return ts;
}
struct timespec time_add(struct timespec *start, struct timespec *end)
{
struct timespec sum = {