--- ../clean/asterisk-1.6.2.16.1/channels/chan_sip.c 2010-12-10 00:10:31.000000000 +0200 +++ channels/chan_sip.c 2011-02-11 12:03:12.000000000 +0200 @@ -7154,14 +7154,18 @@ sip_pvt_lock(p); fr = sip_rtp_read(ast, p, &faxdetected); + + if (fr == &ast_null_frame) { + sip_pvt_unlock(p); + return fr; + } + p->lastrtprx = time(NULL); /* If we detect a CNG tone and fax detection is enabled then send us off to the fax extension */ if (faxdetected && ast_test_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT_CNG)) { - ast_channel_lock(ast); if (strcmp(ast->exten, "fax")) { const char *target_context = S_OR(ast->macrocontext, ast->context); - ast_channel_unlock(ast); if (ast_exists_extension(ast, target_context, "fax", 1, ast->cid.cid_num)) { ast_verbose(VERBOSE_PREFIX_2 "Redirecting '%s' to fax extension due to CNG detection\n", ast->name); pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten); @@ -7172,8 +7176,6 @@ } else { ast_log(LOG_NOTICE, "FAX CNG detected but no fax extension\n"); } - } else { - ast_channel_unlock(ast); } } @@ -22679,14 +22685,10 @@ (t > dialog->lastrtprx + ast_rtp_get_rtpholdtimeout(dialog->rtp)))) { /* Needs a hangup */ if (ast_rtp_get_rtptimeout(dialog->rtp)) { - while (dialog->owner && ast_channel_trylock(dialog->owner)) { - sip_pvt_unlock(dialog); - usleep(1); - sip_pvt_lock(dialog); - } - if (!dialog->owner) { - return; /* channel hangup can occur during deadlock avoidance. */ - } + /* Don't block the monitor thread. This function is called often enough + * that we can wait for the next time around. */ + if ((!dialog->owner) || (dialog->owner && ast_channel_trylock(dialog->owner))) + return; ast_log(LOG_NOTICE, "Disconnecting call '%s' for lack of RTP activity in %ld seconds\n", dialog->owner->name, (long) (t - dialog->lastrtprx)); /* Issue a softhangup */