Index: channels/chan_iax2.c =================================================================== --- channels/chan_iax2.c (revision 151319) +++ channels/chan_iax2.c (working copy) @@ -9798,6 +9798,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); @@ -9819,6 +9821,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); @@ -9831,6 +9835,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. @@ -9842,6 +9848,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; } } @@ -9853,15 +9861,21 @@ 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); AST_LIST_UNLOCK(&active_list); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_testcancel(); + /* See what we need to do */ switch(thread->iostate) { case IAX_IOSTATE_READY: @@ -9879,17 +9893,22 @@ default: break; } + 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); AST_LIST_UNLOCK(&active_list); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_testcancel(); + /* Make sure another frame didn't sneak in there after we thought we were done. */ handle_deferred_full_frames(thread); } @@ -9898,6 +9917,7 @@ * 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); @@ -9905,6 +9925,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)