mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-06-03 03:50:10 +00:00
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:
parent
f601c8f0f2
commit
61bdc9c16e
@ -96,17 +96,27 @@ SWITCH_DECLARE(time_t) switch_timestamp(time_t *t)
|
|||||||
return now;
|
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)
|
static switch_time_t time_now(int64_t offset)
|
||||||
{
|
{
|
||||||
switch_time_t now;
|
switch_time_t now;
|
||||||
|
|
||||||
#if defined(HAVE_CLOCK_GETTIME)
|
#if defined(HAVE_CLOCK_GETTIME)
|
||||||
struct timespec ts;
|
if (MONO) {
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
struct timespec ts;
|
||||||
now = ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec/1000) + offset;
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
now = ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec/1000) + offset;
|
||||||
#else
|
} else {
|
||||||
|
#endif
|
||||||
now = switch_time_now();
|
now = switch_time_now();
|
||||||
|
|
||||||
|
#if defined(HAVE_CLOCK_GETTIME)
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return now;
|
return now;
|
||||||
@ -283,6 +293,24 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
|
|||||||
runtime.sps = runtime.sps_total;
|
runtime.sps = runtime.sps_total;
|
||||||
switch_mutex_unlock(runtime.throttle_mutex);
|
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) {
|
while (globals.RUNNING == 1) {
|
||||||
runtime.reference += STEP_MIC;
|
runtime.reference += STEP_MIC;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user