]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
create the IAX2 processing threads as background threads so they will use smaller...
authorKevin P. Fleming <kpfleming@digium.com>
Thu, 4 Jan 2007 23:50:15 +0000 (23:50 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Thu, 4 Jan 2007 23:50:15 +0000 (23:50 +0000)
when we create a dynamic thread, put it on the dynamic_list right away so we don't lose track of it

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@49581 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c

index 2037a3a4056fb325124415f2da67b318bed9135b..ec3c7be5bf9b0b82974d4a0bceaa7e9cc84b80e1 100644 (file)
@@ -855,24 +855,21 @@ static struct iax2_thread *find_idle_thread(void)
        /* If no idle thread is available from the regular list, try dynamic */
        if (thread == NULL) {
                AST_LIST_LOCK(&dynamic_list);
-               thread = AST_LIST_FIRST(&dynamic_list);
-               if (thread != NULL) {
-                       AST_LIST_REMOVE(&dynamic_list, thread, list);
-               }
+               thread = AST_LIST_REMOVE_HEAD(&dynamic_list, list);
                /* Make sure we absolutely have a thread... if not, try to make one if allowed */
                if (thread == NULL && iaxmaxthreadcount > iaxdynamicthreadcount) {
                        /* We need to MAKE a thread! */
-                       thread = ast_calloc(1, sizeof(*thread));
-                       if (thread != NULL) {
+                       if ((thread = ast_calloc(1, sizeof(*thread)))) {
                                thread->threadnum = iaxdynamicthreadcount;
                                thread->type = IAX_TYPE_DYNAMIC;
                                ast_mutex_init(&thread->lock);
                                ast_cond_init(&thread->cond, NULL);
-                               if (ast_pthread_create(&thread->threadid, NULL, iax2_process_thread, thread)) {
+                               if (ast_pthread_create_background(&thread->threadid, NULL, iax2_process_thread, thread)) {
                                        free(thread);
                                        thread = NULL;
                                } else {
                                        /* All went well and the thread is up, so increment our count */
+                                       AST_LIST_INSERT_TAIL(&dynamic_list, thread, list);
                                        iaxdynamicthreadcount++;
                                }
                        }
@@ -8110,7 +8107,7 @@ static int start_network_thread(void)
                        thread->threadnum = ++threadcount;
                        ast_mutex_init(&thread->lock);
                        ast_cond_init(&thread->cond, NULL);
-                       if (ast_pthread_create(&thread->threadid, NULL, iax2_process_thread, thread)) {
+                       if (ast_pthread_create_background(&thread->threadid, NULL, iax2_process_thread, thread)) {
                                ast_log(LOG_WARNING, "Failed to create new thread!\n");
                                free(thread);
                                thread = NULL;