[Freeswitch-svn] [commit] r7322 - freeswitch/trunk/src

Freeswitch SVN anthm at freeswitch.org
Wed Jan 23 10:26:57 EST 2008


Author: anthm
Date: Wed Jan 23 10:26:57 2008
New Revision: 7322

Modified:
   freeswitch/trunk/src/switch_time.c

Log:
detect broken monotonic clocks

Modified: freeswitch/trunk/src/switch_time.c
==============================================================================
--- freeswitch/trunk/src/switch_time.c	(original)
+++ freeswitch/trunk/src/switch_time.c	Wed Jan 23 10:26:57 2008
@@ -96,17 +96,27 @@
 	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 @@
 	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;



More information about the Freeswitch-svn mailing list