Re: gethrtime() is returning negative value on LINUX
- From: "David Schwartz" <davids@xxxxxxxxxxxxx>
- Date: 21 Mar 2007 22:39:14 -0700
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.
.
- References:
- gethrtime() is returning negative value on LINUX
- From: linux_bp
- gethrtime() is returning negative value on LINUX
- Prev by Date: Re: Linux kernel, possible useless continue
- Next by Date: Re: Linux kernel, possible useless continue
- Previous by thread: Re: gethrtime() is returning negative value on LINUX
- Next by thread: Shared Memory...Some Questions.....
- Index(es):
Relevant Pages
|