SWITCH_DECLARE(switch_bool_t) switch_check_network_list_ip_token(const char *ip_str, const char *list_name, const char **token);
#define switch_check_network_list_ip(_ip_str, _list_name) switch_check_network_list_ip_token(_ip_str, _list_name, NULL)
SWITCH_DECLARE(void) switch_time_set_monotonic(switch_bool_t enable);
+SWITCH_DECLARE(void) switch_time_set_timerfd(switch_bool_t enable);
SWITCH_DECLARE(void) switch_time_set_nanosleep(switch_bool_t enable);
SWITCH_DECLARE(void) switch_time_set_matrix(switch_bool_t enable);
SWITCH_DECLARE(void) switch_time_set_cond_yield(switch_bool_t enable);
}
} else if (!strcasecmp(var, "enable-monotonic-timing")) {
switch_time_set_monotonic(switch_true(var));
+ } else if (!strcasecmp(var, "enable-softtimer-timerfd")) {
+ switch_time_set_timerfd(switch_true(var));
} else if (!strcasecmp(var, "enable-clock-nanosleep")) {
switch_time_set_nanosleep(switch_true(var));
} else if (!strcasecmp(var, "enable-cond-yield")) {
#include <switch.h>
#include <stdio.h>
#include "private/switch_core_pvt.h"
+#ifdef HAVE_TIMERFD_CREATE
+#include <sys/timerfd.h>
+#endif
//#if defined(DARWIN)
#define DISABLE_1MS_COND
static int MONO = 0;
#endif
+#if defined(HAVE_TIMERFD_CREATE)
+// We'll default this to 1 after we have had some positive feedback that it works well
+static int TFD = 0;
+#else
+static int TFD = 0;
+#endif
+
static int NANO = 0;
static int OFFSET = 0;
CRITICAL_SECTION timer_section;
#endif
-#define ONEMS
-#ifdef ONEMS
static int STEP_MS = 1;
static int STEP_MIC = 1000;
static uint32_t TICK_PER_SEC = 1000;
static int MS_PER_TICK = 10;
-#else
-static int STEP_MS = 10;
-static int STEP_MIC = 10000;
-static uint32_t TICK_PER_SEC = 1000;
-static int MS_PER_TICK = 10;
-#endif
static switch_memory_pool_t *module_pool = NULL;
SWITCH_DECLARE(void) switch_time_set_monotonic(switch_bool_t enable)
{
+#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
MONO = enable ? 1 : 0;
switch_time_sync();
+#else
+ MONO = 0;
+#endif
+}
+
+
+SWITCH_DECLARE(void) switch_time_set_timerfd(switch_bool_t enable)
+{
+#if defined(HAVE_TIMERFD_CREATE)
+ TFD = enable ? 1 : 0;
+ switch_time_sync();
+#else
+ TFD = 0;
+#endif
}
if (timer->interval > 0 && timer->interval < MS_PER_TICK) {
MS_PER_TICK = timer->interval;
- STEP_MS = 1;
- STEP_MIC = 1000;
- TICK_PER_SEC = 10000;
switch_time_sync();
}
switch_time_t ts = 0, last = 0;
int fwd_errs = 0, rev_errs = 0;
int profile_tick = 0;
+ int tfd = -1;
+
+#ifdef HAVE_TIMERFD_CREATE
+ struct itimerspec spec = { { 0 } };
+
+ if (MONO && TFD) {
+ tfd = timerfd_create(CLOCK_MONOTONIC, 0);
+
+ if (tfd > -1) {
+ spec.it_interval.tv_sec = 0;
+ spec.it_interval.tv_nsec = 1000000;
+ spec.it_value.tv_sec = spec.it_interval.tv_sec;
+ spec.it_value.tv_nsec = spec.it_interval.tv_nsec;
+
+ if (timerfd_settime(tfd, TFD_TIMER_ABSTIME, &spec, NULL)) {
+ close(tfd);
+ tfd = -1;
+ }
+ }
+ }
+#else
+ tfd = -1;
+#endif
runtime.profile_timer = switch_new_profile_timer();
switch_get_system_idle_time(runtime.profile_timer, &runtime.profile_time);
if (globals.timer_count >= runtime.tipping_point) {
os_yield();
} else {
- do_sleep(1000);
+ if (tfd > -1 && globals.RUNNING == 1) {
+ uint64_t exp;
+ int r;
+ r = read(tfd, &exp, sizeof(exp));
+ } else {
+ do_sleep(1000);
+ }
}
last = ts;
}
}
+ if (tfd > -1) {
+ close(tfd);
+ tfd = -1;
+ }
+
switch_mutex_lock(globals.mutex);
globals.RUNNING = 0;