detect broken monotonic clocks

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7322 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-01-23 15:26:57 +00:00
parent f601c8f0f2
commit 61bdc9c16e
1 changed files with 33 additions and 5 deletions

View File

@ -96,17 +96,27 @@ SWITCH_DECLARE(time_t) switch_timestamp(time_t *t)
return now;
}
#if defined(HAVE_CLOCK_GETTIME)
static int MONO = 1;
#else
static int MONO = 0;
#endif
static switch_time_t time_now(int64_t offset)
{
switch_time_t now;
#if defined(HAVE_CLOCK_GETTIME)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
now = ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec/1000) + offset;
#else
if (MONO) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
now = ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec/1000) + offset;
} else {
#endif
now = switch_time_now();
#if defined(HAVE_CLOCK_GETTIME)
}
#endif
return now;
@ -283,6 +293,24 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
runtime.sps = runtime.sps_total;
switch_mutex_unlock(runtime.throttle_mutex);
if (MONO) {
int loops;
for(loops = 0; loops < 3; loops++) {
ts = time_now(0);
/* if it returns the same value every time it won't be of much use.*/
if (ts == last) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Broken MONOTONIC Clock Detected!, Support Disabled.\n");
MONO = 0;
runtime.reference = switch_time_now();
runtime.initiated = runtime.reference;
}
switch_yield(STEP_MIC);
last = ts;
}
}
ts = 0;
last = 0;
while (globals.RUNNING == 1) {
runtime.reference += STEP_MIC;