]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-4646 --resolve thanks for the update
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 22 Jan 2013 16:01:52 +0000 (10:01 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 22 Jan 2013 16:01:52 +0000 (10:01 -0600)
src/include/private/switch_core_pvt.h
src/switch_core.c
src/switch_time.c

index 7bdf1e3dd065e78389fd8496437eb5d299f3d50e..e4e8dc7c6f4b161842d4a8800474f2928a888ce0 100644 (file)
@@ -214,8 +214,6 @@ typedef enum {
 
 struct switch_runtime {
        switch_time_t initiated;
-       switch_time_t mono_initiated;
-       switch_time_t mono_reference;
        switch_time_t reference;
        int64_t offset;
        switch_event_t *global_vars;
index e7e3c953ade4ccdb81e29e39fbc25642edb33cb0..4f6a99ed9fede7c3ac7df332fd62f8652a258458 100644 (file)
@@ -1664,8 +1664,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
        switch_rtp_init(runtime.memory_pool);
 
        runtime.running = 1;
-       runtime.initiated = switch_time_now();
-       runtime.mono_initiated = switch_mono_micro_time_now();
+       runtime.initiated = switch_mono_micro_time_now();
        
        switch_scheduler_add_task(switch_epoch_time_now(NULL), heartbeat_callback, "heartbeat", "core", 0, NULL, SSHF_NONE | SSHF_NO_DEL);
 
@@ -2102,7 +2101,7 @@ SWITCH_DECLARE(void) switch_core_measure_time(switch_time_t total_ms, switch_cor
 
 SWITCH_DECLARE(switch_time_t) switch_core_uptime(void)
 {
-       return switch_mono_micro_time_now() - runtime.mono_initiated;
+       return switch_mono_micro_time_now() - runtime.initiated;
 }
 
 
index 5a33a208c4cb714e1b5865438894e483429acc14..6d5bfabd470f1d00a1685b9e97229a2344bcbb01 100644 (file)
@@ -180,6 +180,7 @@ static void do_sleep(switch_interval_time_t t)
        clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
 
 #elif defined(DARWIN)
+       t -= OFFSET;
        ts.tv_sec = t / APR_USEC_PER_SEC;
        ts.tv_nsec = (t % APR_USEC_PER_SEC) * 1000;
        nanosleep(&ts, NULL);
@@ -447,7 +448,7 @@ SWITCH_DECLARE(switch_time_t) switch_time_ref(void)
                return time_now(0);
        } else {
                /* Return monotonic time reference (when available) */
-               return time_now(-1);
+               return switch_mono_micro_time_now();
        }
 }
 
@@ -461,14 +462,12 @@ SWITCH_DECLARE(void) switch_time_sync(void)
 
        if (SYSTEM_TIME) {
                runtime.reference = time_now(0);
-               runtime.mono_reference = time_now(-1);
                runtime.offset = 0;
        } else {
-               runtime.offset = runtime.reference - time_now(-1); /* Get the offset between system time and the monotonic clock (when available) */
+               runtime.offset = runtime.reference - switch_mono_micro_time_now(); /* Get the offset between system time and the monotonic clock (when available) */
                runtime.reference = time_now(runtime.offset);
        }
 
-
        if (runtime.reference - last_time > 1000000 || last_time == 0) {
                if (SYSTEM_TIME) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Clock is already configured to always report system time.\n");
@@ -901,6 +900,8 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
                while (((ts = time_now(runtime.offset)) + 100) < runtime.reference) {
                        if (ts < last) {
                                if (MONO) {
+                                       runtime.initiated = switch_mono_micro_time_now() - ((last - runtime.offset) - runtime.initiated);
+
                                        if (time_sync == runtime.time_sync) { /* Only resync if not in the middle of switch_time_sync() already */
                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Virtual Migration Detected! Syncing Clock\n");
                                                win32_init_timers(); /* Make sure to reinit timers on WIN32 */
@@ -918,8 +919,13 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
                                }
 
                                if (!MONO || time_sync == runtime.time_sync) {
+#if defined(HAVE_CLOCK_NANOSLEEP)
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
                                                                          "If you see this message many times try setting the param enable-clock-nanosleep to true in switch.conf.xml or consider a nicer machine to run me on. I AM *FREE* afterall.\n");
+#else
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
+                                                                         "If you see this message many times consider a nicer machine to run me on. I AM *FREE* afterall.\n");
+#endif
                                }
                        } else {
                                rev_errs = 0;
@@ -955,6 +961,8 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
 
                if (ts > (runtime.reference + too_late)) {
                        if (MONO) {
+                               runtime.initiated = switch_mono_micro_time_now() - (((runtime.reference - runtime.microseconds_per_tick) - runtime.offset) - runtime.initiated);
+
                                if (time_sync == runtime.time_sync) { /* Only resync if not in the middle of switch_time_sync() already */
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Virtual Migration Detected! Syncing Clock\n");
                                        win32_init_timers(); /* Make sure to reinit timers on WIN32 */
@@ -962,7 +970,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
                                        time_sync = runtime.time_sync;
                                }
                        } else {
-                               switch_time_t diff = ts - runtime.reference - runtime.microseconds_per_tick;
+                               switch_time_t diff = ts - (runtime.reference - runtime.microseconds_per_tick);
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Forward Clock Skew Detected!\n");
                                fwd_errs++;
                                runtime.reference = switch_time_now();
@@ -1296,7 +1304,7 @@ SWITCH_MODULE_LOAD_FUNCTION(softtimer_load)
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Enabled Windows monotonic clock, using timeGetTime()\n");
                }
 
-               runtime.mono_initiated = switch_mono_micro_time_now(); /* Update mono_initiated, since now is the first time the real clock is enabled */
+               runtime.initiated = switch_mono_micro_time_now(); /* Update mono_initiated, since now is the first time the real clock is enabled */
        }
 
        /* No need to calibrate clock in Win32, we will only sleep ms anyway, it's just not accurate enough */