aboutsummaryrefslogtreecommitdiffstats
path: root/main/dial.c
diff options
context:
space:
mode:
authorfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-16 15:08:24 +0000
committerfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-16 15:08:24 +0000
commit839e37689739de75e9065c321e234525b516c61c (patch)
tree0bb36983d837809029bfe8d32655bf32a808dab7 /main/dial.c
parenteefb2cbf2c494ef229e9aeae0458d69ff4d0971b (diff)
Introduce a lock into the dialing API that protects it when destroying the structure.
(closes issue #11687) Reported by: callguy Patches: 11687.diff uploaded by file (license 11) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@98960 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/dial.c')
-rw-r--r--main/dial.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/main/dial.c b/main/dial.c
index 02bf03e22..2ca0fd0d2 100644
--- a/main/dial.c
+++ b/main/dial.c
@@ -52,6 +52,7 @@ struct ast_dial {
ast_dial_state_callback state_callback; /*! Status callback */
AST_LIST_HEAD_NOLOCK(, ast_dial_channel) channels; /*! Channels being dialed */
pthread_t thread; /*! Thread (if running in async) */
+ ast_mutex_t lock; /*! Lock to protect the thread information above */
};
/*! \brief Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more! */
@@ -137,10 +138,12 @@ static void answer_exec_run(struct ast_dial *dial, struct ast_dial_channel *dial
pbx_exec(chan, ast_app, args);
/* If another thread is not taking over hang up the channel */
+ ast_mutex_lock(&dial->lock);
if (dial->thread != AST_PTHREADT_STOP) {
ast_hangup(chan);
dial_channel->owner = NULL;
}
+ ast_mutex_unlock(&dial->lock);
return;
}
@@ -191,6 +194,9 @@ struct ast_dial *ast_dial_create(void)
/* Initialize thread to NULL */
dial->thread = AST_PTHREADT_NULL;
+ /* Can't forget about the lock */
+ ast_mutex_init(&dial->lock);
+
return dial;
}
@@ -623,6 +629,9 @@ enum ast_dial_result ast_dial_join(struct ast_dial *dial)
/* Record thread */
thread = dial->thread;
+ /* Boom, commence locking */
+ ast_mutex_lock(&dial->lock);
+
/* Stop the thread */
dial->thread = AST_PTHREADT_STOP;
@@ -637,6 +646,9 @@ enum ast_dial_result ast_dial_join(struct ast_dial *dial)
pthread_kill(thread, SIGURG);
}
+ /* Yay done with it */
+ ast_mutex_unlock(&dial->lock);
+
/* Finally wait for the thread to exit */
pthread_join(thread, NULL);
@@ -710,6 +722,9 @@ int ast_dial_destroy(struct ast_dial *dial)
dial->options[i] = NULL;
}
+ /* Lock be gone! */
+ ast_mutex_destroy(&dial->lock);
+
/* Free structure */
free(dial);