aboutsummaryrefslogtreecommitdiffstats
path: root/main/autoservice.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-05-13 21:07:59 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-05-13 21:07:59 +0000
commit8da7a7e7fdb5d03f8109fc0e7075e2db2ff42e4e (patch)
treeb682e9a0ccc5548a0711dcb7e2060dd15ed88c95 /main/autoservice.c
parenta3c3c2cf43ee15c52e8f2d8c46b66fbeb8ae0435 (diff)
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: http://svn.digium.com/svn/asterisk/trunk@116001 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/autoservice.c')
-rw-r--r--main/autoservice.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/main/autoservice.c b/main/autoservice.c
index d34883389..c2550916a 100644
--- a/main/autoservice.c
+++ b/main/autoservice.c
@@ -195,25 +195,29 @@ int ast_autoservice_start(struct ast_channel *chan)
ast_channel_unlock(chan);
AST_LIST_LOCK(&aslist);
- if (AST_LIST_EMPTY(&aslist))
+
+ if (AST_LIST_EMPTY(&aslist) && asthread != AST_PTHREADT_NULL) {
ast_cond_signal(&as_cond);
+ }
+
AST_LIST_INSERT_HEAD(&aslist, as, list);
- AST_LIST_UNLOCK(&aslist);
if (asthread == AST_PTHREADT_NULL) { /* need start the thread */
if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) {
ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
/* There will only be a single member in the list at this point,
the one we just added. */
- AST_LIST_LOCK(&aslist);
AST_LIST_REMOVE(&aslist, as, list);
- AST_LIST_UNLOCK(&aslist);
free(as);
+ asthread = AST_PTHREADT_NULL;
res = -1;
- } else
+ } else {
pthread_kill(asthread, SIGURG);
+ }
}
+ AST_LIST_UNLOCK(&aslist);
+
return res;
}