Merged revisions 77943 via svnmerge from
[asterisk/asterisk.git] / channels / chan_iax2.c
index e4be160..c035b15 100644 (file)
@@ -8392,14 +8392,20 @@ static void *iax2_process_thread(void *data)
                        ts.tv_sec = tv.tv_sec;
                        ts.tv_nsec = tv.tv_usec * 1000;
                        if (ast_cond_timedwait(&thread->cond, &thread->lock, &ts) == ETIMEDOUT) {
-                               ast_mutex_unlock(&thread->lock);
                                AST_LIST_LOCK(&dynamic_list);
                                /* Account for the case where this thread is acquired *right* after a timeout */
                                if ((t = AST_LIST_REMOVE(&dynamic_list, thread, list)))
                                        ast_atomic_fetchadd_int(&iaxdynamicthreadcount, -1);
                                AST_LIST_UNLOCK(&dynamic_list);
-                               if (t)
+                               if (t) {
+                                       ast_mutex_unlock(&thread->lock);
                                        break;          /* exiting the main loop */
+                               }
+                               /* Someone grabbed our thread *right* after we timed out.
+                                * Wait for them to set us up with something to do and signal
+                                * us to continue. */
+                               ast_cond_timedwait(&thread->cond, &thread->lock, &ts);
+                               ast_mutex_unlock(&thread->lock);
                        }
                        if (!t)
                                ast_mutex_unlock(&thread->lock);