2010-04-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Use elapsed time between two mach_absolute_time() calls.
	Fixed compile error in Mac OS X.
	* src/clock_gettime_osx.cc
	* src/timespec.h
pull/1/head
Tatsuhiro Tsujikawa 2010-04-13 16:53:38 +00:00
parent 91e7127396
commit a71148b702
3 changed files with 31 additions and 5 deletions

View File

@ -1,3 +1,19 @@
2010-04-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Use elapsed time between two mach_absolute_time() calls.
Fixed compile error in Mac OS X.
* src/clock_gettime_osx.cc
* src/timespec.h
2010-04-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Implemented clock_gettime() using mach_absolute_time in Mac OS X.
* configure.ac
* src/Makefile.am
* src/a2time.h
* src/clock_gettime_osx.cc
* src/clock_gettime_osx.h
2010-04-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Implemented clock_gettime() using timeGetTime in mingw.

View File

@ -38,13 +38,21 @@
int clock_gettime(int dummyid, struct timespec* tp)
{
uint64_t mt = mach_absolute_time();
static uint64_t lasttime = mach_absolute_time();
static struct timespec monotime = {2678400, 0}; // 1month offset(24*3600*31)
uint64_t now = mach_absolute_time();
static mach_timebase_info_data_t baseinfo;
if(baseinfo.denom == 0) {
mach_timebase_info(&baseinfo);
}
uint64_t t = mt*baseinfo.numer/baseinfo.denom;
tp->tv_sec = t/1000000000+2678400; // 1month offset(24*3600*31)
tp->tv_nsec = t%1000000000;
return 1;
uint64_t elapsed = (now-lasttime)*baseinfo.numer/baseinfo.denom;
monotime.tv_sec += elapsed/1000000000;
monotime.tv_nsec += elapsed%1000000000;
if(monotime.tv_nsec >= 1000000000) {
monotime.tv_sec += monotime.tv_nsec/1000000000;
monotime.tv_nsec %= 1000000000;
}
lasttime = now;
*tp = monotime;
return 0;
}

View File

@ -34,6 +34,8 @@
#ifndef _D_TIMESPEC_H_
#define _D_TIMESPEC_H_
#include "common.h"
#include <time.h>
#ifndef HAVE_STRUCT_TIMESPEC