[asterisk-commits] russell: branch russell/res_monkeys r71266 - in /team/russell/res_monkeys: in...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sun Jun 24 03:02:37 CDT 2007
Author: russell
Date: Sun Jun 24 03:02:36 2007
New Revision: 71266
URL: http://svn.digium.com/view/asterisk?view=rev&rev=71266
Log:
Implement channel attached threads
Modified:
team/russell/res_monkeys/include/asterisk/channel.h
team/russell/res_monkeys/main/channel.c
Modified: team/russell/res_monkeys/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/russell/res_monkeys/include/asterisk/channel.h?view=diff&rev=71266&r1=71265&r2=71266
==============================================================================
--- team/russell/res_monkeys/include/asterisk/channel.h (original)
+++ team/russell/res_monkeys/include/asterisk/channel.h Sun Jun 24 03:02:36 2007
@@ -1441,6 +1441,16 @@
*/
void ast_channel_whisper_stop(struct ast_channel *chan);
+struct ast_chan_thread_args {
+ struct ast_channel *chan;
+ pthread_t thread_id;
+ ast_mutex_t lock;
+ ast_cond_t cond;
+ unsigned int stop_thread:1;
+};
+
+int ast_chan_thread_create(struct ast_channel *chan, void *(*start_func)(void *));
+
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
Modified: team/russell/res_monkeys/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/russell/res_monkeys/main/channel.c?view=diff&rev=71266&r1=71265&r2=71266
==============================================================================
--- team/russell/res_monkeys/main/channel.c (original)
+++ team/russell/res_monkeys/main/channel.c Sun Jun 24 03:02:36 2007
@@ -4898,3 +4898,53 @@
ast_free(chan->whisper);
chan->whisper = NULL;
}
+
+static void chan_thread_destroy(void *data)
+{
+ struct ast_chan_thread_args *thread_args = data;
+
+ if (thread_args->thread_id != AST_PTHREADT_NULL) {
+ ast_mutex_lock(&thread_args->lock);
+ thread_args->stop_thread = 1;
+ ast_cond_signal(&thread_args->cond);
+ ast_mutex_unlock(&thread_args->lock);
+ pthread_join(thread_args->thread_id, NULL);
+ }
+
+ ast_mutex_destroy(&thread_args->lock);
+ ast_cond_destroy(&thread_args->cond);
+
+ free(thread_args);
+}
+
+const struct ast_datastore_info chanthread_datastore_info = {
+ .type = "CHANTHREAD",
+ .destroy = chan_thread_destroy,
+};
+
+int ast_chan_thread_create(struct ast_channel *chan, void *(*start_func)(void *))
+{
+ struct ast_datastore *datastore;
+ struct ast_chan_thread_args *thread_args;
+ int res;
+
+ if (!(thread_args = ast_calloc(1, sizeof(*thread_args))))
+ return -1;
+
+ thread_args->chan = chan;
+ ast_mutex_init(&thread_args->lock);
+ ast_cond_init(&thread_args->cond, NULL);
+ thread_args->thread_id = AST_PTHREADT_NULL;
+
+ if (!(datastore = ast_channel_datastore_alloc(&chanthread_datastore_info, NULL))) {
+ free(thread_args);
+ return -1;
+ }
+
+ ast_channel_lock(chan);
+ ast_channel_datastore_add(chan, datastore);
+ res = ast_pthread_create_background(&thread_args->thread_id, NULL, start_func, thread_args);
+ ast_channel_unlock(chan);
+
+ return res;
+}
More information about the asterisk-commits
mailing list