From 7acee329e1e2f75c286d5f5140d2d05f1dbf4bd5 Mon Sep 17 00:00:00 2001 From: Mark Spencer Date: Sun, 8 Aug 2004 17:15:02 +0000 Subject: Merge BSD stack size work (bug #2067) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3596 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- apps/app_qcall.c | 5 +++-- apps/app_rpt.c | 11 ++++++----- asterisk.c | 4 ++-- autoservice.c | 3 ++- channels/chan_alsa.c | 3 ++- channels/chan_h323.c | 2 +- channels/chan_iax.c | 2 +- channels/chan_iax2.c | 6 +++--- channels/chan_mgcp.c | 4 ++-- channels/chan_modem.c | 3 ++- channels/chan_oss.c | 3 ++- channels/chan_phone.c | 2 +- channels/chan_sip.c | 4 ++-- channels/chan_skinny.c | 8 ++++---- channels/chan_vofr.c | 3 ++- channels/chan_vpb.c | 7 ++++--- channels/chan_zap.c | 14 +++++++------- include/asterisk/agi.h | 3 ++- include/asterisk/lock.h | 1 + include/asterisk/utils.h | 12 ++++++++++++ manager.c | 6 +++--- pbx.c | 8 ++++---- pbx/pbx_gtkconsole.c | 3 ++- pbx/pbx_spool.c | 4 ++-- pbx/pbx_wilcalu.c | 9 +++++---- res/res_agi.c | 4 ++-- res/res_features.c | 2 +- res/res_musiconhold.c | 2 +- utils.c | 21 ++++++++++++++++++++- 29 files changed, 101 insertions(+), 58 deletions(-) diff --git a/apps/app_qcall.c b/apps/app_qcall.c index d171efe68..f5721e167 100755 --- a/apps/app_qcall.c +++ b/apps/app_qcall.c @@ -51,6 +51,7 @@ */ #include +#include #include #include #include @@ -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; } diff --git a/apps/app_rpt.c b/apps/app_rpt.c index 1df9c85a1..b5d0e5331 100755 --- a/apps/app_rpt.c +++ b/apps/app_rpt.c @@ -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 #include #include #include @@ -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); } diff --git a/asterisk.c b/asterisk.c index 2f8df1279..71d1ee448 100755 --- a/asterisk.c +++ b/asterisk.c @@ -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(<hread, NULL, listener, NULL); + ast_pthread_create(<hread, NULL, listener, NULL); return 0; } diff --git a/autoservice.c b/autoservice.c index 98a963353..0082ea87a 100755 --- a/autoservice.c +++ b/autoservice.c @@ -33,6 +33,7 @@ #include #include #include +#include #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; diff --git a/channels/chan_alsa.c b/channels/chan_alsa.c index 5f0efdde9..be1f09700 100755 --- a/channels/chan_alsa.c +++ b/channels/chan_alsa.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -1032,7 +1033,7 @@ int load_module() } for (x=0;xcallednum, 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) diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c index 205550b94..0ea32abf9 100755 --- a/channels/chan_mgcp.c +++ b/channels/chan_mgcp.c @@ -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; diff --git a/channels/chan_modem.c b/channels/chan_modem.c index 1a235c4f5..6113e0844 100755 --- a/channels/chan_modem.c +++ b/channels/chan_modem.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -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; diff --git a/channels/chan_oss.c b/channels/chan_oss.c index 538bfe1f8..86370f971 100755 --- a/channels/chan_oss.c +++ b/channels/chan_oss.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -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; } diff --git a/channels/chan_phone.c b/channels/chan_phone.c index 4828d05ef..bacfaa3c4 100755 --- a/channels/chan_phone.c +++ b/channels/chan_phone.c @@ -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; diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 28954cd05..614f3a964 100755 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -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; diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c index df3398dd0..db8a1ae82 100755 --- a/channels/chan_skinny.c +++ b/channels/chan_skinny.c @@ -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); diff --git a/channels/chan_vofr.c b/channels/chan_vofr.c index ad567aff4..eefde380d 100755 --- a/channels/chan_vofr.c +++ b/channels/chan_vofr.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -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; diff --git a/channels/chan_vpb.c b/channels/chan_vpb.c index e07b1c7d5..01d95a86b 100755 --- a/channels/chan_vpb.c +++ b/channels/chan_vpb.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/channels/chan_zap.c b/channels/chan_zap.c index e97620ed0..8a3b45380 100755 --- a/channels/chan_zap.c +++ b/channels/chan_zap.c @@ -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 : "", @@ -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;idchannels[i]) break; diff --git a/include/asterisk/agi.h b/include/asterisk/agi.h index 25899d58c..a488dfb26 100755 --- a/include/asterisk/agi.h +++ b/include/asterisk/agi.h @@ -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) } diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h index 7d92a727e..059bc89c6 100755 --- a/include/asterisk/lock.h +++ b/include/asterisk/lock.h @@ -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 diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h index 9a3b57329..93f99432a 100755 --- a/include/asterisk/utils.h +++ b/include/asterisk/utils.h @@ -12,7 +12,9 @@ #ifndef _ASTERISK_UTIL_H #define _ASTERISK_UTIL_H +#include #include +#include 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 diff --git a/manager.c b/manager.c index 0db032a98..878fabcc1 100755 --- 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 c39d7e104..d5db64560 100755 --- 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); diff --git a/pbx/pbx_gtkconsole.c b/pbx/pbx_gtkconsole.c index 852daf9a1..ce8189a6a 100755 --- a/pbx/pbx_gtkconsole.c +++ b/pbx/pbx_gtkconsole.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/pbx/pbx_spool.c b/pbx/pbx_spool.c index 2105ffe7b..fd51926b0 100755 --- a/pbx/pbx_spool.c +++ b/pbx/pbx_spool.c @@ -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; } diff --git a/pbx/pbx_wilcalu.c b/pbx/pbx_wilcalu.c index b3be54461..b2f61454f 100755 --- a/pbx/pbx_wilcalu.c +++ b/pbx/pbx_wilcalu.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -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; } diff --git a/res/res_agi.c b/res/res_agi.c index e96807b3f..dce634455 100755 --- a/res/res_agi.c +++ b/res/res_agi.c @@ -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;xpseudofd = -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 63aca4521..c1a03be5f 100755 --- a/utils.c +++ b/utils.c @@ -12,12 +12,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include 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 */ -- cgit v1.2.3