1
0
Fork 0

Use clock_gettime when available instead of the obsolete ftime.

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3899
This commit is contained in:
Peter Veenstra 2015-02-11 19:11:31 +00:00
parent 81ae7277e8
commit ef7ddd1504
2 changed files with 22 additions and 3 deletions

View file

@ -129,6 +129,12 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <math.h>]],[[
]])], [AC_MSG_RESULT(yes)], [AC_DEFINE([DB_HAVE_NO_POWF],[1],[libm doesn't include powf])])
LIBS=$LIBS_BACKUP
dnl Look for clock_gettime, a DB_HAVE_CLOCK_GETTIME is set when present
AH_TEMPLATE([DB_HAVE_CLOCK_GETTIME],[Determines if the function clock_gettime is available.])
AC_SEARCH_LIBS([clock_gettime], [rt] , [found_clock_gettime=yes], [found_clock_gettime=no])
if test x$found_clock_gettime = xyes; then
AC_DEFINE(DB_HAVE_CLOCK_GETTIME)
fi
dnl Checks for libraries.

View file

@ -32,8 +32,11 @@
#include "setup.h"
#include "serialport.h"
#include <time.h>
#ifdef DB_HAVE_CLOCK_GETTIME
//time.h is already included
#else
#include <sys/timeb.h>
#endif
/* if mem_systems 0 then size_extended is reported as the real size else
* zero is reported. ems and xms can increase or decrease the other_memsystems
@ -489,13 +492,23 @@ static Bitu INT11_Handler(void) {
#endif
static void BIOS_HostTimeSync() {
Bit32u milli = 0;
#ifdef DB_HAVE_CLOCK_GETTIME
struct timespec tp;
clock_gettime(CLOCK_REALTIME,&tp);
struct tm *loctime;
loctime = localtime(&tp.tv_sec);
milli = (Bit32u) (tp.tv_nsec / 1000000);
#else
/* Setup time and date */
struct timeb timebuffer;
ftime(&timebuffer);
struct tm *loctime;
loctime = localtime (&timebuffer.time);
milli = (Bit32u) timebuffer.millitm;
#endif
/*
loctime->tm_hour = 23;
loctime->tm_min = 59;
@ -513,7 +526,7 @@ static void BIOS_HostTimeSync() {
loctime->tm_hour*3600*1000+
loctime->tm_min*60*1000+
loctime->tm_sec*1000+
timebuffer.millitm))*(((double)PIT_TICK_RATE/65536.0)/1000.0));
milli))*(((double)PIT_TICK_RATE/65536.0)/1000.0));
mem_writed(BIOS_TIMER,ticks);
}