Merge BSD stack size work (bug #2067)
authorMark Spencer <markster@digium.com>
Sun, 8 Aug 2004 17:15:02 +0000 (17:15 +0000)
committerMark Spencer <markster@digium.com>
Sun, 8 Aug 2004 17:15:02 +0000 (17:15 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3596 65c4cc65-6c06-0410-ace0-fbb531ad65f3

29 files changed:
apps/app_qcall.c
apps/app_rpt.c
asterisk.c
autoservice.c
channels/chan_alsa.c
channels/chan_h323.c
channels/chan_iax.c
channels/chan_iax2.c
channels/chan_mgcp.c
channels/chan_modem.c
channels/chan_oss.c
channels/chan_phone.c
channels/chan_sip.c
channels/chan_skinny.c
channels/chan_vofr.c
channels/chan_vpb.c
channels/chan_zap.c
include/asterisk/agi.h
include/asterisk/lock.h
include/asterisk/utils.h
manager.c
pbx.c
pbx/pbx_gtkconsole.c
pbx/pbx_spool.c
pbx/pbx_wilcalu.c
res/res_agi.c
res/res_features.c
res/res_musiconhold.c
utils.c

index d171efe..f5721e1 100755 (executable)
@@ -51,6 +51,7 @@
  */
  
 #include <asterisk/lock.h>
+#include <asterisk/utils.h>
 #include <asterisk/file.h>
 #include <asterisk/logger.h>
 #include <asterisk/channel.h>
@@ -156,7 +157,7 @@ pthread_attr_t attr;
                        arg = (void *) strdup(fname);
                        pthread_attr_init(&attr);
                        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-                       if (pthread_create(&dialer_thread,&attr,qcall_do,arg) == -1)
+                       if (ast_pthread_create(&dialer_thread,&attr,qcall_do,arg) == -1)
                           {
                                perror("qcall: Cannot create thread");
                                continue;
@@ -371,7 +372,7 @@ int load_module(void)
 {
        snprintf(qdir, sizeof(qdir), "%s/%s", ast_config_AST_SPOOL_DIR, "qcall");
        mkdir(qdir,0760);
-       pthread_create(&qcall_thread,NULL,qcall,NULL);
+       ast_pthread_create(&qcall_thread,NULL,qcall,NULL);
        return 0;
 }
 
index 1df9c85..b5d0e53 100755 (executable)
@@ -103,6 +103,7 @@ enum {REM_LOWPWR,REM_MEDPWR,REM_HIPWR};
 enum {DC_INDETERMINATE, DC_REQ_FLUSH, DC_ERROR, DC_COMPLETE};
 enum {SOURCE_RPT, SOURCE_LNK, SOURCE_RMT};
 
+#include <asterisk/utils.h>
 #include <asterisk/lock.h>
 #include <asterisk/file.h>
 #include <asterisk/logger.h>
@@ -1055,7 +1056,7 @@ pthread_attr_t attr;
        ast_mutex_unlock(&myrpt->lock);
         pthread_attr_init(&attr);
         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-       pthread_create(&tele->threadid,&attr,rpt_tele_thread,(void *) tele);
+       ast_pthread_create(&tele->threadid,&attr,rpt_tele_thread,(void *) tele);
        return;
 }
 
@@ -1615,7 +1616,7 @@ static int function_autopatchup(struct rpt *myrpt, char *param, char *digitbuf,
        ast_mutex_unlock(&myrpt->lock);
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-       pthread_create(&myrpt->rpt_call_thread,&attr,rpt_call,(void *) myrpt);
+       ast_pthread_create(&myrpt->rpt_call_thread,&attr,rpt_call,(void *) myrpt);
        return DC_COMPLETE;
 }
 
@@ -3135,7 +3136,7 @@ char cmd[MAXDTMF+1] = "";
                                                myrpt->exten[myrpt->cidx] = 0;
                                                pthread_attr_init(&attr);
                                                pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-                                               pthread_create(&myrpt->rpt_call_thread,&attr,rpt_call,(void *)myrpt);
+                                               ast_pthread_create(&myrpt->rpt_call_thread,&attr,rpt_call,(void *)myrpt);
                                                continue;
                                        }
                                }
@@ -3539,7 +3540,7 @@ int       i,j,n,longestnode;
                        ast_log(LOG_WARNING,"Did not specify ident for node %s\n",rpt_vars[i].name);
                        pthread_exit(NULL);
                }
-               pthread_create(&rpt_vars[i].rpt_thread,NULL,rpt,(void *) &rpt_vars[i]);
+               ast_pthread_create(&rpt_vars[i].rpt_thread,NULL,rpt,(void *) &rpt_vars[i]);
        }
        /* wait for first one to die (should be never) */
        pthread_join(rpt_vars[0].rpt_thread,NULL);
@@ -3920,7 +3921,7 @@ int unload_module(void)
 
 int load_module(void)
 {
-       pthread_create(&rpt_master_thread,NULL,rpt_master,NULL);
+       ast_pthread_create(&rpt_master_thread,NULL,rpt_master,NULL);
        return ast_register_application(app, rpt_exec, synopsis, descrip);
 }
 
index 2f8df12..71d1ee4 100755 (executable)
@@ -342,7 +342,7 @@ static void *listener(void *unused)
                                        flags = fcntl(consoles[x].p[1], F_GETFL);
                                        fcntl(consoles[x].p[1], F_SETFL, flags | O_NONBLOCK);
                                        consoles[x].fd = s;
-                                       if (pthread_create(&consoles[x].t, &attr, netconsole, &consoles[x])) {
+                                       if (ast_pthread_create(&consoles[x].t, &attr, netconsole, &consoles[x])) {
                                                ast_log(LOG_ERROR, "Unable to spawn thread to handle connection: %s\n", strerror(errno));
                                                consoles[x].fd = -1;
                                                fdprint(s, "Server failed to spawn thread\n");
@@ -395,7 +395,7 @@ static int ast_makesocket(void)
                return -1;
        }
        ast_register_verbose(network_verboser);
-       pthread_create(&lthread, NULL, listener, NULL);
+       ast_pthread_create(&lthread, NULL, listener, NULL);
        return 0;
 }
 
index 98a9633..0082ea8 100755 (executable)
@@ -33,6 +33,7 @@
 #include <asterisk/linkedlists.h>
 #include <asterisk/indications.h>
 #include <asterisk/lock.h>
+#include <asterisk/utils.h>
 
 #define MAX_AUTOMONS 256
 
@@ -106,7 +107,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;
index 5f0efdd..be1f097 100755 (executable)
@@ -18,6 +18,7 @@
 #include <asterisk/pbx.h>
 #include <asterisk/config.h>
 #include <asterisk/cli.h>
+#include <asterisk/utils.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
@@ -1032,7 +1033,7 @@ int load_module()
        }
        for (x=0;x<sizeof(myclis)/sizeof(struct ast_cli_entry); x++)
                ast_cli_register(myclis + x);
-       pthread_create(&sthread, NULL, sound_thread, NULL);
+       ast_pthread_create(&sthread, NULL, sound_thread, NULL);
 #ifdef ALSA_MONITOR
        if (alsa_monitor_start()) {
                ast_log(LOG_ERROR, "Problem starting Monitoring\n");
index 9bd35f0..124c2d9 100755 (executable)
@@ -1441,7 +1441,7 @@ static int restart_monitor(void)
                pthread_kill(monitor_thread, SIGURG);
        } else {
                /* Start a new monitor */
-               if (pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
+               if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
                        ast_mutex_unlock(&monlock);
                        ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
                        return -1;
index 754ce25..6a3cc34 100755 (executable)
@@ -4548,7 +4548,7 @@ static void *network_thread(void *ignore)
 
 static int start_network_thread(void)
 {
-       return pthread_create(&netthreadid, NULL, network_thread, NULL);
+       return ast_pthread_create(&netthreadid, NULL, network_thread, NULL);
 }
 
 static struct iax_context *build_context(char *context)
index f135f15..4c51915 100755 (executable)
@@ -4729,7 +4729,7 @@ static void spawn_dp_lookup(int callno, char *context, char *callednum, char *ca
                strncpy(dpr->callednum, callednum, sizeof(dpr->callednum) - 1);
                if (callerid)
                        dpr->callerid = strdup(callerid);
-               if (pthread_create(&newthread, NULL, dp_lookup_thread, dpr)) {
+               if (ast_pthread_create(&newthread, NULL, dp_lookup_thread, dpr)) {
                        ast_log(LOG_WARNING, "Unable to start lookup thread!\n");
                }
        } else
@@ -4807,7 +4807,7 @@ static int iax_park(struct ast_channel *chan1, struct ast_channel *chan2)
                memset(d, 0, sizeof(*d));
                d->chan1 = chan1m;
                d->chan2 = chan2m;
-               if (!pthread_create(&th, NULL, iax_park_thread, d))
+               if (!ast_pthread_create(&th, NULL, iax_park_thread, d))
                        return 0;
                free(d);
        }
@@ -6164,7 +6164,7 @@ static void *network_thread(void *ignore)
 
 static int start_network_thread(void)
 {
-       return pthread_create(&netthreadid, NULL, network_thread, NULL);
+       return ast_pthread_create(&netthreadid, NULL, network_thread, NULL);
 }
 
 static struct iax2_context *build_context(char *context)
index 205550b..0ea32ab 100755 (executable)
@@ -2798,7 +2798,7 @@ static void handle_hd_hf(struct mgcp_subchannel *sub, char *ev)
                 }
                 c = mgcp_new(sub, AST_STATE_DOWN);
                 if (c) {
-                    if (pthread_create(&t, &attr, mgcp_ss, c)) {
+                    if (ast_pthread_create(&t, &attr, mgcp_ss, c)) {
                         ast_log(LOG_WARNING, "Unable to create switch thread: %s\n", strerror(errno));
                         ast_hangup(c);
                     }
@@ -3325,7 +3325,7 @@ static int restart_monitor(void)
                pthread_kill(monitor_thread, SIGURG);
        } else {
                /* Start a new monitor */
-               if (pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
+               if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
                        ast_mutex_unlock(&monlock);
                        ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
                        return -1;
index 1a235c4..6113e08 100755 (executable)
@@ -22,6 +22,7 @@
 #include <asterisk/pbx.h>
 #include <asterisk/options.h>
 #include <asterisk/vmodem.h>
+#include <asterisk/utils.h>
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <errno.h>
@@ -673,7 +674,7 @@ static int restart_monitor()
                pthread_join(monitor_thread, NULL);
        }
        /* Start a new monitor */
-       if (pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
+       if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
                ast_mutex_unlock(&monlock);
                ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
                return -1;
index 538bfe1..86370f9 100755 (executable)
@@ -25,6 +25,7 @@
 #include <asterisk/pbx.h>
 #include <asterisk/config.h>
 #include <asterisk/cli.h>
+#include <asterisk/utils.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
@@ -1011,7 +1012,7 @@ int load_module()
                }
                ast_destroy(cfg);
        }
-       pthread_create(&sthread, NULL, sound_thread, NULL);
+       ast_pthread_create(&sthread, NULL, sound_thread, NULL);
        return 0;
 }
 
index 4828d05..bacfaa3 100755 (executable)
@@ -962,7 +962,7 @@ static int restart_monitor()
 #endif
        }
        /* Start a new monitor */
-       if (pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
+       if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
                ast_mutex_unlock(&monlock);
                ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
                return -1;
index 28954cd..614f3a9 100755 (executable)
@@ -6780,7 +6780,7 @@ static int sip_park(struct ast_channel *chan1, struct ast_channel *chan2, struct
                copy_request(&d->req, req);
                d->chan1 = chan1m;
                d->chan2 = chan2m;
-               if (!pthread_create(&th, NULL, sip_park_thread, d))
+               if (!ast_pthread_create(&th, NULL, sip_park_thread, d))
                        return 0;
                free(d);
        }
@@ -7633,7 +7633,7 @@ static int restart_monitor(void)
                pthread_attr_init(&attr);
                pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
                /* Start a new monitor */
-               if (pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
+               if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
                        ast_mutex_unlock(&monlock);
                        ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
                        return -1;
index df3398d..db8a1ae 100755 (executable)
@@ -2113,7 +2113,7 @@ static int handle_message(skinny_req *req, struct skinnysession *s)
                                        c = skinny_new(sub, AST_STATE_DOWN);                    
                                        if(c) {
                                                /* start switch */
-                                               if (pthread_create(&t, NULL, skinny_ss, c)) {
+                                               if (ast_pthread_create(&t, NULL, skinny_ss, c)) {
                                                        ast_log(LOG_WARNING, "Unable to create switch thread: %s\n", strerror(errno));
                                                        ast_hangup(c);
                                                }
@@ -2403,7 +2403,7 @@ static void *accept_thread(void *ignore)
                sessions = s;
                ast_mutex_unlock(&sessionlock);
                
-               if (pthread_create(&tcp_thread, NULL, skinny_session, s)) {
+               if (ast_pthread_create(&tcp_thread, NULL, skinny_session, s)) {
                        destroy_session(s);
                }
        }
@@ -2461,7 +2461,7 @@ static int restart_monitor(void)
                pthread_kill(monitor_thread, SIGURG);
        } else {
                /* Start a new monitor */
-               if (pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
+               if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
                        ast_mutex_unlock(&monlock);
                        ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
                        return -1;
@@ -2649,7 +2649,7 @@ static int reload_config(void)
                                ast_verbose(VERBOSE_PREFIX_2 "Skinny listening on %s:%d\n", 
                                        ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr.sin_addr), ntohs(bindaddr.sin_port));
 
-                       pthread_create(&accept_t,NULL, accept_thread, NULL);
+                       ast_pthread_create(&accept_t,NULL, accept_thread, NULL);
                }
        }
        ast_mutex_unlock(&netlock);
index ad567af..eefde38 100755 (executable)
@@ -19,6 +19,7 @@
 #include <asterisk/config.h>
 #include <asterisk/logger.h>
 #include <asterisk/module.h>
+#include <asterisk/utils.h>
 #include <asterisk/pbx.h>
 #include <asterisk/options.h>
 #include <sys/socket.h>
@@ -1014,7 +1015,7 @@ static int restart_monitor(void)
                pthread_kill(monitor_thread, SIGURG);
        } else {
                /* Start a new monitor */
-               if (pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
+               if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
                        ast_mutex_unlock(&monlock);
                        ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
                        return -1;
index e07b1c7..01d95a8 100755 (executable)
@@ -23,6 +23,7 @@
 #include <asterisk/module.h>
 #include <asterisk/pbx.h>
 #include <asterisk/options.h>
+#include <asterisk/utils.h>
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <errno.h>
@@ -942,7 +943,7 @@ static int restart_monitor(void)
                        vpb_put_event(&e);
                } else {
                        /* Start a new monitor */
-                       int pid = pthread_create(&monitor_thread, NULL, do_monitor, NULL); 
+                       int pid = ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL); 
                        if (option_verbose > 3)
                                ast_verbose(VERBOSE_PREFIX_4 "Created new monitor thread %d\n",pid);
                        if (pid < 0) {
@@ -1287,7 +1288,7 @@ static int vpb_call(struct ast_channel *ast, char *dest, int timeout)
        }
 
        if (!p->readthread){
-               pthread_create(&p->readthread, NULL, do_chanreads, (void *)p);
+               ast_pthread_create(&p->readthread, NULL, do_chanreads, (void *)p);
        }
 
        tmp = ast_mutex_unlock(&p->lock);
@@ -1423,7 +1424,7 @@ static int vpb_answer(struct ast_channel *ast)
                if( !p->readthread ){
        //              res = ast_mutex_unlock(&p->lock);
        //              ast_verbose("%s: unLOCKING in answer [%d]\n", p->dev,res);
-                       pthread_create(&p->readthread, NULL, do_chanreads, (void *)p);
+                       ast_pthread_create(&p->readthread, NULL, do_chanreads, (void *)p);
                } else {
                        if(option_verbose>3) 
                                ast_verbose(VERBOSE_PREFIX_4 "%s: Record thread already running!!\n",p->dev);
index e97620e..8a3b453 100755 (executable)
@@ -3482,7 +3482,7 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
                                                                        if (res)
                                                                                ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel);
                                                                        p->owner = chan;
-                                                                       if (chan && pthread_create(&threadid, &attr, ss_thread, chan)) {
+                                                                       if (chan && ast_pthread_create(&threadid, &attr, ss_thread, chan)) {
                                                                                ast_log(LOG_WARNING, "Unable to start simple switch on channel %d\n", p->channel);
                                                                                res = tone_zone_play_tone(p->subs[SUB_REAL].zfd, ZT_TONE_CONGESTION);
                                                                                zt_enable_ec(p);
@@ -5311,7 +5311,7 @@ static int handle_init_event(struct zt_pvt *i, int event)
                                                res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_DIALTONE);
                                        if (res < 0) 
                                                ast_log(LOG_WARNING, "Unable to play dialtone on channel %d\n", i->channel);
-                                       if (pthread_create(&threadid, &attr, ss_thread, chan)) {
+                                       if (ast_pthread_create(&threadid, &attr, ss_thread, chan)) {
                                                ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
                                                res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_CONGESTION);
                                                if (res < 0)
@@ -5344,7 +5344,7 @@ static int handle_init_event(struct zt_pvt *i, int event)
                case SIG_SF:
                                /* Check for callerid, digits, etc */
                                chan = zt_new(i, AST_STATE_RING, 0, SUB_REAL, 0, 0);
-                               if (chan && pthread_create(&threadid, &attr, ss_thread, chan)) {
+                               if (chan && ast_pthread_create(&threadid, &attr, ss_thread, chan)) {
                                        ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
                                        res = tone_zone_play_tone(i->subs[SUB_REAL].zfd, ZT_TONE_CONGESTION);
                                        if (res < 0)
@@ -5670,7 +5670,7 @@ static int restart_monitor(void)
 #endif
        } else {
                /* Start a new monitor */
-               if (pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
+               if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
                        ast_mutex_unlock(&monlock);
                        ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
                        return -1;
@@ -6951,7 +6951,7 @@ static void *pri_dchannel(void *vpri)
                                        idle = zt_request("Zap", AST_FORMAT_ULAW, idlen);
                                        if (idle) {
                                                pri->pvts[nextidle]->isidlecall = 1;
-                                               if (pthread_create(&p, NULL, do_idle_thread, idle)) {
+                                               if (ast_pthread_create(&p, NULL, do_idle_thread, idle)) {
                                                        ast_log(LOG_WARNING, "Unable to start new thread for idle channel '%s'\n", idle->name);
                                                        zt_hangup(idle);
                                                }
@@ -7320,7 +7320,7 @@ static void *pri_dchannel(void *vpri)
                                                                pbx_builtin_setvar_helper(c, "CALLINGSUBADDR", e->ring.callingsubaddr);
                                                        }
                                                        ast_mutex_lock(&pri->lock);
-                                                       if (c && !pthread_create(&threadid, &attr, ss_thread, c)) {
+                                                       if (c && !ast_pthread_create(&threadid, &attr, ss_thread, c)) {
                                                                if (option_verbose > 2)
                                                                        ast_verbose(VERBOSE_PREFIX_3 "Accepting overlap call from '%s' to '%s' on channel %d/%d, span %d\n",
                                                                                e->ring.callingnum, !ast_strlen_zero(pri->pvts[chanpos]->exten) ? pri->pvts[chanpos]->exten : "<unspecified>", 
@@ -7777,7 +7777,7 @@ static int start_pri(struct zt_pri *pri)
        /* Assume primary is the one we use */
        pri->pri = pri->dchans[0];
        pri->resetpos = -1;
-       if (pthread_create(&pri->master, NULL, pri_dchannel, pri)) {
+       if (ast_pthread_create(&pri->master, NULL, pri_dchannel, pri)) {
                for (i=0;i<NUM_DCHANS;i++) {
                        if (!pri->dchannels[i])
                                break;
index 25899d5..a488dfb 100755 (executable)
@@ -37,7 +37,8 @@ typedef struct agi_command {
        struct agi_command *next;
 } agi_command;
 
-
+int agi_register(agi_command *cmd);
+void agi_unregister(agi_command *cmd);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }
index 7d92a72..059bc89 100755 (executable)
@@ -357,5 +357,6 @@ static inline int ast_mutex_trylock(ast_mutex_t *pmutex)
 #define AST_MUTEX_INITIALIZER __use_AST_MUTEX_DEFINE_STATIC_rather_than_AST_MUTEX_INITIALIZER__
 
 #define gethostbyname __gethostbyname__is__not__reentrant__use__ast_gethostbyname__instead__
+#define pthread_create __use_ast_pthread_create_instead__
 
 #endif
index 9a3b573..93f9943 100755 (executable)
@@ -12,7 +12,9 @@
 #ifndef _ASTERISK_UTIL_H
 #define _ASTERISK_UTIL_H
 
+#include <netinet/in.h>
 #include <netdb.h>
+#include <pthread.h>
 
 static inline int ast_strlen_zero(const char *s)
 {
@@ -37,4 +39,14 @@ extern int ast_utils_init(void);
 #endif
 #define inet_ntoa __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__
 
+#ifdef LINUX
+#define ast_pthread_create pthread_create
+#else
+/* Linux threads have a default 2MB stack size. */
+#ifndef PTHREAD_ATTR_STACKSIZE
+#define        PTHREAD_ATTR_STACKSIZE          2097152
+#endif /* PTHREAD_ATTR_STACKSIZE */
+extern int ast_pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *data);
+#endif /* LINUX */
+
 #endif
index 0db032a..878fabc 100755 (executable)
--- a/manager.c
+++ b/manager.c
@@ -886,7 +886,7 @@ static int action_originate(struct mansession *s, struct message *m)
                        fast->priority = pi;
                        pthread_attr_init(&attr);
                        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-                       if (pthread_create(&th, &attr, fast_originate, fast))
+                       if (ast_pthread_create(&th, &attr, fast_originate, fast))
                        {
                                res = -1;
                        }
@@ -1216,7 +1216,7 @@ static void *accept_thread(void *ignore)
                s->next = sessions;
                sessions = s;
                ast_mutex_unlock(&sessionlock);
-               if (pthread_create(&t, &attr, session_do, s))
+               if (ast_pthread_create(&t, &attr, session_do, s))
                        destroy_session(s);
        }
        pthread_attr_destroy(&attr);
@@ -1448,7 +1448,7 @@ int init_manager(void)
                }
                if (option_verbose)
                        ast_verbose("Asterisk Management interface listening on port %d\n", portno);
-               pthread_create(&t, NULL, accept_thread, NULL);
+               ast_pthread_create(&t, NULL, accept_thread, NULL);
        }
        return 0;
 }
diff --git a/pbx.c b/pbx.c
index c39d7e1..d5db645 100755 (executable)
--- a/pbx.c
+++ b/pbx.c
@@ -1985,7 +1985,7 @@ int ast_pbx_start(struct ast_channel *c)
        /* Start a new thread, and get something handling this channel. */
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-       if (pthread_create(&t, &attr, pbx_thread, c)) {
+       if (ast_pthread_create(&t, &attr, pbx_thread, c)) {
                ast_log(LOG_WARNING, "Failed to create new channel thread\n");
                return -1;
        }
@@ -4041,7 +4041,7 @@ int ast_pbx_outgoing_exten(char *type, int format, void *data, int timeout, char
                }
                pthread_attr_init(&attr);
                pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-               if (pthread_create(&as->p, &attr, async_wait, as)) {
+               if (ast_pthread_create(&as->p, &attr, async_wait, as)) {
                        ast_log(LOG_WARNING, "Failed to start async wait\n");
                        free(as);
                        ast_hangup(chan);
@@ -4111,7 +4111,7 @@ int ast_pbx_outgoing_app(char *type, int format, void *data, int timeout, char *
                                        } else {
                                                pthread_attr_init(&attr);
                                                pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-                                               if (pthread_create(&tmp->t, &attr, ast_pbx_run_app, tmp)) {
+                                               if (ast_pthread_create(&tmp->t, &attr, ast_pbx_run_app, tmp)) {
                                                        ast_log(LOG_WARNING, "Unable to spawn execute thread on %s: %s\n", chan->name, strerror(errno));
                                                        free(tmp);
                                                        ast_hangup(chan);
@@ -4152,7 +4152,7 @@ int ast_pbx_outgoing_app(char *type, int format, void *data, int timeout, char *
                /* Start a new thread, and get something handling this channel. */
                pthread_attr_init(&attr);
                pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-               if (pthread_create(&as->p, &attr, async_wait, as)) {
+               if (ast_pthread_create(&as->p, &attr, async_wait, as)) {
                        ast_log(LOG_WARNING, "Failed to start async wait\n");
                        free(as);
                        ast_hangup(chan);
index 852daf9..ce8189a 100755 (executable)
@@ -26,6 +26,7 @@
 #include <asterisk/logger.h>
 #include <asterisk/options.h>
 #include <asterisk/cli.h>
+#include <asterisk/utils.h>
 #include <stdlib.h>
 #include <fcntl.h>
 #include <unistd.h>
@@ -450,7 +451,7 @@ static int show_console(void)
        gtk_container_add(GTK_CONTAINER(window), hbox);
        gtk_window_set_title(GTK_WINDOW(window), "Asterisk Console");
        gtk_widget_grab_focus(cli);
-       pthread_create(&console_thread, NULL, consolethread, NULL);
+       ast_pthread_create(&console_thread, NULL, consolethread, NULL);
        /* XXX Okay, seriously fix me! XXX */
        usleep(100000);
        ast_register_verbose(verboser);
index 2105ffe..fd51926 100755 (executable)
@@ -253,7 +253,7 @@ static void launch_service(struct outgoing *o)
        pthread_attr_t attr;
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-       if (pthread_create(&t,&attr,attempt_thread, o) == -1) {
+       if (ast_pthread_create(&t,&attr,attempt_thread, o) == -1) {
                ast_log(LOG_WARNING, "Unable to create thread :(\n");
                free(o);
        }
@@ -382,7 +382,7 @@ int load_module(void)
        }
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-       if (pthread_create(&thread,&attr,scan_thread, NULL) == -1) {
+       if (ast_pthread_create(&thread,&attr,scan_thread, NULL) == -1) {
                ast_log(LOG_WARNING, "Unable to create thread :(\n");
                return -1;
        }
index b3be544..b2f6145 100755 (executable)
@@ -25,6 +25,7 @@
 #include <asterisk/module.h>
 #include <asterisk/translate.h>
 #include <asterisk/options.h>
+#include <asterisk/utils.h>
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
@@ -98,7 +99,7 @@ static void *autodial(void *ignore)
                                /* if & then string is complete */
                                if(buf[x]=='&'){
                                        if(NULL!=(pass=(void *)strdup(sendbuf))){
-                                               pthread_create(&dialstring_thread, NULL, dialstring, pass);
+                                               ast_pthread_create(&dialstring_thread, NULL, dialstring, pass);
                                                sendbufptr=sendbuf;
                                                memset(sendbuf, 0, 257);
                                        }
@@ -130,7 +131,7 @@ static void *snooze_alarm(void *pass)
        struct alarm_data *data = (struct alarm_data *) pass;
 
        sleep(data->snooze_len);
-       pthread_create(&dialstring_thread, NULL, dialstring, data->dialstr);
+       ast_pthread_create(&dialstring_thread, NULL, dialstring, data->dialstr);
        /* dialstring will free data->dialstr */
        free(pass);
        pthread_exit(NULL);
@@ -153,7 +154,7 @@ static void  set_snooze_alarm(char *dialstr, int snooze_len)
                pthread_exit(NULL);
        }
        pass->snooze_len=snooze_len;
-       pthread_create(&snooze_alarm_thread,NULL,snooze_alarm,pass);
+       ast_pthread_create(&snooze_alarm_thread,NULL,snooze_alarm,pass);
 }
                        
 static void *dialstring(void *string)
@@ -266,7 +267,7 @@ int load_module(void)
                        return 0;
                }
        }
-       pthread_create(&autodialer_thread, NULL, autodial, NULL);
+       ast_pthread_create(&autodialer_thread, NULL, autodial, NULL);
        return 0;
 }
 
index e96807b..dce6344 100755 (executable)
@@ -1160,7 +1160,7 @@ static int help_workhorse(int fd, char *match[])
        return 0;
 }
 
-static int agi_register(agi_command *agi)
+int agi_register(agi_command *agi)
 {
        int x;
        for (x=0;x<MAX_COMMANDS - 1;x++) {
@@ -1179,7 +1179,7 @@ static int agi_register(agi_command *agi)
        return -1;
 }
 
-static void agi_unregister(agi_command *agi)
+void agi_unregister(agi_command *agi)
 {
        int x;
        for (x=0;x<MAX_COMMANDS - 1;x++) {
index 669060c..4d21929 100755 (executable)
@@ -864,7 +864,7 @@ int load_module(void)
                }
        }
        ast_add_extension2(con, 1, ast_parking_ext(), 1, NULL, parkcall, strdup(""),free, registrar);
-       pthread_create(&parking_thread, NULL, do_parking_thread, NULL);
+       ast_pthread_create(&parking_thread, NULL, do_parking_thread, NULL);
        res = ast_register_application(parkedcall, park_exec, synopsis, descrip);
        if (!res)
                res = ast_register_application(parkcall, park_call_exec, synopsis2, descrip2);
index 6479565..f31b977 100755 (executable)
@@ -548,7 +548,7 @@ static int moh_register(char *classname, char *mode, char *param, char *miscargs
 #else
                moh->pseudofd = -1;
 #endif
-               if (pthread_create(&moh->thread, NULL, monmp3thread, moh)) {
+               if (ast_pthread_create(&moh->thread, NULL, monmp3thread, moh)) {
                        ast_log(LOG_WARNING, "Unable to create moh...\n");
                        if (moh->pseudofd > -1)
                                close(moh->pseudofd);
diff --git a/utils.c b/utils.c
index 63aca45..c1a03be 100755 (executable)
--- a/utils.c
+++ b/utils.c
 #include <ctype.h>
 #include <string.h>
 #include <unistd.h>
+#include <errno.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <asterisk/lock.h>
 #include <asterisk/utils.h>
+#include <asterisk/logger.h>
 
 static char base64[64];
 static char b2a[256];
@@ -197,7 +199,7 @@ int test_for_thread_safety(void)
        lock_count += 1;
        ast_mutex_lock(&test_lock);
        lock_count += 1;
-       pthread_create(&test_thread, NULL, test_thread_body, NULL); 
+       ast_pthread_create(&test_thread, NULL, test_thread_body, NULL); 
        usleep(100);
        if (lock_count != 2) 
                test_errors++;
@@ -344,3 +346,20 @@ int ast_utils_init(void)
        base64_init();
        return 0;
 }
+
+
+#ifndef LINUX
+#undef pthread_create /* For ast_pthread_create function only */
+int ast_pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *data)
+{
+       pthread_attr_t lattr;
+       if (!attr) {
+               pthread_attr_init(&lattr);
+               attr = &lattr;
+       }
+       errno = pthread_attr_setstacksize(attr, PTHREAD_ATTR_STACKSIZE);
+       if (errno)
+               ast_log(LOG_WARNING, "pthread_attr_setstacksize returned non-zero: %s\n", strerror(errno));
+       return pthread_create(thread, attr, start_routine, data); /* We're in ast_pthread_create, so it's okay */
+}
+#endif /* ! LINUX */