more stuff

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10410 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-11-14 23:31:21 +00:00
parent bca7917503
commit 2ed601f934
35 changed files with 104 additions and 76 deletions

View File

@ -1682,8 +1682,8 @@ SWITCH_DECLARE(uint32_t) switch_core_default_dtmf_duration(uint32_t duration);
SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string); 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(switch_status_t) switch_console_set_alias(const char *string);
SWITCH_DECLARE(int) switch_system(const char *cmd, switch_bool_t wait); 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();
///\} ///\}
/*! /*!

View File

@ -1195,7 +1195,7 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, v
if (conference->video_running == 1) { if (conference->video_running == 1) {
conference->video_running = -1; conference->video_running = -1;
while (conference->video_running) { while (conference->video_running) {
switch_yield(1000); switch_cond_next();
} }
} }
@ -2010,7 +2010,7 @@ static void conference_loop_output(conference_member_t *member)
if (use_timer) { if (use_timer) {
switch_core_timer_next(&timer); switch_core_timer_next(&timer);
} else { } else {
switch_yield(1000); switch_cond_next();
} }
} /* Rinse ... Repeat */ } /* Rinse ... Repeat */
@ -2032,7 +2032,7 @@ static void conference_loop_output(conference_member_t *member)
/* Wait for the input thread to end */ /* Wait for the input thread to end */
while (switch_test_flag(member, MFLAG_ITHREAD)) { while (switch_test_flag(member, MFLAG_ITHREAD)) {
switch_yield(1000); switch_cond_next();
} }
} }

View File

@ -203,7 +203,7 @@ SWITCH_STANDARD_APP(record_fsv_function)
if (eh.up) { if (eh.up) {
while (eh.up) { while (eh.up) {
switch_yield(1000); switch_cond_next();
} }
} }
@ -320,7 +320,7 @@ SWITCH_STANDARD_APP(play_fsv_function)
switch_core_session_write_video_frame(session, &vid_frame, SWITCH_IO_FLAG_NONE, 0); switch_core_session_write_video_frame(session, &vid_frame, SWITCH_IO_FLAG_NONE, 0);
} }
if (ts && last && last != ts) { if (ts && last && last != ts) {
switch_yield(1000); switch_cond_next();
} }
last = ts; last = ts;
} else { } else {

View File

@ -64,7 +64,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_skel_runtime)
{ {
while(looping) while(looping)
{ {
switch_yield(1000); switch_cond_next();
} }
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }

View File

@ -302,7 +302,7 @@ static switch_status_t cepstral_speech_read_tts(switch_speech_handle_t *sh, void
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
break; break;
} }
switch_yield(1000); switch_cond_next();
continue; continue;
} }

View File

@ -1112,7 +1112,7 @@ static switch_status_t negotiate_media(switch_core_session_t *session)
if (switch_test_flag(tech_pvt, TFLAG_BYE) || !switch_test_flag(tech_pvt, TFLAG_IO)) { if (switch_test_flag(tech_pvt, TFLAG_BYE) || !switch_test_flag(tech_pvt, TFLAG_IO)) {
goto done; goto done;
} }
switch_yield(1000); switch_cond_next();
} }
if (switch_channel_get_state(channel) >= CS_HANGUP || switch_test_flag(tech_pvt, TFLAG_BYE)) { if (switch_channel_get_state(channel) >= CS_HANGUP || switch_test_flag(tech_pvt, TFLAG_BYE)) {

View File

@ -583,7 +583,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
while (switch_test_flag(tech_pvt, TFLAG_IO)) { while (switch_test_flag(tech_pvt, TFLAG_IO)) {
if (!switch_test_flag(tech_pvt, TFLAG_CODEC)) { if (!switch_test_flag(tech_pvt, TFLAG_CODEC)) {
switch_yield(1000); switch_cond_next();
continue; continue;
} }
if (switch_test_flag(tech_pvt, TFLAG_BREAK)) { if (switch_test_flag(tech_pvt, TFLAG_BREAK)) {
@ -615,7 +615,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
switch_yield(1000); switch_cond_next();
if (++ms_count >= 30000) { if (++ms_count >= 30000) {
break; break;
} }

View File

@ -491,7 +491,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
break; break;
} }
switch_yield(1000); switch_cond_next();
} }
if (switch_test_flag(tech_pvt, TFLAG_LINKED)) { if (switch_test_flag(tech_pvt, TFLAG_LINKED)) {

View File

@ -131,7 +131,7 @@ long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switc
PaUtil_FlushRingBuffer(&aStream->outFIFO); PaUtil_FlushRingBuffer(&aStream->outFIFO);
return 0; return 0;
} }
switch_yield(1000); switch_cond_next();
} }
} }
return numFrames; return numFrames;
@ -169,7 +169,7 @@ long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switch
if (bytesRead) { if (bytesRead) {
p += bytesRead; p += bytesRead;
} else { } else {
switch_yield(1000); switch_cond_next();
} }
} }

View File

@ -309,7 +309,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
switch_yield(1000); switch_cond_next();
} }

View File

@ -453,7 +453,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
// Maybe we should timeout? // Maybe we should timeout?
while(switch_channel_ready(channel) && !switch_test_flag(tech_pvt, TFLAG_3PCC_HAS_ACK)) { 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_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "3PCC-PROXY, Done waiting for ACK\n");
} }
@ -2549,7 +2549,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sofia_shutdown)
switch_event_unbind_callback(general_event_handler); switch_event_unbind_callback(general_event_handler);
while (mod_sofia_globals.threads) { while (mod_sofia_globals.threads) {
switch_yield(1000); switch_cond_next();
if (++sanity >= 10000) { if (++sanity >= 10000) {
break; break;
} }

View File

@ -3159,7 +3159,7 @@ char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex
break; break;
} else if (result == SWITCH_CORE_DB_BUSY) { } else if (result == SWITCH_CORE_DB_BUSY) {
running++; running++;
switch_yield(1000); switch_cond_next();
continue; continue;
} }
break; break;

View File

@ -1052,7 +1052,7 @@ static switch_status_t unicall_read_frame(switch_core_session_t *session, switch
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
switch_yield(1000); switch_cond_next();
} }
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;

View File

@ -338,7 +338,7 @@ static switch_status_t woomera_read_frame(switch_core_session_t *session, switch
if (switch_test_flag(tech_pvt, TFLAG_MEDIA)) { if (switch_test_flag(tech_pvt, TFLAG_MEDIA)) {
break; break;
} }
switch_yield(1000); switch_cond_next();
} }
if (!tech_pvt->udp_socket) { if (!tech_pvt->udp_socket) {

View File

@ -253,7 +253,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_event_multicast_shutdown)
globals.running = -1; globals.running = -1;
while (x < 100000 && globals.running) { while (x < 100000 && globals.running) {
x++; x++;
switch_yield(1000); switch_cond_next();
} }
} }

View File

@ -1049,7 +1049,7 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event,
} }
} }
if (do_sleep) { if (do_sleep) {
switch_yield(1000); switch_cond_next();
} }
} }

View File

@ -303,7 +303,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_zeroconf_runtime)
sw_uint32 ms; sw_uint32 ms;
ms = 100; ms = 100;
sw_discovery_step(globals.discovery, &ms); sw_discovery_step(globals.discovery, &ms);
switch_yield(1000); switch_cond_next();
} }
RUNNING = 0; RUNNING = 0;
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;

View File

@ -1195,7 +1195,7 @@ void do_telecast(switch_stream_handle_t *stream)
switch_buffer_unlock(buffer); switch_buffer_unlock(buffer);
} else { } else {
if (!bytes) { if (!bytes) {
switch_yield(1000); switch_cond_next();
continue; continue;
} }
memset(buf, 0, bytes); memset(buf, 0, bytes);

View File

@ -2135,7 +2135,7 @@ static JSBool session_wait_for_media(JSContext * cx, JSObject * obj, uintN argc,
break; break;
} }
switch_yield(1000); switch_cond_next();
} }
JS_ResumeRequest(cx, saveDepth); JS_ResumeRequest(cx, saveDepth);
check_hangup_hook(jss, &ret); check_hangup_hook(jss, &ret);
@ -2179,7 +2179,7 @@ static JSBool session_wait_for_answer(JSContext * cx, JSObject * obj, uintN argc
break; break;
} }
switch_yield(1000); switch_cond_next();
} }
JS_ResumeRequest(cx, saveDepth); JS_ResumeRequest(cx, saveDepth);
check_hangup_hook(jss, &ret); check_hangup_hook(jss, &ret);

View File

@ -683,7 +683,7 @@ SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t *sock, const
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
break; break;
} }
switch_yield(1000); switch_cond_next();
} else { } else {
to_count = 0; to_count = 0;
} }

View File

@ -683,7 +683,7 @@ SWITCH_DECLARE(void) switch_channel_wait_for_state(switch_channel_t *channel, sw
if (mystate != ostate || state >= CS_HANGUP || state == want_state) { if (mystate != ostate || state >= CS_HANGUP || state == want_state) {
break; break;
} }
switch_yield(1000); switch_cond_next();
} }
} }
@ -709,7 +709,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_wait_for_flag(switch_channel_t *c
} }
} }
switch_yield(1000); switch_cond_next();
if (super_channel && !switch_channel_ready(super_channel)) { if (super_channel && !switch_channel_ready(super_channel)) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;

View File

@ -449,7 +449,7 @@ static void *SWITCH_THREAD_FUNC console_thread(switch_thread_t *thread, void *ob
free(cmd); free(cmd);
} }
} }
switch_yield(1000); switch_cond_next();
} }
switch_core_destroy_memory_pool(&pool); switch_core_destroy_memory_pool(&pool);

View File

@ -360,6 +360,7 @@ SWITCH_DECLARE(void) switch_core_launch_thread(switch_thread_start_t func, void
} }
ts->objs[0] = obj; ts->objs[0] = obj;
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_threadattr_priority_increase(thd_attr);
switch_thread_create(&thread, thd_attr, func, ts, pool); switch_thread_create(&thread, thd_attr, func, ts, pool);
} }
} }

View File

@ -444,7 +444,7 @@ void switch_core_memory_stop(void)
#ifndef INSTANTLY_DESTROY_POOLS #ifndef INSTANTLY_DESTROY_POOLS
memory_manager.pool_thread_running = -1; memory_manager.pool_thread_running = -1;
while (memory_manager.pool_thread_running) { while (memory_manager.pool_thread_running) {
switch_yield(1000); switch_cond_next();
} }
#endif #endif
} }
@ -503,7 +503,7 @@ switch_memory_pool_t *switch_core_memory_init(void)
switch_thread_create(&thread, thd_attr, pool_thread, NULL, memory_manager.memory_pool); switch_thread_create(&thread, thd_attr, pool_thread, NULL, memory_manager.memory_pool);
while (!memory_manager.pool_thread_running) { while (!memory_manager.pool_thread_running) {
switch_yield(1000); switch_cond_next();
} }
#endif #endif

View File

@ -220,7 +220,7 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t * thread,
} }
if (nothing_in_queue) { if (nothing_in_queue) {
switch_yield(1000); switch_cond_next();
} }
} }

View File

@ -462,7 +462,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
if (endstate == switch_channel_get_running_state(session->channel)) { if (endstate == switch_channel_get_running_state(session->channel)) {
if (endstate == CS_NEW) { if (endstate == CS_NEW) {
switch_yield(1000); switch_cond_next();
} else { } else {
switch_thread_cond_wait(session->cond, session->mutex); switch_thread_cond_wait(session->cond, session->mutex);
} }

View File

@ -446,7 +446,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void)
} }
while (x < 10000 && THREAD_COUNT) { while (x < 10000 && THREAD_COUNT) {
switch_yield(1000); switch_cond_next();
if (THREAD_COUNT == last) { if (THREAD_COUNT == last) {
x++; x++;
} }
@ -537,7 +537,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_init(switch_memory_pool_t *pool)
switch_thread_create(&thread, thd_attr, switch_event_thread, EVENT_QUEUE[2], RUNTIME_POOL); switch_thread_create(&thread, thd_attr, switch_event_thread, EVENT_QUEUE[2], RUNTIME_POOL);
while (!THREAD_COUNT) { while (!THREAD_COUNT) {
switch_yield(1000); switch_cond_next();
} }

View File

@ -112,13 +112,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session,
} }
if (switch_channel_test_flag(channel, CF_PROXY_MODE)) { if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
switch_yield(1000); switch_cond_next();
continue; continue;
} }
if (switch_channel_test_flag(channel, CF_SERVICE) || if (switch_channel_test_flag(channel, CF_SERVICE) ||
(!switch_channel_test_flag(channel, CF_ANSWERED) && !switch_channel_test_flag(channel, CF_EARLY_MEDIA))) { (!switch_channel_test_flag(channel, CF_ANSWERED) && !switch_channel_test_flag(channel, CF_EARLY_MEDIA))) {
switch_yield(1000); switch_cond_next();
} else { } else {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {
@ -709,7 +709,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
} }
if (switch_channel_test_flag(channel, CF_SERVICE)) { if (switch_channel_test_flag(channel, CF_SERVICE)) {
switch_yield(1000); switch_cond_next();
} else { } else {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
} }
@ -824,7 +824,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
} }
if (switch_channel_test_flag(channel, CF_SERVICE)) { if (switch_channel_test_flag(channel, CF_SERVICE)) {
switch_yield(1000); switch_cond_next();
} else { } else {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {

View File

@ -157,7 +157,7 @@ SWITCH_DECLARE(void) switch_ivr_session_echo(switch_core_session_t *session, swi
#ifdef SWITCH_VIDEO_IN_THREADS #ifdef SWITCH_VIDEO_IN_THREADS
if (eh.up) { if (eh.up) {
while (eh.up) { while (eh.up) {
switch_yield(1000); switch_cond_next();
} }
} }
#endif #endif

View File

@ -913,7 +913,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
} }
while (switch_channel_get_state(peer_channel) == CS_EXCHANGE_MEDIA) { while (switch_channel_get_state(peer_channel) == CS_EXCHANGE_MEDIA) {
switch_yield(1000); switch_cond_next();
} }
switch_core_session_rwunlock(peer_session); switch_core_session_rwunlock(peer_session);

View File

@ -497,7 +497,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
} }
} }
} else { } else {
switch_yield(1000); switch_cond_next();
} }
} }
@ -1199,7 +1199,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
goto notready; 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); check_per_channel_timeouts(peer_channels, per_channel_timelimit_sec, per_channel_progress_timelimit_sec, and_argc, start);
@ -1432,7 +1432,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
} }
} else { } else {
switch_yield(10000); switch_yield(100000);
} }
} }

View File

@ -402,7 +402,7 @@ SWITCH_DECLARE(switch_status_t) switch_log_init(switch_memory_pool_t *pool, swit
switch_thread_create(&thread, thd_attr, log_thread, NULL, LOG_POOL); switch_thread_create(&thread, thd_attr, log_thread, NULL, LOG_POOL);
while (!THREAD_RUNNING) { while (!THREAD_RUNNING) {
switch_yield(1000); switch_cond_next();
} }
if (colorize) { if (colorize) {
@ -438,7 +438,7 @@ SWITCH_DECLARE(switch_status_t) switch_log_shutdown(void)
THREAD_RUNNING = -1; THREAD_RUNNING = -1;
switch_queue_push(LOG_QUEUE, NULL); switch_queue_push(LOG_QUEUE, NULL);
while (THREAD_RUNNING) { while (THREAD_RUNNING) {
switch_yield(1000); switch_cond_next();
} }
switch_core_memory_reclaim_logger(); switch_core_memory_reclaim_logger();

View File

@ -558,7 +558,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_local_address(switch_rtp_t *rtp_s
if (++x > 1000) { if (++x > 1000) {
break; break;
} }
switch_yield(1000); switch_cond_next();
} }
switch_socket_opt_set(new_sock, SWITCH_SO_NONBLOCK, FALSE); switch_socket_opt_set(new_sock, SWITCH_SO_NONBLOCK, FALSE);
@ -1537,7 +1537,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
rtp_session->recv_msg.header.ts = htonl(jb_frame->ts); 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! */ } 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) { if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK) && status == SWITCH_STATUS_BREAK) {
switch_yield(1000); switch_cond_next();
continue; continue;
} }

View File

@ -518,7 +518,7 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip,
switch_socket_close(sock); switch_socket_close(sock);
return SWITCH_STATUS_TIMEOUT; return SWITCH_STATUS_TIMEOUT;
} }
switch_yield(1000); switch_cond_next();
} }
switch_socket_close(sock); switch_socket_close(sock);

View File

@ -172,14 +172,14 @@ SWITCH_DECLARE(void) switch_micro_sleep(switch_interval_time_t t)
SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t) SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t)
{ {
if (t < 1000) { if (t < 1000 || t >= 10000) {
do_sleep(t); do_sleep(t);
return; return;
} }
#ifndef DISABLE_1MS_COND #ifndef DISABLE_1MS_COND
if (globals.use_cond_yield == 1) { if (globals.use_cond_yield == 1) {
switch_cond_yield((uint32_t)(t / 1000)); switch_cond_yield(t);
return; return;
} }
#endif #endif
@ -188,20 +188,39 @@ SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t)
} }
SWITCH_DECLARE(void) switch_cond_yield(uint32_t ms) SWITCH_DECLARE(void) switch_cond_next(void)
{ {
if (!ms) return; #ifdef DISABLE_1MS_COND
do_sleep(1000);
if (globals.use_cond_yield != 1) { #else
do_sleep(ms * 1000); if (!runtime.timestamp || globals.use_cond_yield != 1) {
do_sleep(1000);
return; return;
} }
switch_mutex_lock(TIMER_MATRIX[1].mutex); 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); 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);
}
} }
@ -292,22 +311,28 @@ static switch_status_t timer_sync(switch_timer_t *timer)
static switch_status_t timer_next(switch_timer_t *timer) static switch_status_t timer_next(switch_timer_t *timer)
{ {
timer_private_t *private_info = timer->private_info; timer_private_t *private_info = timer->private_info;
timer_step(timer);
#if 1 #ifdef DISABLE_1MS_COND
switch_mutex_lock(TIMER_MATRIX[timer->interval].mutex); int cond_index = timer->interval;
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);
#else #else
while (globals.RUNNING == 1 && private_info->ready && TIMER_MATRIX[timer->interval].tick < private_info->reference) { int cond_index = 1;
check_roll();
do_sleep(1000);
}
#endif #endif
timer_step(timer);
while (globals.RUNNING == 1 && private_info->ready && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
check_roll();
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);
}
}
if (globals.RUNNING == 1) { if (globals.RUNNING == 1) {
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -486,7 +511,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
if ((current_ms % x) == 0) { if ((current_ms % x) == 0) {
if (TIMER_MATRIX[x].count) { if (TIMER_MATRIX[x].count) {
TIMER_MATRIX[x].tick++; 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) { if (TIMER_MATRIX[x].mutex && switch_mutex_trylock(TIMER_MATRIX[x].mutex) == SWITCH_STATUS_SUCCESS) {
switch_thread_cond_broadcast(TIMER_MATRIX[x].cond); switch_thread_cond_broadcast(TIMER_MATRIX[x].cond);
switch_mutex_unlock(TIMER_MATRIX[x].mutex); switch_mutex_unlock(TIMER_MATRIX[x].mutex);
@ -726,11 +751,13 @@ SWITCH_MODULE_LOAD_FUNCTION(softtimer_load)
timer_interface->timer_destroy = timer_destroy; timer_interface->timer_destroy = timer_destroy;
/* indicate that the module should continue to be loaded */ /* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_NOUNLOAD;
} }
SWITCH_MODULE_SHUTDOWN_FUNCTION(softtimer_shutdown) SWITCH_MODULE_SHUTDOWN_FUNCTION(softtimer_shutdown)
{ {
globals.use_cond_yield = 0;
if (globals.RUNNING == 1) { if (globals.RUNNING == 1) {
switch_mutex_lock(globals.mutex); switch_mutex_lock(globals.mutex);
globals.RUNNING = -1; globals.RUNNING = -1;