Fix bug 1217. Change pthread_t initializers to AST_PTHREADT_NULL and
authorJames Golovich <james@gnuinter.net>
Mon, 15 Mar 2004 07:51:22 +0000 (07:51 +0000)
committerJames Golovich <james@gnuinter.net>
Mon, 15 Mar 2004 07:51:22 +0000 (07:51 +0000)
AST_PTHREADT_STOP

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2434 65c4cc65-6c06-0410-ace0-fbb531ad65f3

12 files changed:
asterisk.c
autoservice.c
channels/chan_h323.c
channels/chan_iax.c
channels/chan_iax2.c
channels/chan_mgcp.c
channels/chan_modem.c
channels/chan_phone.c
channels/chan_sip.c
channels/chan_skinny.c
channels/chan_vofr.c
channels/chan_zap.c

index a267df9..7adb027 100755 (executable)
@@ -34,7 +34,7 @@
 #include <signal.h>
 #include <sched.h>
 #include <asterisk/io.h>
-#include <pthread.h>
+#include <asterisk/lock.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/select.h>
@@ -109,7 +109,7 @@ char ast_config_AST_RUN_DIR[AST_CONFIG_MAX_PATH];
 static char *_argv[256];
 static int shuttingdown = 0;
 static int restartnow = 0;
-static pthread_t consolethread = (pthread_t) -1;
+static pthread_t consolethread = AST_PTHREADT_NULL;
 
 int ast_register_atexit(void (*func)(void))
 {
@@ -544,7 +544,7 @@ static void quit_handler(int num, int nice, int safeshutdown, int restart)
                restartnow = 1;
                /* If there is a consolethread running send it a SIGHUP 
                   so it can execvp, otherwise we can do it ourselves */
-               if (consolethread != (pthread_t) -1) {
+               if (consolethread != AST_PTHREADT_NULL) {
                        pthread_kill(consolethread, SIGHUP);
                        /* Give the signal handler some time to complete */
                        sleep(2);
@@ -591,7 +591,7 @@ static void console_verboser(const char *s, int pos, int replace, int complete)
        fflush(stdout);
        if (complete)
        /* Wake up a select()ing console */
-               if (option_console && consolethread != (pthread_t) -1)
+               if (option_console && consolethread != AST_PTHREADT_NULL)
                        pthread_kill(consolethread, SIGURG);
 }
 
index 7e5699b..3f24db8 100755 (executable)
@@ -44,7 +44,7 @@ struct asent {
 };
 
 static struct asent *aslist = NULL;
-static pthread_t asthread = (pthread_t) -1;
+static pthread_t asthread = AST_PTHREADT_NULL;
 
 static void *autoservice_run(void *ign)
 {
@@ -80,7 +80,7 @@ static void *autoservice_run(void *ign)
                                ast_frfree(f);
                }
        }
-       asthread = (pthread_t) -1;
+       asthread = AST_PTHREADT_NULL;
        return NULL;
 }
 
@@ -90,7 +90,7 @@ int ast_autoservice_start(struct ast_channel *chan)
        struct asent *as;
        int needstart;
        ast_mutex_lock(&autolock);
-       needstart = (asthread == (pthread_t) -1) ? 1 : 0 /* aslist ? 0 : 1 */;
+       needstart = (asthread == AST_PTHREADT_NULL) ? 1 : 0 /* aslist ? 0 : 1 */;
        as = aslist;
        while(as) {
                if (as->chan == chan)
@@ -142,7 +142,7 @@ int ast_autoservice_stop(struct ast_channel *chan)
                if (!chan->_softhangup)
                        res = 0;
        }
-       if (asthread != (pthread_t) -1) 
+       if (asthread != AST_PTHREADT_NULL) 
                pthread_kill(asthread, SIGURG);
        ast_mutex_unlock(&autolock);
        /* Wait for it to un-block */
index 5b99ed8..70761d8 100755 (executable)
@@ -147,7 +147,7 @@ static ast_mutex_t monlock = AST_MUTEX_INITIALIZER;
 
 /* This is the thread for the monitor which checks for input on the channels
    which are not currently in use.  */
-static pthread_t monitor_thread = 0;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
 
 static int restart_monitor(void);
 
@@ -1260,7 +1260,7 @@ restartsearch:
 static int restart_monitor(void)
 {
        /* If we're supposed to be stopped -- stay stopped */
-       if (monitor_thread == -2)
+       if (monitor_thread == AST_PTHREADT_STOP)
                return 0;
        if (ast_mutex_lock(&monlock)) {
                ast_log(LOG_WARNING, "Unable to lock monitor\n");
@@ -1271,7 +1271,7 @@ static int restart_monitor(void)
                ast_log(LOG_WARNING, "Cannot kill myself\n");
                return -1;
        }
-       if (monitor_thread && (monitor_thread != -2)) {
+       if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
                /* Wake up the thread */
                pthread_kill(monitor_thread, SIGURG);
        } else {
@@ -1840,12 +1840,12 @@ int unload_module()
        }
 
        if (!ast_mutex_lock(&monlock)) {
-                if (monitor_thread && (monitor_thread != -2)) {
+                if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
                         pthread_cancel(monitor_thread);
                         pthread_kill(monitor_thread, SIGURG);
                         pthread_join(monitor_thread, NULL);
                  }
-                monitor_thread = (pthread_t) -2;
+                monitor_thread = AST_PTHREADT_STOP;
                 ast_mutex_unlock(&monlock);
         } else {
                 ast_log(LOG_WARNING, "Unable to lock the monitor\n");
index ce08970..a88e855 100755 (executable)
@@ -149,7 +149,7 @@ static int iaxdebug = 0;
 static char accountcode[20];
 static int amaflags = 0;
 
-static pthread_t netthreadid;
+static pthread_t netthreadid = AST_PTHREADT_NULL;
 
 #define IAX_STATE_STARTED              (1 << 0)
 #define IAX_STATE_AUTHENTICATED (1 << 1)
@@ -5345,8 +5345,10 @@ static int __unload_module(void)
 {
        int x;
        /* Cancel the network thread, close the net socket */
-       pthread_cancel(netthreadid);
-       pthread_join(netthreadid, NULL);
+       if (netthreadid != AST_PTHREADT_NULL) {
+               pthread_cancel(netthreadid);
+               pthread_join(netthreadid, NULL);
+       }
        close(netsocket);
        for (x=0;x<AST_IAX_MAX_CALLS;x++)
                if (iaxs[x])
index 04f8073..c9da32e 100755 (executable)
@@ -172,7 +172,7 @@ static char accountcode[20];
 static int amaflags = 0;
 static int notransfer = 0;
 
-static pthread_t netthreadid;
+static pthread_t netthreadid = AST_PTHREADT_NULL;
 
 #define IAX_STATE_STARTED              (1 << 0)
 #define IAX_STATE_AUTHENTICATED (1 << 1)
@@ -6521,8 +6521,10 @@ static int __unload_module(void)
 {
        int x;
        /* Cancel the network thread, close the net socket */
-       pthread_cancel(netthreadid);
-       pthread_join(netthreadid, NULL);
+       if (netthreadid != AST_PTHREADT_NULL) {
+               pthread_cancel(netthreadid);
+               pthread_join(netthreadid, NULL);
+       }
        close(netsocket);
        for (x=0;x<IAX_MAX_CALLS;x++)
                if (iaxs[x])
index 6774ac7..1554b33 100755 (executable)
@@ -167,7 +167,7 @@ static ast_mutex_t monlock = AST_MUTEX_INITIALIZER;
 
 /* This is the thread for the monitor which checks for input on the channels
    which are not currently in use.  */
-static pthread_t monitor_thread = 0;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
 
 static int restart_monitor(void);
 
@@ -2558,7 +2558,7 @@ static int restart_monitor(void)
         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);   
 
        /* If we're supposed to be stopped -- stay stopped */
-       if (monitor_thread == (pthread_t) -2)
+       if (monitor_thread == AST_PTHREADT_STOP)
                return 0;
        if (ast_mutex_lock(&monlock)) {
                ast_log(LOG_WARNING, "Unable to lock monitor\n");
@@ -3052,12 +3052,12 @@ int unload_module()
                return -1;
        }
        if (!ast_mutex_lock(&monlock)) {
-               if (monitor_thread && (monitor_thread != -2)) {
+               if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
                        pthread_cancel(monitor_thread);
                        pthread_kill(monitor_thread, SIGURG);
                        pthread_join(monitor_thread, NULL);
                }
-               monitor_thread = -2;
+               monitor_thread = AST_PTHREADT_STOP;
                ast_mutex_unlock(&monlock);
        } else {
                ast_log(LOG_WARNING, "Unable to lock the monitor\n");
index 09451de..728aa36 100755 (executable)
@@ -83,7 +83,7 @@ static ast_mutex_t monlock = AST_MUTEX_INITIALIZER;
 
 /* This is the thread for the monitor which checks for input on the channels
    which are not currently in use.  */
-static pthread_t monitor_thread = (pthread_t) -1;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
 
 static int restart_monitor(void);
 
@@ -646,7 +646,7 @@ static void *do_monitor(void *data)
 static int restart_monitor()
 {
        /* If we're supposed to be stopped -- stay stopped */
-       if (monitor_thread == (pthread_t) -2)
+       if (monitor_thread == AST_PTHREADT_STOP)
                return 0;
        if (ast_mutex_lock(&monlock)) {
                ast_log(LOG_WARNING, "Unable to lock monitor\n");
@@ -657,7 +657,7 @@ static int restart_monitor()
                ast_log(LOG_WARNING, "Cannot kill myself\n");
                return -1;
        }
-       if (monitor_thread != (pthread_t) -1) {
+       if (monitor_thread != AST_PTHREADT_NULL) {
                pthread_cancel(monitor_thread);
                /* Nudge it a little, as it's probably stuck in select */
                pthread_kill(monitor_thread, SIGURG);
@@ -861,11 +861,11 @@ static int __unload_module(void)
                return -1;
        }
        if (!ast_mutex_lock(&monlock)) {
-               if (monitor_thread != (pthread_t) -1 && monitor_thread != (pthread_t) -2) {
+               if (monitor_thread != AST_PTHREADT_NULL && monitor_thread != AST_PTHREADT_STOP) {
                        pthread_cancel(monitor_thread);
                        pthread_join(monitor_thread, NULL);
                }
-               monitor_thread = (pthread_t) -2;
+               monitor_thread = AST_PTHREADT_STOP;
                ast_mutex_unlock(&monlock);
        } else {
                ast_log(LOG_WARNING, "Unable to lock the monitor\n");
index 7757348..5ebe021 100755 (executable)
@@ -67,7 +67,7 @@ static ast_mutex_t monlock = AST_MUTEX_INITIALIZER;
 
 /* This is the thread for the monitor which checks for input on the channels
    which are not currently in use.  */
-static pthread_t monitor_thread = -1;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
 
 static int restart_monitor(void);
 
@@ -910,7 +910,7 @@ static void *do_monitor(void *data)
 static int restart_monitor()
 {
        /* If we're supposed to be stopped -- stay stopped */
-       if (monitor_thread == -2)
+       if (monitor_thread == AST_PTHREADT_STOP)
                return 0;
        if (ast_mutex_lock(&monlock)) {
                ast_log(LOG_WARNING, "Unable to lock monitor\n");
@@ -921,7 +921,7 @@ static int restart_monitor()
                ast_log(LOG_WARNING, "Cannot kill myself\n");
                return -1;
        }
-       if (monitor_thread != -1) {
+       if (monitor_thread != AST_PTHREADT_NULL) {
                pthread_cancel(monitor_thread);
 #if 0
                pthread_join(monitor_thread, NULL);
@@ -1071,11 +1071,11 @@ static int __unload_module(void)
                return -1;
        }
        if (!ast_mutex_lock(&monlock)) {
-               if (monitor_thread > -1) {
+               if (monitor_thread > AST_PTHREADT_NULL) {
                        pthread_cancel(monitor_thread);
                        pthread_join(monitor_thread, NULL);
                }
-               monitor_thread = -2;
+               monitor_thread = AST_PTHREADT_STOP;
                ast_mutex_unlock(&monlock);
        } else {
                ast_log(LOG_WARNING, "Unable to lock the monitor\n");
index 2784277..bcf9ff9 100755 (executable)
@@ -134,7 +134,7 @@ static ast_mutex_t monlock = AST_MUTEX_INITIALIZER;
 
 /* This is the thread for the monitor which checks for input on the channels
    which are not currently in use.  */
-static pthread_t monitor_thread = 0;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
 
 static int restart_monitor(void);
 
@@ -5818,7 +5818,7 @@ restartsearch:
 static int restart_monitor(void)
 {
        /* If we're supposed to be stopped -- stay stopped */
-       if (monitor_thread == (pthread_t) -2)
+       if (monitor_thread == AST_PTHREADT_STOP)
                return 0;
        if (ast_mutex_lock(&monlock)) {
                ast_log(LOG_WARNING, "Unable to lock monitor\n");
@@ -6865,12 +6865,12 @@ int unload_module()
                return -1;
        }
        if (!ast_mutex_lock(&monlock)) {
-               if (monitor_thread && ((int)monitor_thread != -2)) {
+               if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
                        pthread_cancel(monitor_thread);
                        pthread_kill(monitor_thread, SIGURG);
                        pthread_join(monitor_thread, NULL);
                }
-               monitor_thread = (pthread_t) -2;
+               monitor_thread = AST_PTHREADT_STOP;
                ast_mutex_unlock(&monlock);
        } else {
                ast_log(LOG_WARNING, "Unable to lock the monitor\n");
index b44c494..0a01bdc 100755 (executable)
@@ -599,7 +599,7 @@ static ast_mutex_t devicelock = AST_MUTEX_INITIALIZER;
 
 /* This is the thread for the monitor which checks for input on the channels
    which are not currently in use.  */
-static pthread_t monitor_thread = 0;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
 
 /* Wait up to 16 seconds for first digit */
 static int firstdigittimeout = 16000;
@@ -2415,7 +2415,7 @@ static int restart_monitor(void)
 {
 
        /* If we're supposed to be stopped -- stay stopped */
-       if (monitor_thread == (pthread_t)-2)
+       if (monitor_thread == AST_PTHREADT_STOP)
                return 0;
        if (ast_mutex_lock(&monlock)) {
                ast_log(LOG_WARNING, "Unable to lock monitor\n");
@@ -2718,12 +2718,12 @@ int unload_module()
                return -1;
        }
        if (!ast_mutex_lock(&monlock)) {
-               if (monitor_thread && (monitor_thread != -2)) {
+               if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
                        pthread_cancel(monitor_thread);
                        pthread_kill(monitor_thread, SIGURG);
                        pthread_join(monitor_thread, NULL);
                }
-               monitor_thread = -2;
+               monitor_thread = AST_PTHREADT_STOP;
                ast_mutex_unlock(&monlock);
        } else {
                ast_log(LOG_WARNING, "Unable to lock the monitor\n");
index 289e101..3d677bd 100755 (executable)
@@ -64,7 +64,7 @@ static ast_mutex_t monlock = AST_MUTEX_INITIALIZER;
 
 /* This is the thread for the monitor which checks for input on the channels
    which are not currently in use.  */
-static pthread_t monitor_thread = 0;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
 
 static int restart_monitor(void);
 
@@ -997,7 +997,7 @@ static void *do_monitor(void *data)
 static int restart_monitor(void)
 {
        /* If we're supposed to be stopped -- stay stopped */
-       if (monitor_thread == -2)
+       if (monitor_thread == AST_PTHREADT_STOP)
                return 0;
        if (ast_mutex_lock(&monlock)) {
                ast_log(LOG_WARNING, "Unable to lock monitor\n");
@@ -1161,7 +1161,7 @@ static int __unload_module(void)
                        pthread_kill(monitor_thread, SIGURG);
                        pthread_join(monitor_thread, NULL);
                }
-               monitor_thread = -2;
+               monitor_thread = AST_PTHREADT_STOP;
                ast_mutex_unlock(&monlock);
        } else {
                ast_log(LOG_WARNING, "Unable to lock the monitor\n");
index dd089f5..930a870 100755 (executable)
@@ -228,7 +228,7 @@ static ast_mutex_t monlock = AST_MUTEX_INITIALIZER;
 
 /* This is the thread for the monitor which checks for input on the channels
    which are not currently in use.  */
-static pthread_t monitor_thread = 0;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
 
 static int restart_monitor(void);
 
@@ -5171,7 +5171,7 @@ static int restart_monitor(void)
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
        /* If we're supposed to be stopped -- stay stopped */
-       if (monitor_thread == -2)
+       if (monitor_thread == AST_PTHREADT_STOP)
                return 0;
        if (ast_mutex_lock(&monlock)) {
                ast_log(LOG_WARNING, "Unable to lock monitor\n");
@@ -7313,12 +7313,12 @@ static int __unload_module(void)
                return -1;
        }
        if (!ast_mutex_lock(&monlock)) {
-               if (monitor_thread && (monitor_thread != -2)) {
+               if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
                        pthread_cancel(monitor_thread);
                        pthread_kill(monitor_thread, SIGURG);
                        pthread_join(monitor_thread, NULL);
                }
-               monitor_thread = -2;
+               monitor_thread = AST_PTHREADT_STOP;
                ast_mutex_unlock(&monlock);
        } else {
                ast_log(LOG_WARNING, "Unable to lock the monitor\n");