Re: gethrtime() is returning negative value on LINUX



On Mar 16, 11:19 pm, "linux_bp" <rishabh.g...@xxxxxxxxx> wrote:
hi
we had implemented gethrtime on LINUX machine using the following
code:

Here's a much better implementation (untested):

#include <time.h>
long long gethrtime(void)
{
struct timespec sp;
int ret;
long long v;
#ifdef CLOCK_MONOTONIC_HR
ret=clock_gettime(CLOCK_MONOTONIC_HR, &sp);
#else
ret=clock_gettime(CLOCK_MONOTONIC, &sp);
#endif
if(ret!=0) return 0;
v=1000000000LL; /* seconds->nanonseconds */
v*=sp.tv_sec;
v+=sp.tv_nsec;
return v;
}

DS

--
If you know anyone who has an invite to the ICQ 6 Preview, I'd
appreciate
one. Email me for details. Thanks in advance.

.



Relevant Pages