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);
}
}
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;
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:
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,
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);
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] = "";
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);
}
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) {
}
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 */
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,
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;
}
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) {
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;
}
}
static void *rpt_master(void *config)
{
int i, n;
- pthread_attr_t attr;
struct ast_config *cfg;
char *this;
const char *val;
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 (;;) {
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);
}
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");
/* 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;
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 */
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);
{
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 {
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;
static int start_network_thread(void)
{
- pthread_attr_t attr;
int threadcount = 0;
int x;
for (x = 0; x < iaxthreadcount; x++) {
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;
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) {
}
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);
}
/*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)
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;
}
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);
as = accept(skinnysock, (struct sockaddr *)&sin, &sinlen);
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;
}
char *c;
struct zt_pvt *p = ast->tech_pvt;
pthread_t threadid;
- pthread_attr_t attr;
struct ast_channel *chan;
struct ast_frame *f;
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);
}
p->subs[SUB_THREEWAY].needhold = 1;
}
- pthread_attr_destroy(&attr);
}
} else {
/* Already have a 3 way call */
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:
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)
zap_destroy_channel_bynum(i->channel);
break;
}
- pthread_attr_destroy(&attr);
return 0;
}
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;
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;
}
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);
while(1) {
int cause=0;
struct zt_pvt *crv;
pthread_t threadid;
- pthread_attr_t attr;
char ani2str[6];
char plancallingnum[256];
char plancallingani[256];
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>"),
pri->pvts[chanpos]->call = NULL;
}
}
- pthread_attr_destroy(&attr);
} else {
ast_mutex_unlock(&pri->lock);
/* Release PRI lock while we create the channel */
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
\param start The string to analyze
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;
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]);
/* 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);
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 */
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);
}
}
socklen_t sinlen;
struct server_instance *ser;
pthread_t launched;
- pthread_attr_t attr;
for (;;) {
int i, flags;
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;
}
char tmp2[256];
pthread_t th;
- pthread_attr_t attr;
if (!name) {
astman_send_error(s, m, "Channel not specified");
return 0;
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);
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");
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;
}
struct async_stat *as;
int res = -1, cdr_res = -1;
struct outgoing_helper oh;
- pthread_attr_t attr;
if (sync) {
oh.context = context;
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) {
}
ast_hangup(chan);
res = -1;
- pthread_attr_destroy(&attr);
goto outgoing_exten_cleanup;
}
- pthread_attr_destroy(&attr);
res = 0;
}
outgoing_exten_cleanup:
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;
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)
if (locked_channel)
*locked_channel = chan;
}
- pthread_attr_destroy(&attr);
}
}
} else {
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:
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];
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
}
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));
int skipfirst = 0;
pthread_t lookupthread;
- pthread_attr_t attr;
memset(&dr2, 0, sizeof(dr2));
memset(&dr, 0, sizeof(dr));
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));
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) {
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));
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)
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)) {
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;
}