소스 검색

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
Tatsuhiro Tsujikawa 15 년 전
부모
커밋
a71148b702
3개의 변경된 파일31개의 추가작업 그리고 5개의 파일을 삭제
  1. 16 0
      ChangeLog
  2. 13 5
      src/clock_gettime_osx.cc
  3. 2 0
      src/timespec.h

+ 16 - 0
ChangeLog

@@ -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.

+ 13 - 5
src/clock_gettime_osx.cc

@@ -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;
 }

+ 2 - 0
src/timespec.h

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