diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-05-13 21:05:57 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-05-13 21:05:57 +0000 |
commit | 03a5a3694a37cf03392bfc7917f4574039b1e1e9 (patch) | |
tree | 9aa0e57b380152eac15de72fe055755a8286e62f /main | |
parent | 9b672fb213eb8fa70d78b1cc2f0e1fd21b26fa29 (diff) |
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/branches/1.4@115990 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r-- | main/autoservice.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/main/autoservice.c b/main/autoservice.c index 88ab0d4e6..fb0840f92 100644 --- a/main/autoservice.c +++ b/main/autoservice.c @@ -201,25 +201,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; } |