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);
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;
}
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);
return time_now(0);
} else {
/* Return monotonic time reference (when available) */
- return time_now(-1);
+ return switch_mono_micro_time_now();
}
}
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");
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 */
}
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;
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 */
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();
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 */