For some 3rd party library functions, it requires that I pass it a timespec that uses absolute time and not relative time.
To do this I have:
struct timespec ts;
struct timespec now;
if (clock_gettime(CLOCK_REALTIME, &now) != 0)
{
printf("Error: ");
printf("%s\n", strerror(errno));
}
tspec_add(&ts, &now, 5000); //ts = now + 5000ms.
//I pass ts to the library function.
And the functions work fine.. However, if I use CLOCK_MONOTONIC or CLOCK_MONOTONIC_RAW it does NOT work.
I checked for errors (NONE occur). The function success but the time it outputs is completely different and very very small. It printed 9005 for tv.sec but when using CLOCK_REALTIME it printed a huge number (I assume time since epoch).
Why is this? How can I use the monotonic clock to do the same?
Aucun commentaire:
Enregistrer un commentaire