workaround for kernel bug

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28668 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2009-09-14 12:44:52 +00:00
parent 640ae938c6
commit e1eae65cf7
2 changed files with 37 additions and 12 deletions

View file

@ -1,3 +1,7 @@
2009-09-14 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSCalendarDate.m: Workaround for bug in some linux SMP systems
2009-09-12 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSCalendarDate.m: Add optional diagnostics to detect system

View file

@ -296,6 +296,39 @@ GSTimeNow(void)
gettimeofday (&tp, NULL);
t = (NSTimeInterval)tp.tv_sec - NSTimeIntervalSince1970;
t += (NSTimeInterval)tp.tv_usec / (NSTimeInterval)1000000.0;
#if 1
/* This is a workaround for a bug on some SMP intel systems where the TSC
* clock information from the processors gets out of sync and causes a
* leap of 4398 seconds into the future for an instant, and then back.
* If we detect a time jump back (or forwards by that sort of amount)
* we refettch the system time.
*/
{
static int old = 0;
if (old == 0)
{
old = tp.tv_sec;
}
else
{
int diff = tp.tv_sec - old;
old = tp.tv_sec;
if (diff < 0 || diff > 3000)
{
time_t now = (time_t)tp.tv_sec;
fprintf(stderr, "WARNING: system time changed by %d seconds: %s\n",
diff, ctime(&now));
/* Get time again ... should be OK now.
*/
t = GSTimeNow();
}
}
}
#endif
#else
SYSTEMTIME sys_time;
/*
@ -306,18 +339,6 @@ GSTimeNow(void)
sys_time.wMinute, sys_time.wSecond, sys_time.wMilliseconds);
#endif /* __MINGW32__ */
#if defined(DEBUG)
{
static NSTimeInterval old = 0.0;
if (t < old)
{
fprintf(stderr, "WARNING: system time changed by %g seconds\n",
t - old);
}
old = t;
}
#endif
return t;
}