diff --git a/Makefile.am b/Makefile.am index 23a2141af2..5631c6a506 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,7 +56,7 @@ src/switch_stun.c\ src/switch_log.c\ src/switch_xml.c\ src/switch_config.c\ -src/softtimer.c\ +src/switch_time.c\ libs/stfu/stfu.c\ src/switch_cpp.cpp\ libs/libteletone/src/libteletone_detect.c\ diff --git a/configure.in b/configure.in index 547e4cb075..20ae00f262 100644 --- a/configure.in +++ b/configure.in @@ -188,6 +188,9 @@ AC_FUNC_STRFTIME AC_CHECK_FUNCS([gethostname vasprintf mmap mlock mlockall usleep]) AC_CHECK_FUNCS([sched_setscheduler setpriority setrlimit setgroups initgroups]) +AC_CHECK_LIB(rt, clock_gettime, [AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define if you have clock_gettime()])]) +AC_CHECK_LIB(rt, clock_nanosleep, [AC_DEFINE(HAVE_CLOCK_NANOSLEEP, 1, [Define if you have clock_nanosleep()])]) + AC_CHECK_DECL([RLIMIT_MEMLOCK], [AC_DEFINE([HAVE_RLIMIT_MEMLOCK],[1],[RLIMIT_MEMLOCK constant for setrlimit])],, [#ifdef HAVE_SYS_RESOURCE_H diff --git a/src/switch_apr.c b/src/switch_apr.c index 5546fd97a6..6f02df7540 100644 --- a/src/switch_apr.c +++ b/src/switch_apr.c @@ -233,7 +233,13 @@ SWITCH_DECLARE(switch_status_t) switch_mutex_trylock(switch_mutex_t * lock) SWITCH_DECLARE(switch_time_t) switch_time_now(void) { +#ifdef HAVE_CLOCK_GETTIME + struct timespec ts; + clock_gettime(CLOCK_REALTIME,&ts); + return ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec/1000); +#else return (switch_time_t) apr_time_now(); +#endif } SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt_get(switch_time_t * result, switch_time_exp_t * input) @@ -256,17 +262,6 @@ SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt(switch_time_exp_t * result, return apr_time_exp_gmt((apr_time_exp_t *) result, input); } -SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t) -{ -#if defined(HAVE_USLEEP) - usleep(t); -#elif defined(WIN32) - Sleep((DWORD) ((t) / 1000)); -#else - apr_sleep(t); -#endif -} - SWITCH_DECLARE(switch_status_t) switch_rfc822_date(char *date_str, switch_time_t t) { diff --git a/src/softtimer.c b/src/switch_time.c similarity index 95% rename from src/softtimer.c rename to src/switch_time.c index 0444555535..a4a4e0dd65 100644 --- a/src/softtimer.c +++ b/src/switch_time.c @@ -80,6 +80,29 @@ static timer_matrix_t TIMER_MATRIX[MAX_ELEMENTS + 1]; #define IDLE_SPEED 100 +SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t) +{ + +#if defined(HAVE_CLOCK_NANOSLEEP) + struct timespec ts; + ts.tv_sec = t / APR_USEC_PER_SEC; + ts.tv_nsec = (t % APR_USEC_PER_SEC) * 1000; + + clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL); + +#elif defined(HAVE_USLEEP) + usleep(t); +#elif defined(WIN32) + Sleep((DWORD) ((t) / 1000)); +#else + apr_sleep(t); +#endif + + +} + + + static switch_status_t timer_init(switch_timer_t *timer) { timer_private_t *private_info;