[Freeswitch-svn] [commit] r10357 - in freeswitch/trunk/src: . include mod/applications/mod_commands
FreeSWITCH SVN
anthm at freeswitch.org
Wed Nov 12 05:55:23 PST 2008
Author: anthm
Date: Wed Nov 12 08:55:22 2008
New Revision: 10357
Log:
posturepedics for better sleep
Modified:
freeswitch/trunk/src/include/switch_apr.h
freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
freeswitch/trunk/src/switch_time.c
Modified: freeswitch/trunk/src/include/switch_apr.h
==============================================================================
--- freeswitch/trunk/src/include/switch_apr.h (original)
+++ freeswitch/trunk/src/include/switch_apr.h Wed Nov 12 08:55:22 2008
@@ -337,6 +337,7 @@
* @warning May sleep for longer than the specified time.
*/
SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t);
+SWITCH_DECLARE(void) switch_micro_sleep(switch_interval_time_t t);
/** @} */
Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c Wed Nov 12 08:55:22 2008
@@ -42,6 +42,36 @@
SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load);
SWITCH_MODULE_DEFINITION(mod_commands, mod_commands_load, NULL, NULL);
+SWITCH_STANDARD_API(time_test_function)
+{
+ switch_time_t now, then;
+ int x;
+ long mss = atol(cmd);
+ uint32_t total = 0;
+ int diff;
+ int max = 10;
+ char *p;
+
+ if ((p = strchr(cmd, ' '))) {
+ max = atoi(p+1);
+ if (max < 0) {
+ max = 10;
+ }
+ }
+
+ for (x = 0; x < max; x++) {
+ then = switch_time_now();
+ switch_yield(mss);
+ now = switch_time_now();
+ diff = (int) now - then;
+ stream->write_function(stream, "test %d sleep %ld %d\n", x+1, mss, diff);
+ total += diff;
+ }
+ stream->write_function(stream, "avg %d\n", total / x);
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
SWITCH_STANDARD_API(user_data_function)
{
switch_xml_t x_domain, xml = NULL, x_user = NULL, x_param, x_params;
@@ -2939,6 +2969,7 @@
SWITCH_ADD_API(commands_api_interface, "uuid_send_dtmf", "send dtmf digits", uuid_send_dtmf_function, UUID_SEND_DTMF_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "eval", "eval (noop)", eval_function, "<expression>");
SWITCH_ADD_API(commands_api_interface, "system", "Execute a system command", system_function, SYSTEM_SYNTAX);
+ SWITCH_ADD_API(commands_api_interface, "time_test", "time_test", time_test_function, "<mss>");
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_NOUNLOAD;
Modified: freeswitch/trunk/src/switch_time.c
==============================================================================
--- freeswitch/trunk/src/switch_time.c (original)
+++ freeswitch/trunk/src/switch_time.c Wed Nov 12 08:55:22 2008
@@ -106,25 +106,6 @@
#endif
-static void do_yield(switch_interval_time_t t)
-{
-#if defined(HAVE_CLOCK_NANOSLEEP) && defined(SWITCH_USE_CLOCK_FUNCS)
- 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
-
-}
-
SWITCH_DECLARE(void) switch_time_set_monotonic(switch_bool_t enable)
{
MONO = enable ? 1 : 0;
@@ -158,39 +139,29 @@
runtime.reference = time_now(runtime.offset);
}
+SWITCH_DECLARE(void) switch_micro_sleep(switch_interval_time_t t)
+{
+ apr_sleep(t);
+}
+
SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t)
{
+ if (t <= 1000) {
+#if defined(WIN32)
+ Sleep(1);
+#else
+ apr_sleep(t);
+#endif
+ return;
+ }
+
if (globals.use_cond_yield == 1) {
switch_cond_yield((uint32_t)(t / 1000));
return;
}
-
-#if defined(HAVE_USLEEP)
- usleep(t);
-#elif defined(WIN32)
- Sleep((DWORD) ((t) / 1000));
-#else
- apr_sleep(t);
-#endif
-
-#if 0
-#if defined(HAVE_CLOCK_NANOSLEEP) && defined(SWITCH_USE_CLOCK_FUNCS)
- 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
-#endif
-
}
@@ -199,7 +170,8 @@
if (!ms) return;
if (globals.use_cond_yield != 1) {
- do_yield(ms * 1000);
+ apr_sleep(ms * 1000);
+ return;
}
switch_mutex_lock(TIMER_MATRIX[1].mutex);
@@ -216,7 +188,7 @@
int sanity = 0;
while (globals.STARTED == 0) {
- do_yield(100000);
+ apr_sleep(100000);
if (++sanity == 10) {
break;
}
@@ -312,7 +284,7 @@
#else
while (globals.RUNNING == 1 && private_info->ready && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
check_roll();
- do_yield(1000);
+ apr_sleep(1000);
}
#endif
@@ -396,7 +368,7 @@
runtime.initiated = runtime.reference;
break;
}
- do_yield(STEP_MIC);
+ apr_sleep(STEP_MIC);
last = ts;
}
}
@@ -431,7 +403,7 @@
} else {
rev_errs = 0;
}
- do_yield(STEP_MIC);
+ apr_sleep(STEP_MIC);
last = ts;
}
@@ -739,7 +711,7 @@
switch_mutex_unlock(globals.mutex);
while (globals.RUNNING == -1) {
- do_yield(10000);
+ apr_sleep(10000);
}
}
#if defined(WIN32)
More information about the Freeswitch-svn
mailing list