[asterisk-commits] russell: trunk r65968 - in /trunk: apps/
channels/ include/asterisk/ main/ pbx/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Thu May 24 11:30:20 MST 2007
Author: russell
Date: Thu May 24 13:30:19 2007
New Revision: 65968
URL: http://svn.digium.com/view/asterisk?view=rev&rev=65968
Log:
Add a new API call for creating detached threads. Then, go replace all of the
places in the code where the same block of code for creating detached threads
was replicated. (patch from bbryant)
Modified:
trunk/apps/app_meetme.c
trunk/apps/app_mixmonitor.c
trunk/apps/app_rpt.c
trunk/channels/chan_h323.c
trunk/channels/chan_iax2.c
trunk/channels/chan_mgcp.c
trunk/channels/chan_sip.c
trunk/channels/chan_skinny.c
trunk/channels/chan_zap.c
trunk/include/asterisk/utils.h
trunk/main/asterisk.c
trunk/main/cdr.c
trunk/main/http.c
trunk/main/manager.c
trunk/main/pbx.c
trunk/main/utils.c
trunk/pbx/pbx_dundi.c
trunk/pbx/pbx_spool.c
Modified: trunk/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_meetme.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/apps/app_meetme.c (original)
+++ trunk/apps/app_meetme.c Thu May 24 13:30:19 2007
@@ -1428,10 +1428,7 @@
ast_hangup(conf->lchan);
conf->lchan = NULL;
} else {
- pthread_attr_init(&conf->attr);
- pthread_attr_setdetachstate(&conf->attr, PTHREAD_CREATE_DETACHED);
- ast_pthread_create_background(&conf->recordthread, &conf->attr, recordthread, conf);
- pthread_attr_destroy(&conf->attr);
+ ast_pthread_create_detached_background(&conf->recordthread, &conf->attr, recordthread, conf);
}
}
@@ -3458,7 +3455,6 @@
struct sla_ringing_trunk *ringing_trunk = NULL;
struct run_station_args args;
enum ast_dial_result dial_res;
- pthread_attr_t attr;
pthread_t dont_care;
ast_mutex_t cond_lock;
ast_cond_t cond;
@@ -3499,15 +3495,12 @@
free(ringing_station);
ast_mutex_init(&cond_lock);
ast_cond_init(&cond, NULL);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
ast_mutex_lock(&cond_lock);
- ast_pthread_create_background(&dont_care, &attr, run_station, &args);
+ ast_pthread_create_detached_background(&dont_care, NULL, run_station, &args);
ast_cond_wait(&cond, &cond_lock);
ast_mutex_unlock(&cond_lock);
ast_mutex_destroy(&cond_lock);
ast_cond_destroy(&cond);
- pthread_attr_destroy(&attr);
break;
case AST_DIAL_RESULT_TRYING:
case AST_DIAL_RESULT_RINGING:
@@ -4237,7 +4230,6 @@
ast_mutex_t cond_lock;
ast_cond_t cond;
pthread_t dont_care;
- pthread_attr_t attr;
struct dial_trunk_args args = {
.trunk_ref = trunk_ref,
.station = station,
@@ -4251,15 +4243,12 @@
ast_autoservice_start(chan);
ast_mutex_init(&cond_lock);
ast_cond_init(&cond, NULL);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
ast_mutex_lock(&cond_lock);
- ast_pthread_create_background(&dont_care, &attr, dial_trunk, &args);
+ ast_pthread_create_detached_background(&dont_care, NULL, dial_trunk, &args);
ast_cond_wait(&cond, &cond_lock);
ast_mutex_unlock(&cond_lock);
ast_mutex_destroy(&cond_lock);
ast_cond_destroy(&cond);
- pthread_attr_destroy(&attr);
ast_autoservice_stop(chan);
if (!trunk_ref->trunk->chan) {
ast_log(LOG_DEBUG, "Trunk didn't get created. chan: %lx\n", (long) trunk_ref->trunk->chan);
Modified: trunk/apps/app_mixmonitor.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_mixmonitor.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/apps/app_mixmonitor.c (original)
+++ trunk/apps/app_mixmonitor.c Thu May 24 13:30:19 2007
@@ -229,7 +229,6 @@
static void launch_monitor_thread(struct ast_channel *chan, const char *filename, unsigned int flags,
int readvol, int writevol, const char *post_process)
{
- pthread_attr_t attr;
pthread_t thread;
struct mixmonitor *mixmonitor;
char postprocess2[1024] = "";
@@ -296,10 +295,7 @@
return;
}
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- ast_pthread_create_background(&thread, &attr, mixmonitor_thread, mixmonitor);
- pthread_attr_destroy(&attr);
+ ast_pthread_create_detached_background(&thread, NULL, mixmonitor_thread, mixmonitor);
}
Modified: trunk/apps/app_rpt.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_rpt.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/apps/app_rpt.c (original)
+++ trunk/apps/app_rpt.c Thu May 24 13:30:19 2007
@@ -2452,7 +2452,6 @@
struct rpt_tele *tele;
struct rpt_link *mylink = (struct rpt_link *) data;
int res;
- pthread_attr_t attr;
tele = ast_calloc(1, sizeof(struct rpt_tele));
if (!tele) {
@@ -2471,10 +2470,7 @@
}
insque((struct qelem *)tele, (struct qelem *)myrpt->tele.next);
rpt_mutex_unlock(&myrpt->lock);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- res = ast_pthread_create(&tele->threadid, &attr, rpt_tele_thread, (void *) tele);
- pthread_attr_destroy(&attr);
+ res = ast_pthread_create_detached(&tele->threadid, NULL, rpt_tele_thread, (void *) tele);
if (res != 0) {
rpt_mutex_lock(&myrpt->lock);
remque((struct qlem *) tele); /* We don't like stuck transmitters, remove it from the queue */
@@ -3108,7 +3104,6 @@
static int function_autopatchup(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink)
{
- pthread_attr_t attr;
int i, index;
char *value = NULL;
AST_DECLARE_APP_ARGS(params,
@@ -3184,10 +3179,7 @@
myrpt->cidx = 0;
myrpt->exten[myrpt->cidx] = 0;
rpt_mutex_unlock(&myrpt->lock);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- ast_pthread_create(&myrpt->rpt_call_thread, &attr, rpt_call, (void *) myrpt);
- pthread_attr_destroy(&attr);
+ ast_pthread_create_detached(&myrpt->rpt_call_thread, NULL, rpt_call, (void *) myrpt);
return DC_COMPLETE;
}
@@ -5448,7 +5440,6 @@
static void local_dtmf_helper(struct rpt *myrpt, char c)
{
int res;
- pthread_attr_t attr;
char cmd[MAXDTMF+1] = "";
if (c == myrpt->p.endchar) {
@@ -5537,10 +5528,7 @@
myrpt->cidx = 0;
myrpt->exten[myrpt->cidx] = 0;
rpt_mutex_unlock(&myrpt->lock);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- ast_pthread_create(&myrpt->rpt_call_thread, &attr, rpt_call, (void *)myrpt);
- pthread_attr_destroy(&attr);
+ ast_pthread_create_detached(&myrpt->rpt_call_thread, NULL, rpt_call, (void *)myrpt);
return;
}
}
@@ -6668,7 +6656,6 @@
static void *rpt_master(void *config)
{
int i, n;
- pthread_attr_t attr;
struct ast_config *cfg;
char *this;
const char *val;
@@ -6732,10 +6719,7 @@
ast_config_destroy(cfg);
pthread_exit(NULL);
}
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- ast_pthread_create(&rpt_vars[i].rpt_thread, &attr, rpt, (void *) &rpt_vars[i]);
- pthread_attr_destroy(&attr);
+ ast_pthread_create_detached(&rpt_vars[i].rpt_thread, NULL, rpt, (void *) &rpt_vars[i]);
}
usleep(500000);
for (;;) {
@@ -6761,10 +6745,7 @@
rpt_vars[i].threadrestarts = 0;
rpt_vars[i].lastthreadrestarttime = time(NULL);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- ast_pthread_create(&rpt_vars[i].rpt_thread, &attr, rpt, (void *) &rpt_vars[i]);
- pthread_attr_destroy(&attr);
+ ast_pthread_create_detached(&rpt_vars[i].rpt_thread, NULL, rpt, (void *) &rpt_vars[i]);
ast_log(LOG_WARNING, "rpt_thread restarted on node %s\n", rpt_vars[i].name);
}
Modified: trunk/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_h323.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/channels/chan_h323.c (original)
+++ trunk/channels/chan_h323.c Thu May 24 13:30:19 2007
@@ -2601,7 +2601,6 @@
static int restart_monitor(void)
{
- pthread_attr_t attr;
/* If we're supposed to be stopped -- stay stopped */
if (ast_mutex_lock(&monlock)) {
ast_log(LOG_WARNING, "Unable to lock monitor\n");
@@ -2620,17 +2619,13 @@
/* Wake up the thread */
pthread_kill(monitor_thread, SIGURG);
} else {
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
/* Start a new monitor */
- if (ast_pthread_create_background(&monitor_thread, &attr, do_monitor, NULL) < 0) {
+ if (ast_pthread_create_detached_background(&monitor_thread, NULL, do_monitor, NULL) < 0) {
monitor_thread = AST_PTHREADT_NULL;
ast_mutex_unlock(&monlock);
ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
- pthread_attr_destroy(&attr);
return -1;
}
- pthread_attr_destroy(&attr);
}
ast_mutex_unlock(&monlock);
return 0;
Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Thu May 24 13:30:19 2007
@@ -926,7 +926,6 @@
static struct iax2_thread *find_idle_thread(void)
{
- pthread_attr_t attr;
struct iax2_thread *thread = NULL;
/* Pop the head of the idle list off */
@@ -960,9 +959,7 @@
ast_cond_init(&thread->cond, NULL);
/* Create thread and send it on it's way */
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (ast_pthread_create_background(&thread->threadid, &attr, iax2_process_thread, thread)) {
+ if (ast_pthread_create_detached_background(&thread->threadid, NULL, iax2_process_thread, thread)) {
ast_cond_destroy(&thread->cond);
ast_mutex_destroy(&thread->lock);
free(thread);
@@ -6267,24 +6264,18 @@
{
pthread_t newthread;
struct dpreq_data *dpr;
- pthread_attr_t attr;
if (!(dpr = ast_calloc(1, sizeof(*dpr))))
return;
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
dpr->callno = callno;
ast_copy_string(dpr->context, context, sizeof(dpr->context));
ast_copy_string(dpr->callednum, callednum, sizeof(dpr->callednum));
if (callerid)
dpr->callerid = ast_strdup(callerid);
- if (ast_pthread_create(&newthread, &attr, dp_lookup_thread, dpr)) {
+ if (ast_pthread_create_detached(&newthread, NULL, dp_lookup_thread, dpr)) {
ast_log(LOG_WARNING, "Unable to start lookup thread!\n");
}
-
- pthread_attr_destroy(&attr);
}
struct iax_dual {
@@ -6352,18 +6343,11 @@
return -1;
}
if ((d = ast_calloc(1, sizeof(*d)))) {
- pthread_attr_t attr;
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
d->chan1 = chan1m;
d->chan2 = chan2m;
- if (!ast_pthread_create_background(&th, &attr, iax_park_thread, d)) {
- pthread_attr_destroy(&attr);
+ if (!ast_pthread_create_detached_background(&th, NULL, iax_park_thread, d)) {
return 0;
}
- pthread_attr_destroy(&attr);
free(d);
}
return -1;
@@ -8467,7 +8451,6 @@
static int start_network_thread(void)
{
- pthread_attr_t attr;
int threadcount = 0;
int x;
for (x = 0; x < iaxthreadcount; x++) {
@@ -8477,9 +8460,7 @@
thread->threadnum = ++threadcount;
ast_mutex_init(&thread->lock);
ast_cond_init(&thread->cond, NULL);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (ast_pthread_create(&thread->threadid, &attr, iax2_process_thread, thread)) {
+ if (ast_pthread_create_detached(&thread->threadid, NULL, iax2_process_thread, thread)) {
ast_log(LOG_WARNING, "Failed to create new thread!\n");
free(thread);
thread = NULL;
Modified: trunk/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_mgcp.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/channels/chan_mgcp.c (original)
+++ trunk/channels/chan_mgcp.c Thu May 24 13:30:19 2007
@@ -2956,9 +2956,6 @@
struct mgcp_endpoint *p = sub->parent;
struct ast_channel *c;
pthread_t t;
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
/* Off hook / answer */
if (sub->outgoing) {
@@ -3006,7 +3003,7 @@
}
c = mgcp_new(sub, AST_STATE_DOWN);
if (c) {
- if (ast_pthread_create(&t, &attr, mgcp_ss, c)) {
+ if (ast_pthread_create_detached(&t, NULL, mgcp_ss, c)) {
ast_log(LOG_WARNING, "Unable to create switch thread: %s\n", strerror(errno));
ast_hangup(c);
}
@@ -3034,7 +3031,6 @@
/*ast_queue_control(sub->owner, AST_CONTROL_ANSWER);*/
}
}
- pthread_attr_destroy(&attr);
}
static int handle_request(struct mgcp_subchannel *sub, struct mgcp_request *req, struct sockaddr_in *sin)
Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Thu May 24 13:30:19 2007
@@ -13640,24 +13640,18 @@
return -1;
}
if ((d = ast_calloc(1, sizeof(*d)))) {
- pthread_attr_t attr;
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
/* Save original request for followup */
copy_request(&d->req, req);
d->chan1 = transferee; /* Transferee */
d->chan2 = transferer; /* Transferer */
d->seqno = seqno;
- if (ast_pthread_create_background(&th, &attr, sip_park_thread, d) < 0) {
+ if (ast_pthread_create_detached_background(&th, NULL, sip_park_thread, d) < 0) {
/* Could not start thread */
free(d); /* We don't need it anymore. If thread is created, d will be free'd
by sip_park_thread() */
- pthread_attr_destroy(&attr);
return 0;
}
- pthread_attr_destroy(&attr);
}
return -1;
}
Modified: trunk/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_skinny.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/channels/chan_skinny.c (original)
+++ trunk/channels/chan_skinny.c Thu May 24 13:30:19 2007
@@ -4514,11 +4514,7 @@
struct skinnysession *s;
struct protoent *p;
int arg = 1;
- pthread_attr_t attr;
pthread_t tcp_thread;
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
for (;;) {
sinlen = sizeof(sin);
@@ -4544,14 +4540,13 @@
sessions = s;
ast_mutex_unlock(&sessionlock);
- if (ast_pthread_create(&tcp_thread, &attr, skinny_session, s)) {
+ if (ast_pthread_create_detached(&tcp_thread, NULL, skinny_session, s)) {
destroy_session(s);
}
}
if (skinnydebug)
ast_verbose("killing accept thread\n");
close(as);
- pthread_attr_destroy(&attr);
return 0;
}
Modified: trunk/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_zap.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/channels/chan_zap.c (original)
+++ trunk/channels/chan_zap.c Thu May 24 13:30:19 2007
@@ -3946,7 +3946,6 @@
char *c;
struct zt_pvt *p = ast->tech_pvt;
pthread_t threadid;
- pthread_attr_t attr;
struct ast_channel *chan;
struct ast_frame *f;
@@ -4549,11 +4548,9 @@
if (res)
ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel);
p->owner = chan;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (!chan) {
ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", p->channel);
- } else if (ast_pthread_create(&threadid, &attr, ss_thread, chan)) {
+ } else if (ast_pthread_create_detached(&threadid, NULL, 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);
@@ -4569,7 +4566,6 @@
}
p->subs[SUB_THREEWAY].needhold = 1;
}
- pthread_attr_destroy(&attr);
}
} else {
/* Already have a 3 way call */
@@ -6941,8 +6937,7 @@
pthread_t threadid;
pthread_attr_t attr;
struct ast_channel *chan;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
/* Handle an event on a given channel for the monitor thread. */
switch (event) {
case ZT_EVENT_NONE:
@@ -6986,7 +6981,7 @@
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 (ast_pthread_create(&threadid, &attr, ss_thread, chan)) {
+ if (ast_pthread_create_detached(&threadid, NULL, 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)
@@ -7133,7 +7128,6 @@
zap_destroy_channel_bynum(i->channel);
break;
}
- pthread_attr_destroy(&attr);
return 0;
}
@@ -7332,9 +7326,6 @@
static int restart_monitor(void)
{
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
/* If we're supposed to be stopped -- stay stopped */
if (monitor_thread == AST_PTHREADT_STOP)
return 0;
@@ -7349,15 +7340,13 @@
pthread_kill(monitor_thread, SIGURG);
} else {
/* Start a new monitor */
- if (ast_pthread_create_background(&monitor_thread, &attr, do_monitor, NULL) < 0) {
+ if (ast_pthread_create_detached_background(&monitor_thread, NULL, do_monitor, NULL) < 0) {
ast_mutex_unlock(&monlock);
ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
- pthread_attr_destroy(&attr);
return -1;
}
}
ast_mutex_unlock(&monlock);
- pthread_attr_destroy(&attr);
return 0;
}
@@ -8521,14 +8510,10 @@
ss7_event *e = NULL;
struct zt_pvt *p;
int chanpos;
- pthread_attr_t attr;
struct pollfd pollers[NUM_DCHANS];
int cic;
unsigned int dpc;
int nextms = 0;
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
ss7_start(ss7);
@@ -9300,7 +9285,6 @@
int cause=0;
struct zt_pvt *crv;
pthread_t threadid;
- pthread_attr_t attr;
char ani2str[6];
char plancallingnum[256];
char plancallingani[256];
@@ -9799,9 +9783,7 @@
pbx_builtin_setvar_helper(c, "PRIREDIRECTREASON", redirectingreason2str(e->ring.redirectingreason));
ast_mutex_lock(&pri->lock);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (c && !ast_pthread_create(&threadid, &attr, ss_thread, c)) {
+ if (c && !ast_pthread_create_detached(&threadid, NULL, 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",
plancallingnum, S_OR(pri->pvts[chanpos]->exten, "<unspecified>"),
@@ -9816,7 +9798,6 @@
pri->pvts[chanpos]->call = NULL;
}
}
- pthread_attr_destroy(&attr);
} else {
ast_mutex_unlock(&pri->lock);
/* Release PRI lock while we create the channel */
Modified: trunk/include/asterisk/utils.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/utils.h?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/include/asterisk/utils.h (original)
+++ trunk/include/asterisk/utils.h Thu May 24 13:30:19 2007
@@ -291,15 +291,28 @@
void *data, size_t stacksize, const char *file, const char *caller,
int line, const char *start_fn);
+int ast_pthread_create_detached_stack(pthread_t *thread, pthread_attr_t *attr, void*(*start_routine)(void *),
+ void *data, size_t stacksize, const char *file, const char *caller,
+ int line, const char *start_fn);
+
#define ast_pthread_create(a, b, c, d) ast_pthread_create_stack(a, b, c, d, \
0, \
__FILE__, __FUNCTION__, \
__LINE__, #c)
+#define ast_pthread_create_detached(a, b, c, d) ast_pthread_create_detached_stack(a, b, c, d, \
+ 0, \
+ __FILE__, __FUNCTION__, \
+ __LINE__, #c)
#define ast_pthread_create_background(a, b, c, d) ast_pthread_create_stack(a, b, c, d, \
AST_BACKGROUND_STACKSIZE, \
__FILE__, __FUNCTION__, \
__LINE__, #c)
+
+#define ast_pthread_create_detached_background(a, b, c, d) ast_pthread_create_detached_stack(a, b, c, d, \
+ AST_BACKGROUND_STACKSIZE, \
+ __FILE__, __FUNCTION__, \
+ __LINE__, #c)
/*!
\brief Process a string to find and replace characters
Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/main/asterisk.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Thu May 24 13:30:19 2007
@@ -932,9 +932,6 @@
int x;
int flags;
struct pollfd fds[1];
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
for (;;) {
if (ast_socket < 0)
return NULL;
@@ -966,7 +963,7 @@
fcntl(consoles[x].p[1], F_SETFL, flags | O_NONBLOCK);
consoles[x].fd = s;
consoles[x].mute = ast_opt_mute;
- if (ast_pthread_create_background(&consoles[x].t, &attr, netconsole, &consoles[x])) {
+ if (ast_pthread_create_detached_background(&consoles[x].t, NULL, netconsole, &consoles[x])) {
ast_log(LOG_ERROR, "Unable to spawn thread to handle connection: %s\n", strerror(errno));
close(consoles[x].p[0]);
close(consoles[x].p[1]);
@@ -3029,13 +3026,9 @@
/* Console stuff now... */
/* Register our quit function */
char title[256];
- pthread_attr_t attr;
pthread_t dont_care;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- ast_pthread_create(&dont_care, &attr, monitor_sig_flags, NULL);
- pthread_attr_destroy(&attr);
+ ast_pthread_create_detached(&dont_care, NULL, monitor_sig_flags, NULL);
set_icon("Asterisk");
snprintf(title, sizeof(title), "Asterisk Console on '%s' (pid %ld)", hostname, (long)ast_mainpid);
Modified: trunk/main/cdr.c
URL: http://svn.digium.com/view/asterisk/trunk/main/cdr.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/main/cdr.c (original)
+++ trunk/main/cdr.c Thu May 24 13:30:19 2007
@@ -1033,7 +1033,6 @@
void ast_cdr_submit_batch(int shutdown)
{
struct ast_cdr_batch_item *oldbatchitems = NULL;
- pthread_attr_t attr;
pthread_t batch_post_thread = AST_PTHREADT_NULL;
/* if there's no batch, or no CDRs in the batch, then there's nothing to do */
@@ -1053,16 +1052,13 @@
ast_log(LOG_DEBUG, "CDR single-threaded batch processing begins now\n");
do_batch_backend_process(oldbatchitems);
} else {
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (ast_pthread_create_background(&batch_post_thread, &attr, do_batch_backend_process, oldbatchitems)) {
+ if (ast_pthread_create_detached_background(&batch_post_thread, NULL, do_batch_backend_process, oldbatchitems)) {
ast_log(LOG_WARNING, "CDR processing thread could not detach, now trying in this thread\n");
do_batch_backend_process(oldbatchitems);
} else {
if (option_debug)
ast_log(LOG_DEBUG, "CDR multi-threaded batch processing begins now\n");
}
- pthread_attr_destroy(&attr);
}
}
Modified: trunk/main/http.c
URL: http://svn.digium.com/view/asterisk/trunk/main/http.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/main/http.c (original)
+++ trunk/main/http.c Thu May 24 13:30:19 2007
@@ -907,7 +907,6 @@
socklen_t sinlen;
struct server_instance *ser;
pthread_t launched;
- pthread_attr_t attr;
for (;;) {
int i, flags;
@@ -935,17 +934,13 @@
ser->fd = fd;
ser->parent = desc;
memcpy(&ser->requestor, &sin, sizeof(ser->requestor));
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (ast_pthread_create_background(&launched, &attr, make_file_from_fd, ser)) {
+ if (ast_pthread_create_detached_background(&launched, NULL, make_file_from_fd, ser)) {
ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
close(ser->fd);
free(ser);
}
- pthread_attr_destroy(&attr);
}
return NULL;
}
Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Thu May 24 13:30:19 2007
@@ -1933,7 +1933,6 @@
char tmp2[256];
pthread_t th;
- pthread_attr_t attr;
if (!name) {
astman_send_error(s, m, "Channel not specified");
return 0;
@@ -1988,14 +1987,11 @@
ast_copy_string(fast->account, account, sizeof(fast->account));
fast->timeout = to;
fast->priority = pi;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (ast_pthread_create(&th, &attr, fast_originate, fast)) {
+ if (ast_pthread_create_detached(&th, NULL, fast_originate, fast)) {
res = -1;
} else {
res = 0;
}
- pthread_attr_destroy(&attr);
}
} else if (!ast_strlen_zero(app)) {
res = ast_pbx_outgoing_app(tech, AST_FORMAT_SLINEAR, data, to, app, appdata, &reason, 1, l, n, vars, account, NULL);
Modified: trunk/main/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/main/pbx.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Thu May 24 13:30:19 2007
@@ -2551,7 +2551,6 @@
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
{
pthread_t t;
- pthread_attr_t attr;
if (!c) {
ast_log(LOG_WARNING, "Asked to start thread on NULL channel?\n");
@@ -2562,14 +2561,10 @@
return AST_PBX_CALL_LIMIT;
/* Start a new thread, and get something handling this channel. */
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (ast_pthread_create(&t, &attr, pbx_thread, c)) {
+ if (ast_pthread_create_detached(&t, NULL, pbx_thread, c)) {
ast_log(LOG_WARNING, "Failed to create new channel thread\n");
- pthread_attr_destroy(&attr);
return AST_PBX_FAILED;
}
- pthread_attr_destroy(&attr);
return AST_PBX_SUCCESS;
}
@@ -4999,7 +4994,6 @@
struct async_stat *as;
int res = -1, cdr_res = -1;
struct outgoing_helper oh;
- pthread_attr_t attr;
if (sync) {
oh.context = context;
@@ -5111,9 +5105,7 @@
ast_set_variables(chan, vars);
if (account)
ast_cdr_setaccount(chan, account);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (ast_pthread_create(&as->p, &attr, async_wait, as)) {
+ if (ast_pthread_create_detached(&as->p, NULL, async_wait, as)) {
ast_log(LOG_WARNING, "Failed to start async wait\n");
free(as);
if (channel) {
@@ -5122,10 +5114,8 @@
}
ast_hangup(chan);
res = -1;
- pthread_attr_destroy(&attr);
goto outgoing_exten_cleanup;
}
- pthread_attr_destroy(&attr);
res = 0;
}
outgoing_exten_cleanup:
@@ -5163,7 +5153,6 @@
struct app_tmp *tmp;
int res = -1, cdr_res = -1;
struct outgoing_helper oh;
- pthread_attr_t attr;
memset(&oh, 0, sizeof(oh));
oh.vars = vars;
@@ -5212,11 +5201,9 @@
ast_channel_unlock(chan);
ast_pbx_run_app(tmp);
} else {
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (locked_channel)
ast_channel_lock(chan);
- if (ast_pthread_create(&tmp->t, &attr, ast_pbx_run_app, tmp)) {
+ if (ast_pthread_create_detached(&tmp->t, NULL, ast_pbx_run_app, tmp)) {
ast_log(LOG_WARNING, "Unable to spawn execute thread on %s: %s\n", chan->name, strerror(errno));
free(tmp);
if (locked_channel)
@@ -5227,7 +5214,6 @@
if (locked_channel)
*locked_channel = chan;
}
- pthread_attr_destroy(&attr);
}
}
} else {
@@ -5275,24 +5261,20 @@
if (account)
ast_cdr_setaccount(chan, account);
/* Start a new thread, and get something handling this channel. */
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (locked_channel)
ast_channel_lock(chan);
- if (ast_pthread_create(&as->p, &attr, async_wait, as)) {
+ if (ast_pthread_create_detached(&as->p, NULL, async_wait, as)) {
ast_log(LOG_WARNING, "Failed to start async wait\n");
free(as);
if (locked_channel)
ast_channel_unlock(chan);
ast_hangup(chan);
res = -1;
- pthread_attr_destroy(&attr);
goto outgoing_app_cleanup;
} else {
if (locked_channel)
*locked_channel = chan;
}
- pthread_attr_destroy(&attr);
res = 0;
}
outgoing_app_cleanup:
Modified: trunk/main/utils.c
URL: http://svn.digium.com/view/asterisk/trunk/main/utils.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Thu May 24 13:30:19 2007
@@ -595,6 +595,32 @@
return pthread_create(thread, attr, start_routine, data); /* We're in ast_pthread_create, so it's okay */
}
+
+int ast_pthread_create_detached_stack(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *),
+ void *data, size_t stacksize, const char *file, const char *caller,
+ int line, const char *start_fn)
+{
+ unsigned char attr_destroy = 0;
+ int res;
+
+ if (!attr) {
+ attr = alloca(sizeof(*attr));
+ pthread_attr_init(attr);
+ attr_destroy = 1;
+ }
+
+ if ((errno = pthread_attr_setdetachstate(attr, PTHREAD_CREATE_DETACHED)))
+ ast_log(LOG_WARNING, "pthread_attr_setdetachstate: %s\n", strerror(errno));
+
+ res = ast_pthread_create_stack(thread, attr, start_routine, data,
+ stacksize, file, caller, line, start_fn);
+
+ if (attr_destroy)
+ pthread_attr_destroy(attr);
+
+ return res;
+}
+
int ast_wait_for_input(int fd, int ms)
{
struct pollfd pfd[1];
Modified: trunk/pbx/pbx_dundi.c
URL: http://svn.digium.com/view/asterisk/trunk/pbx/pbx_dundi.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/pbx/pbx_dundi.c (original)
+++ trunk/pbx/pbx_dundi.c Thu May 24 13:30:19 2007
@@ -771,7 +771,7 @@
char eid_str[20];
char *s;
pthread_t lookupthread;
- pthread_attr_t attr;
+
if (ies->eidcount > 1) {
/* Since it is a requirement that the first EID is the authenticating host
and the last EID is the root, it is permissible that the first and last EID
@@ -798,20 +798,17 @@
}
if (option_debug)
ast_log(LOG_DEBUG, "Answering EID query for '%s@%s'!\n", dundi_eid_to_str(eid_str, sizeof(eid_str), ies->reqeid), ies->called_context);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
trans->thread = 1;
- if (ast_pthread_create(&lookupthread, &attr, dundi_query_thread, st)) {
+ if (ast_pthread_create_detached(&lookupthread, NULL, dundi_query_thread, st)) {
trans->thread = 0;
ast_log(LOG_WARNING, "Unable to create thread!\n");
free(st);
memset(&ied, 0, sizeof(ied));
dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Out of threads");
dundi_send(trans, DUNDI_COMMAND_EIDRESPONSE, 0, 1, &ied);
- pthread_attr_destroy(&attr);
return -1;
}
- pthread_attr_destroy(&attr);
} else {
ast_log(LOG_WARNING, "Out of memory!\n");
memset(&ied, 0, sizeof(ied));
@@ -916,7 +913,6 @@
int skipfirst = 0;
pthread_t lookupthread;
- pthread_attr_t attr;
memset(&dr2, 0, sizeof(dr2));
memset(&dr, 0, sizeof(dr));
@@ -1029,20 +1025,16 @@
st->nummaps = mapcount;
if (option_debug)
ast_log(LOG_DEBUG, "Forwarding precache for '%s@%s'!\n", ies->called_number, ies->called_context);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
trans->thread = 1;
- if (ast_pthread_create(&lookupthread, &attr, dundi_precache_thread, st)) {
+ if (ast_pthread_create_detached(&lookupthread, NULL, dundi_precache_thread, st)) {
trans->thread = 0;
ast_log(LOG_WARNING, "Unable to create thread!\n");
free(st);
memset(&ied, 0, sizeof(ied));
dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Out of threads");
dundi_send(trans, DUNDI_COMMAND_PRECACHERP, 0, 1, &ied);
- pthread_attr_destroy(&attr);
return -1;
}
- pthread_attr_destroy(&attr);
} else {
ast_log(LOG_WARNING, "Out of memory!\n");
memset(&ied, 0, sizeof(ied));
@@ -1065,7 +1057,6 @@
int skipfirst = 0;
pthread_t lookupthread;
- pthread_attr_t attr;
totallen = sizeof(struct dundi_query_state);
/* Count matching map entries */
AST_LIST_TRAVERSE(&mappings, cur, list) {
@@ -1118,20 +1109,16 @@
st->nummaps = mapcount;
if (option_debug)
ast_log(LOG_DEBUG, "Answering query for '%s@%s'!\n", ies->called_number, ies->called_context);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
trans->thread = 1;
- if (ast_pthread_create(&lookupthread, &attr, dundi_lookup_thread, st)) {
+ if (ast_pthread_create_detached(&lookupthread, NULL, dundi_lookup_thread, st)) {
trans->thread = 0;
ast_log(LOG_WARNING, "Unable to create thread!\n");
free(st);
memset(&ied, 0, sizeof(ied));
dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Out of threads");
dundi_send(trans, DUNDI_COMMAND_DPRESPONSE, 0, 1, &ied);
- pthread_attr_destroy(&attr);
return -1;
}
- pthread_attr_destroy(&attr);
} else {
ast_log(LOG_WARNING, "Out of memory!\n");
memset(&ied, 0, sizeof(ied));
Modified: trunk/pbx/pbx_spool.c
URL: http://svn.digium.com/view/asterisk/trunk/pbx/pbx_spool.c?view=diff&rev=65968&r1=65967&r2=65968
==============================================================================
--- trunk/pbx/pbx_spool.c (original)
+++ trunk/pbx/pbx_spool.c Thu May 24 13:30:19 2007
@@ -359,15 +359,12 @@
static void launch_service(struct outgoing *o)
{
pthread_t t;
- pthread_attr_t attr;
int ret;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if ((ret = ast_pthread_create(&t,&attr,attempt_thread, o)) != 0) {
+
+ if ((ret = ast_pthread_create_detached(&t, NULL, attempt_thread, o))) {
ast_log(LOG_WARNING, "Unable to create thread :( (returned error: %d)\n", ret);
free_outgoing(o);
}
- pthread_attr_destroy(&attr);
}
static int scan_service(char *fn, time_t now, time_t atime)
@@ -486,7 +483,6 @@
static int load_module(void)
{
pthread_t thread;
- pthread_attr_t attr;
int ret;
snprintf(qdir, sizeof(qdir), "%s/%s", ast_config_AST_SPOOL_DIR, "outgoing");
if (mkdir(qdir, 0700) && (errno != EEXIST)) {
@@ -494,13 +490,12 @@
return 0;
}
snprintf(qdonedir, sizeof(qdir), "%s/%s", ast_config_AST_SPOOL_DIR, "outgoing_done");
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if ((ret = ast_pthread_create_background(&thread,&attr,scan_thread, NULL)) != 0) {
+
+ if ((ret = ast_pthread_create_detached_background(&thread, NULL, scan_thread, NULL))) {
ast_log(LOG_WARNING, "Unable to create thread :( (returned error: %d)\n", ret);
return -1;
}
- pthread_attr_destroy(&attr);
+
return 0;
}
More information about the asterisk-commits
mailing list