Skip to content
Snippets Groups Projects
Commit 8e4c0e85 authored by Russell Bryant's avatar Russell Bryant
Browse files

Merged revisions 115990 via svnmerge from

https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r115990 | russell | 2008-05-13 16:05:57 -0500 (Tue, 13 May 2008) | 5 lines

Fix an issue that I noticed in autoservice while mmichelson and I were debugging
a different problem.  I noticed that it was theoretically possible for two threads
to attempt to start the autoservice thread at the same time.  This change makes the
process of starting the autoservice thread, thread-safe.

........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@116001 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 8d187239
No related branches found
No related tags found
No related merge requests found
...@@ -195,25 +195,29 @@ int ast_autoservice_start(struct ast_channel *chan) ...@@ -195,25 +195,29 @@ int ast_autoservice_start(struct ast_channel *chan)
ast_channel_unlock(chan); ast_channel_unlock(chan);
AST_LIST_LOCK(&aslist); AST_LIST_LOCK(&aslist);
if (AST_LIST_EMPTY(&aslist))
if (AST_LIST_EMPTY(&aslist) && asthread != AST_PTHREADT_NULL) {
ast_cond_signal(&as_cond); ast_cond_signal(&as_cond);
}
AST_LIST_INSERT_HEAD(&aslist, as, list); AST_LIST_INSERT_HEAD(&aslist, as, list);
AST_LIST_UNLOCK(&aslist);
if (asthread == AST_PTHREADT_NULL) { /* need start the thread */ if (asthread == AST_PTHREADT_NULL) { /* need start the thread */
if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) { if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) {
ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n"); ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
/* There will only be a single member in the list at this point, /* There will only be a single member in the list at this point,
the one we just added. */ the one we just added. */
AST_LIST_LOCK(&aslist);
AST_LIST_REMOVE(&aslist, as, list); AST_LIST_REMOVE(&aslist, as, list);
AST_LIST_UNLOCK(&aslist);
free(as); free(as);
asthread = AST_PTHREADT_NULL;
res = -1; res = -1;
} else } else {
pthread_kill(asthread, SIGURG); pthread_kill(asthread, SIGURG);
}
} }
AST_LIST_UNLOCK(&aslist);
return res; return res;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment