Index: channels/chan_iax2.c =================================================================== --- channels/chan_iax2.c (revision 134704) +++ channels/chan_iax2.c (working copy) @@ -9560,6 +9560,8 @@ ast_atomic_fetchadd_int(&iaxactivethreadcount,1); pthread_cleanup_push(iax2_process_thread_cleanup, data); for(;;) { + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); + /* Wait for something to signal us to be awake */ ast_mutex_lock(&thread->lock); @@ -9581,6 +9583,8 @@ * thread list, so just go away. */ if (!put_into_idle) { ast_mutex_unlock(&thread->lock); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_testcancel(); break; } AST_LIST_LOCK(&dynamic_list); @@ -9593,6 +9597,8 @@ * not acquired immediately after the timeout, * so it's time to go away. */ ast_mutex_unlock(&thread->lock); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_testcancel(); break; } /* Someone grabbed our thread *right* after we timed out. @@ -9604,6 +9610,8 @@ if (ast_cond_timedwait(&thread->cond, &thread->lock, &ts) == ETIMEDOUT) { ast_mutex_unlock(&thread->lock); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_testcancel(); break; } } @@ -9615,10 +9623,13 @@ put_into_idle = 1; ast_mutex_unlock(&thread->lock); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_testcancel(); if (thread->iostate == IAX_IOSTATE_IDLE) continue; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); /* Add ourselves to the active list now */ AST_LIST_LOCK(&active_list); AST_LIST_INSERT_HEAD(&active_list, thread, list); @@ -9641,12 +9652,16 @@ default: break; } + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_testcancel(); + time(&thread->checktime); thread->iostate = IAX_IOSTATE_IDLE; #ifdef DEBUG_SCHED_MULTITHREAD thread->curfunc[0]='\0'; #endif + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); /* Now... remove ourselves from the active list, and return to the idle list */ AST_LIST_LOCK(&active_list); AST_LIST_REMOVE(&active_list, thread, list); @@ -9654,12 +9669,16 @@ /* Make sure another frame didn't sneak in there after we thought we were done. */ handle_deferred_full_frames(thread); + + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_testcancel(); } /*!\note For some reason, idle threads are exiting without being removed * from an idle list, which is causing memory corruption. Forcibly remove * it from the list, if it's there. */ + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); AST_LIST_LOCK(&idle_list); AST_LIST_REMOVE(&idle_list, thread, list); AST_LIST_UNLOCK(&idle_list); @@ -9667,6 +9686,7 @@ AST_LIST_LOCK(&dynamic_list); AST_LIST_REMOVE(&dynamic_list, thread, list); AST_LIST_UNLOCK(&dynamic_list); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); /* I am exiting here on my own volition, I need to clean up my own data structures * Assume that I am no longer in any of the lists (idle, active, or dynamic)