Fix directed pickup to a call that is up (bug #5425 with mods)
[asterisk/asterisk.git] / autoservice.c
index 2f28f35..7dcec2a 100755 (executable)
@@ -1,38 +1,54 @@
 /*
- * Asterisk -- A telephony toolkit for Linux.
+ * Asterisk -- An open source telephony toolkit.
  *
- * Automatic channel service routines
- * 
- * Copyright (C) 1999, Mark Spencer
+ * Copyright (C) 1999 - 2005, Digium, Inc.
+ *
+ * Mark Spencer <markster@digium.com>
  *
- * Mark Spencer <markster@linux-support.net>
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
  *
  * This program is free software, distributed under the terms of
- * the GNU General Public License
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*
+ *
+ * Automatic channel service routines
+ * 
  */
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <pthread.h>
 #include <string.h>
 #include <sys/time.h>
 #include <signal.h>
 #include <errno.h>
 #include <unistd.h>
 #include <math.h>                      /* For PI */
-#include <asterisk/pbx.h>
-#include <asterisk/frame.h>
-#include <asterisk/sched.h>
-#include <asterisk/options.h>
-#include <asterisk/channel.h>
-#include <asterisk/channel_pvt.h>
-#include <asterisk/logger.h>
-#include <asterisk/file.h>
-#include <asterisk/translate.h>
-#include <asterisk/manager.h>
-#include <asterisk/chanvars.h>
-#include <asterisk/linkedlists.h>
-#include <asterisk/indications.h>
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/pbx.h"
+#include "asterisk/frame.h"
+#include "asterisk/sched.h"
+#include "asterisk/options.h"
+#include "asterisk/channel.h"
+#include "asterisk/logger.h"
+#include "asterisk/file.h"
+#include "asterisk/translate.h"
+#include "asterisk/manager.h"
+#include "asterisk/chanvars.h"
+#include "asterisk/linkedlists.h"
+#include "asterisk/indications.h"
+#include "asterisk/lock.h"
+#include "asterisk/utils.h"
 
 #define MAX_AUTOMONS 256
 
@@ -106,7 +122,7 @@ int ast_autoservice_start(struct ast_channel *chan)
                        aslist = as;
                        res = 0;
                        if (needstart) {
-                               if (pthread_create(&asthread, NULL, autoservice_run, NULL)) {
+                               if (ast_pthread_create(&asthread, NULL, autoservice_run, NULL)) {
                                        ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
                                        free(aslist);
                                        aslist = NULL;
@@ -146,7 +162,7 @@ int ast_autoservice_stop(struct ast_channel *chan)
                pthread_kill(asthread, SIGURG);
        ast_mutex_unlock(&autolock);
        /* Wait for it to un-block */
-       while(chan->blocking)
+       while(ast_test_flag(chan, AST_FLAG_BLOCKING))
                usleep(1000);
        return res;
 }