SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string);
SWITCH_DECLARE(switch_status_t) switch_console_set_alias(const char *string);
SWITCH_DECLARE(int) switch_system(const char *cmd, switch_bool_t wait);
-SWITCH_DECLARE(void) switch_cond_yield(uint32_t ms);
-
+SWITCH_DECLARE(void) switch_cond_yield(switch_interval_time_t t);
+SWITCH_DECLARE(void) switch_cond_next();
///\}
/*!
if (conference->video_running == 1) {
conference->video_running = -1;
while (conference->video_running) {
- switch_yield(1000);
+ switch_cond_next();
}
}
if (use_timer) {
switch_core_timer_next(&timer);
} else {
- switch_yield(1000);
+ switch_cond_next();
}
} /* Rinse ... Repeat */
/* Wait for the input thread to end */
while (switch_test_flag(member, MFLAG_ITHREAD)) {
- switch_yield(1000);
+ switch_cond_next();
}
}
if (eh.up) {
while (eh.up) {
- switch_yield(1000);
+ switch_cond_next();
}
}
switch_core_session_write_video_frame(session, &vid_frame, SWITCH_IO_FLAG_NONE, 0);
}
if (ts && last && last != ts) {
- switch_yield(1000);
+ switch_cond_next();
}
last = ts;
} else {
{
while(looping)
{
- switch_yield(1000);
+ switch_cond_next();
}
return SWITCH_STATUS_TERM;
}
status = SWITCH_STATUS_SUCCESS;
break;
}
- switch_yield(1000);
+ switch_cond_next();
continue;
}
if (switch_test_flag(tech_pvt, TFLAG_BYE) || !switch_test_flag(tech_pvt, TFLAG_IO)) {
goto done;
}
- switch_yield(1000);
+ switch_cond_next();
}
if (switch_channel_get_state(channel) >= CS_HANGUP || switch_test_flag(tech_pvt, TFLAG_BYE)) {
while (switch_test_flag(tech_pvt, TFLAG_IO)) {
if (!switch_test_flag(tech_pvt, TFLAG_CODEC)) {
- switch_yield(1000);
+ switch_cond_next();
continue;
}
if (switch_test_flag(tech_pvt, TFLAG_BREAK)) {
return SWITCH_STATUS_SUCCESS;
}
- switch_yield(1000);
+ switch_cond_next();
if (++ms_count >= 30000) {
break;
}
break;
}
- switch_yield(1000);
+ switch_cond_next();
}
if (switch_test_flag(tech_pvt, TFLAG_LINKED)) {
PaUtil_FlushRingBuffer(&aStream->outFIFO);
return 0;
}
- switch_yield(1000);
+ switch_cond_next();
}
}
return numFrames;
if (bytesRead) {
p += bytesRead;
} else {
- switch_yield(1000);
+ switch_cond_next();
}
}
return SWITCH_STATUS_SUCCESS;
}
- switch_yield(1000);
+ switch_cond_next();
}
// Maybe we should timeout?
while(switch_channel_ready(channel) && !switch_test_flag(tech_pvt, TFLAG_3PCC_HAS_ACK)) {
- switch_yield(1000);
+ switch_cond_next();
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "3PCC-PROXY, Done waiting for ACK\n");
}
switch_event_unbind_callback(general_event_handler);
while (mod_sofia_globals.threads) {
- switch_yield(1000);
+ switch_cond_next();
if (++sanity >= 10000) {
break;
}
break;
} else if (result == SWITCH_CORE_DB_BUSY) {
running++;
- switch_yield(1000);
+ switch_cond_next();
continue;
}
break;
return SWITCH_STATUS_SUCCESS;
}
- switch_yield(1000);
+ switch_cond_next();
}
return SWITCH_STATUS_FALSE;
if (switch_test_flag(tech_pvt, TFLAG_MEDIA)) {
break;
}
- switch_yield(1000);
+ switch_cond_next();
}
if (!tech_pvt->udp_socket) {
globals.running = -1;
while (x < 100000 && globals.running) {
x++;
- switch_yield(1000);
+ switch_cond_next();
}
}
}
}
if (do_sleep) {
- switch_yield(1000);
+ switch_cond_next();
}
}
sw_uint32 ms;
ms = 100;
sw_discovery_step(globals.discovery, &ms);
- switch_yield(1000);
+ switch_cond_next();
}
RUNNING = 0;
return SWITCH_STATUS_TERM;
switch_buffer_unlock(buffer);
} else {
if (!bytes) {
- switch_yield(1000);
+ switch_cond_next();
continue;
}
memset(buf, 0, bytes);
break;
}
- switch_yield(1000);
+ switch_cond_next();
}
JS_ResumeRequest(cx, saveDepth);
check_hangup_hook(jss, &ret);
break;
}
- switch_yield(1000);
+ switch_cond_next();
}
JS_ResumeRequest(cx, saveDepth);
check_hangup_hook(jss, &ret);
status = SWITCH_STATUS_FALSE;
break;
}
- switch_yield(1000);
+ switch_cond_next();
} else {
to_count = 0;
}
if (mystate != ostate || state >= CS_HANGUP || state == want_state) {
break;
}
- switch_yield(1000);
+ switch_cond_next();
}
}
}
}
- switch_yield(1000);
+ switch_cond_next();
if (super_channel && !switch_channel_ready(super_channel)) {
return SWITCH_STATUS_FALSE;
free(cmd);
}
}
- switch_yield(1000);
+ switch_cond_next();
}
switch_core_destroy_memory_pool(&pool);
}
ts->objs[0] = obj;
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+ switch_threadattr_priority_increase(thd_attr);
switch_thread_create(&thread, thd_attr, func, ts, pool);
}
}
#ifndef INSTANTLY_DESTROY_POOLS
memory_manager.pool_thread_running = -1;
while (memory_manager.pool_thread_running) {
- switch_yield(1000);
+ switch_cond_next();
}
#endif
}
switch_thread_create(&thread, thd_attr, pool_thread, NULL, memory_manager.memory_pool);
while (!memory_manager.pool_thread_running) {
- switch_yield(1000);
+ switch_cond_next();
}
#endif
}
if (nothing_in_queue) {
- switch_yield(1000);
+ switch_cond_next();
}
}
if (endstate == switch_channel_get_running_state(session->channel)) {
if (endstate == CS_NEW) {
- switch_yield(1000);
+ switch_cond_next();
} else {
switch_thread_cond_wait(session->cond, session->mutex);
}
}
while (x < 10000 && THREAD_COUNT) {
- switch_yield(1000);
+ switch_cond_next();
if (THREAD_COUNT == last) {
x++;
}
switch_thread_create(&thread, thd_attr, switch_event_thread, EVENT_QUEUE[2], RUNTIME_POOL);
while (!THREAD_COUNT) {
- switch_yield(1000);
+ switch_cond_next();
}
}
if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
- switch_yield(1000);
+ switch_cond_next();
continue;
}
if (switch_channel_test_flag(channel, CF_SERVICE) ||
(!switch_channel_test_flag(channel, CF_ANSWERED) && !switch_channel_test_flag(channel, CF_EARLY_MEDIA))) {
- switch_yield(1000);
+ switch_cond_next();
} else {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) {
}
if (switch_channel_test_flag(channel, CF_SERVICE)) {
- switch_yield(1000);
+ switch_cond_next();
} else {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
}
}
if (switch_channel_test_flag(channel, CF_SERVICE)) {
- switch_yield(1000);
+ switch_cond_next();
} else {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) {
#ifdef SWITCH_VIDEO_IN_THREADS
if (eh.up) {
while (eh.up) {
- switch_yield(1000);
+ switch_cond_next();
}
}
#endif
}
while (switch_channel_get_state(peer_channel) == CS_EXCHANGE_MEDIA) {
- switch_yield(1000);
+ switch_cond_next();
}
switch_core_session_rwunlock(peer_session);
}
}
} else {
- switch_yield(1000);
+ switch_cond_next();
}
}
goto notready;
}
- switch_yield(10000);
+ switch_yield(100000);
}
check_per_channel_timeouts(peer_channels, per_channel_timelimit_sec, per_channel_progress_timelimit_sec, and_argc, start);
}
} else {
- switch_yield(10000);
+ switch_yield(100000);
}
}
switch_thread_create(&thread, thd_attr, log_thread, NULL, LOG_POOL);
while (!THREAD_RUNNING) {
- switch_yield(1000);
+ switch_cond_next();
}
if (colorize) {
THREAD_RUNNING = -1;
switch_queue_push(LOG_QUEUE, NULL);
while (THREAD_RUNNING) {
- switch_yield(1000);
+ switch_cond_next();
}
switch_core_memory_reclaim_logger();
if (++x > 1000) {
break;
}
- switch_yield(1000);
+ switch_cond_next();
}
switch_socket_opt_set(new_sock, SWITCH_SO_NONBLOCK, FALSE);
rtp_session->recv_msg.header.ts = htonl(jb_frame->ts);
} else if (!bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) { /* We're late! We're Late! */
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK) && status == SWITCH_STATUS_BREAK) {
- switch_yield(1000);
+ switch_cond_next();
continue;
}
switch_socket_close(sock);
return SWITCH_STATUS_TIMEOUT;
}
- switch_yield(1000);
+ switch_cond_next();
}
switch_socket_close(sock);
SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t)
{
- if (t < 1000) {
+ if (t < 1000 || t >= 10000) {
do_sleep(t);
return;
}
#ifndef DISABLE_1MS_COND
if (globals.use_cond_yield == 1) {
- switch_cond_yield((uint32_t)(t / 1000));
+ switch_cond_yield(t);
return;
}
#endif
}
-SWITCH_DECLARE(void) switch_cond_yield(uint32_t ms)
+SWITCH_DECLARE(void) switch_cond_next(void)
{
- if (!ms) return;
-
- if (globals.use_cond_yield != 1) {
- do_sleep(ms * 1000);
+#ifdef DISABLE_1MS_COND
+ do_sleep(1000);
+#else
+ if (!runtime.timestamp || globals.use_cond_yield != 1) {
+ do_sleep(1000);
return;
}
-
switch_mutex_lock(TIMER_MATRIX[1].mutex);
- while(globals.RUNNING == 1 && globals.use_cond_yield == 1 && ms--) {
- switch_thread_cond_wait(TIMER_MATRIX[1].cond, TIMER_MATRIX[1].mutex);
- }
+ switch_thread_cond_wait(TIMER_MATRIX[1].cond, TIMER_MATRIX[1].mutex);
switch_mutex_unlock(TIMER_MATRIX[1].mutex);
+#endif
+}
+
+SWITCH_DECLARE(void) switch_cond_yield(switch_interval_time_t t)
+{
+ switch_time_t want;
+ if (!t) return;
+
+ if (!runtime.timestamp || globals.use_cond_yield != 1) {
+ do_sleep(t);
+ return;
+ }
+ want = runtime.timestamp + t;
+ while(globals.RUNNING == 1 && globals.use_cond_yield == 1 && runtime.timestamp < want) {
+ switch_mutex_lock(TIMER_MATRIX[1].mutex);
+ if (runtime.timestamp < want) {
+ switch_thread_cond_wait(TIMER_MATRIX[1].cond, TIMER_MATRIX[1].mutex);
+ }
+ switch_mutex_unlock(TIMER_MATRIX[1].mutex);
+ }
+
}
static switch_status_t timer_next(switch_timer_t *timer)
{
timer_private_t *private_info = timer->private_info;
- timer_step(timer);
-#if 1
- switch_mutex_lock(TIMER_MATRIX[timer->interval].mutex);
- while (globals.RUNNING == 1 && private_info->ready && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
- check_roll();
- switch_thread_cond_wait(TIMER_MATRIX[timer->interval].cond, TIMER_MATRIX[timer->interval].mutex);
- }
- switch_mutex_unlock(TIMER_MATRIX[timer->interval].mutex);
+#ifdef DISABLE_1MS_COND
+ int cond_index = timer->interval;
#else
+ int cond_index = 1;
+#endif
+
+ timer_step(timer);
+
while (globals.RUNNING == 1 && private_info->ready && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
check_roll();
- do_sleep(1000);
+ if (globals.use_cond_yield == 1) {
+ switch_mutex_lock(TIMER_MATRIX[cond_index].mutex);
+ if (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
+ switch_thread_cond_wait(TIMER_MATRIX[cond_index].cond, TIMER_MATRIX[cond_index].mutex);
+ }
+ switch_mutex_unlock(TIMER_MATRIX[cond_index].mutex);
+ } else {
+ do_sleep(1000);
+ }
}
-#endif
-
+
if (globals.RUNNING == 1) {
return SWITCH_STATUS_SUCCESS;
}
if ((current_ms % x) == 0) {
if (TIMER_MATRIX[x].count) {
TIMER_MATRIX[x].tick++;
-#if 1
+#ifdef DISABLE_1MS_COND
if (TIMER_MATRIX[x].mutex && switch_mutex_trylock(TIMER_MATRIX[x].mutex) == SWITCH_STATUS_SUCCESS) {
switch_thread_cond_broadcast(TIMER_MATRIX[x].cond);
switch_mutex_unlock(TIMER_MATRIX[x].mutex);
timer_interface->timer_destroy = timer_destroy;
/* indicate that the module should continue to be loaded */
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_NOUNLOAD;
}
SWITCH_MODULE_SHUTDOWN_FUNCTION(softtimer_shutdown)
{
+ globals.use_cond_yield = 0;
+
if (globals.RUNNING == 1) {
switch_mutex_lock(globals.mutex);
globals.RUNNING = -1;