[asterisk-commits] kpfleming: trunk r44379 - in /trunk: ./ apps/ channels/ include/asterisk/ mai...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Oct 4 12:51:39 MST 2006


Author: kpfleming
Date: Wed Oct  4 14:51:38 2006
New Revision: 44379

URL: http://svn.digium.com/view/asterisk?rev=44379&view=rev
Log:
Merged revisions 44378 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r44378 | kpfleming | 2006-10-04 14:47:22 -0500 (Wed, 04 Oct 2006) | 4 lines

update thread creation code a bit
reduce standard thread stack size slightly to allow the pthreads library to allocate the stack+data and not overflow a power-of-2 allocation in the kernel and waste memory/address space
add a new stack size for 'background' threads (those that don't handle PBX calls) when LOW_MEMORY is defined

........

Modified:
    trunk/   (props changed)
    trunk/apps/app_meetme.c
    trunk/apps/app_mixmonitor.c
    trunk/apps/app_queue.c
    trunk/channels/chan_alsa.c
    trunk/channels/chan_h323.c
    trunk/channels/chan_iax2.c
    trunk/channels/chan_mgcp.c
    trunk/channels/chan_oss.c
    trunk/channels/chan_phone.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/autoservice.c
    trunk/main/cdr.c
    trunk/main/devicestate.c
    trunk/main/dnsmgr.c
    trunk/main/http.c
    trunk/main/manager.c
    trunk/main/utils.c
    trunk/pbx/pbx_dundi.c
    trunk/pbx/pbx_spool.c
    trunk/res/res_jabber.c
    trunk/res/res_musiconhold.c
    trunk/res/res_smdi.c
    trunk/res/res_snmp.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_meetme.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/apps/app_meetme.c (original)
+++ trunk/apps/app_meetme.c Wed Oct  4 14:51:38 2006
@@ -1080,7 +1080,7 @@
 	if ((conf->recording == MEETME_RECORD_OFF) && ((confflags & CONFFLAG_RECORDCONF) || (conf->lchan))) {
 		pthread_attr_init(&conf->attr);
 		pthread_attr_setdetachstate(&conf->attr, PTHREAD_CREATE_DETACHED);
-		ast_pthread_create(&conf->recordthread, &conf->attr, recordthread, conf);
+		ast_pthread_create_background(&conf->recordthread, &conf->attr, recordthread, conf);
 	}
 
 	time(&user->jointime);

Modified: trunk/apps/app_mixmonitor.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_mixmonitor.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/apps/app_mixmonitor.c (original)
+++ trunk/apps/app_mixmonitor.c Wed Oct  4 14:51:38 2006
@@ -292,7 +292,7 @@
 
 	pthread_attr_init(&attr);
 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-	ast_pthread_create(&thread, &attr, mixmonitor_thread, mixmonitor);
+	ast_pthread_create_background(&thread, &attr, mixmonitor_thread, mixmonitor);
 	pthread_attr_destroy(&attr);
 
 }

Modified: trunk/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_queue.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/apps/app_queue.c (original)
+++ trunk/apps/app_queue.c Wed Oct  4 14:51:38 2006
@@ -596,7 +596,7 @@
 	strcpy(sc->dev, dev);
 	pthread_attr_init(&attr);
 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-	if (ast_pthread_create(&t, &attr, changethread, sc)) {
+	if (ast_pthread_create_background(&t, &attr, changethread, sc)) {
 		ast_log(LOG_WARNING, "Failed to create update thread!\n");
 		free(sc);
 	}

Modified: trunk/channels/chan_alsa.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_alsa.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/channels/chan_alsa.c (original)
+++ trunk/channels/chan_alsa.c Wed Oct  4 14:51:38 2006
@@ -1151,7 +1151,7 @@
 
 	ast_cli_register_multiple(cli_alsa, sizeof(cli_alsa) / sizeof(struct ast_cli_entry));
 
-	ast_pthread_create(&sthread, NULL, sound_thread, NULL);
+	ast_pthread_create_background(&sthread, NULL, sound_thread, NULL);
 #ifdef ALSA_MONITOR
 	if (alsa_monitor_start())
 		ast_log(LOG_ERROR, "Problem starting Monitoring\n");

Modified: trunk/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_h323.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/channels/chan_h323.c (original)
+++ trunk/channels/chan_h323.c Wed Oct  4 14:51:38 2006
@@ -2590,7 +2590,7 @@
 		pthread_attr_init(&attr);
 		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 		/* Start a new monitor */
-		if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
+		if (ast_pthread_create_background(&monitor_thread, &attr, do_monitor, NULL) < 0) {
 			monitor_thread = AST_PTHREADT_NULL;
 			ast_mutex_unlock(&monlock);
 			ast_log(LOG_ERROR, "Unable to start monitor thread.\n");

Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Wed Oct  4 14:51:38 2006
@@ -6106,7 +6106,7 @@
 	if ((d = ast_calloc(1, sizeof(*d)))) {
 		d->chan1 = chan1m;
 		d->chan2 = chan2m;
-		if (!ast_pthread_create(&th, NULL, iax_park_thread, d))
+		if (!ast_pthread_create_background(&th, NULL, iax_park_thread, d))
 			return 0;
 		free(d);
 	}
@@ -8083,8 +8083,8 @@
 			AST_LIST_UNLOCK(&idle_list);
 		}
 	}
-	ast_pthread_create(&schedthreadid, NULL, sched_thread, NULL);
-	ast_pthread_create(&netthreadid, NULL, network_thread, NULL);
+	ast_pthread_create_background(&schedthreadid, NULL, sched_thread, NULL);
+	ast_pthread_create_background(&netthreadid, NULL, network_thread, NULL);
 	if (option_verbose > 1)
 		ast_verbose(VERBOSE_PREFIX_2 "%d helper threaads started\n", threadcount);
 	return 0;

Modified: trunk/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_mgcp.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/channels/chan_mgcp.c (original)
+++ trunk/channels/chan_mgcp.c Wed Oct  4 14:51:38 2006
@@ -3500,7 +3500,7 @@
 		pthread_kill(monitor_thread, SIGURG);
 	} else {
 		/* Start a new monitor */
-		if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
+		if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) {
 			ast_mutex_unlock(&monlock);
 			ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
 			return -1;

Modified: trunk/channels/chan_oss.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_oss.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/channels/chan_oss.c (original)
+++ trunk/channels/chan_oss.c Wed Oct  4 14:51:38 2006
@@ -1540,7 +1540,7 @@
 		ast_log(LOG_ERROR, "Unable to create pipe\n");
 		goto error;
 	}
-	ast_pthread_create(&o->sthread, NULL, sound_thread, o);
+	ast_pthread_create_background(&o->sthread, NULL, sound_thread, o);
 	/* link into list of devices */
 	if (o != &oss_default) {
 		o->next = oss_default.next;

Modified: trunk/channels/chan_phone.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_phone.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/channels/chan_phone.c (original)
+++ trunk/channels/chan_phone.c Wed Oct  4 14:51:38 2006
@@ -1157,7 +1157,7 @@
 	}
 	monitor = 1;
 	/* Start a new monitor */
-	if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
+	if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) {
 		ast_mutex_unlock(&monlock);
 		ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
 		return -1;

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Wed Oct  4 14:51:38 2006
@@ -12275,7 +12275,7 @@
 		d->chan1 = transferee;	/* Transferee */
 		d->chan2 = transferer;	/* Transferer */
 		d->seqno = seqno;
-		if (ast_pthread_create(&th, NULL, sip_park_thread, d) < 0) {
+		if (ast_pthread_create_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() */
@@ -14619,7 +14619,7 @@
 		pthread_kill(monitor_thread, SIGURG);
 	} else {
 		/* Start a new monitor */
-		if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
+		if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) {
 			ast_mutex_unlock(&monlock);
 			ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
 			return -1;

Modified: trunk/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_skinny.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/channels/chan_skinny.c (original)
+++ trunk/channels/chan_skinny.c Wed Oct  4 14:51:38 2006
@@ -4331,7 +4331,7 @@
 		pthread_kill(monitor_thread, SIGURG);
 	} else {
 		/* Start a new monitor */
-		if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
+		if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) {
 			ast_mutex_unlock(&monlock);
 			ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
 			return -1;
@@ -4512,7 +4512,7 @@
 			if (option_verbose > 1)
 				ast_verbose(VERBOSE_PREFIX_2 "Skinny listening on %s:%d\n",
 					ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port));
-			ast_pthread_create(&accept_t,NULL, accept_thread, NULL);
+			ast_pthread_create_background(&accept_t,NULL, accept_thread, NULL);
 		}
 	}
 	ast_mutex_unlock(&netlock);

Modified: trunk/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_zap.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/channels/chan_zap.c (original)
+++ trunk/channels/chan_zap.c Wed Oct  4 14:51:38 2006
@@ -7245,7 +7245,7 @@
 #endif
 	} else {
 		/* Start a new monitor */
-		if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
+		if (ast_pthread_create_background(&monitor_thread, &attr, do_monitor, NULL) < 0) {
 			ast_mutex_unlock(&monlock);
 			ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
 			return -1;
@@ -9156,7 +9156,7 @@
 					idle = zt_request("Zap", AST_FORMAT_ULAW, idlen, &cause);
 					if (idle) {
 						pri->pvts[nextidle]->isidlecall = 1;
-						if (ast_pthread_create(&p, NULL, do_idle_thread, idle)) {
+						if (ast_pthread_create_background(&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);
 						}
@@ -10192,7 +10192,7 @@
 	/* Assume primary is the one we use */
 	pri->pri = pri->dchans[0];
 	pri->resetpos = -1;
-	if (ast_pthread_create(&pri->master, NULL, pri_dchannel, pri)) {
+	if (ast_pthread_create_background(&pri->master, NULL, pri_dchannel, pri)) {
 		for (i = 0; i < NUM_DCHANS; i++) {
 			if (!pri->dchannels[i])
 				break;

Modified: trunk/include/asterisk/utils.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/utils.h?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/include/asterisk/utils.h (original)
+++ trunk/include/asterisk/utils.h Wed Oct  4 14:51:38 2006
@@ -246,15 +246,30 @@
 		|| (sin1->sin_port != sin2->sin_port));
 }
 
-#define AST_STACKSIZE 256 * 1024
+#define AST_STACKSIZE 240 * 1024
+
+#if defined(LOW_MEMORY)
+#define AST_BACKGROUND_STACKSIZE 48 * 1024
+#else
+#define AST_BACKGROUND_STACKSIZE 240 * 1024
+#endif
 
 void ast_register_thread(char *name);
 void ast_unregister_thread(void *id);
 
-#define ast_pthread_create(a,b,c,d) ast_pthread_create_stack(a,b,c,d,0, \
-	 __FILE__, __FUNCTION__, __LINE__, #c)
-int ast_pthread_create_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);
+int ast_pthread_create_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_background(a, b, c, d) ast_pthread_create_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?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Wed Oct  4 14:51:38 2006
@@ -300,7 +300,7 @@
 	if (!new)
 		return;
 	new->id = pthread_self();
-	new->name = name; /* this was a copy already */
+	new->name = name; /* steal the allocated memory for the thread name */
 	AST_LIST_LOCK(&thread_list);
 	AST_LIST_INSERT_HEAD(&thread_list, new, list);
 	AST_LIST_UNLOCK(&thread_list);
@@ -312,7 +312,7 @@
 
 	AST_LIST_LOCK(&thread_list);
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&thread_list, x, list) {
-		if ((void *)x->id == id) {
+		if ((void *) x->id == id) {
 			AST_LIST_REMOVE_CURRENT(&thread_list, list);
 			break;
 		}
@@ -859,7 +859,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(&consoles[x].t, &attr, netconsole, &consoles[x])) {
+					if (ast_pthread_create_background(&consoles[x].t, &attr, 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]);
@@ -917,7 +917,7 @@
 		return -1;
 	}
 	ast_register_verbose(network_verboser);
-	ast_pthread_create(&lthread, NULL, listener, NULL);
+	ast_pthread_create_background(&lthread, NULL, listener, NULL);
 
 	if (!ast_strlen_zero(ast_config_AST_CTL_OWNER)) {
 		struct passwd *pw;

Modified: trunk/main/autoservice.c
URL: http://svn.digium.com/view/asterisk/trunk/main/autoservice.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/main/autoservice.c (original)
+++ trunk/main/autoservice.c Wed Oct  4 14:51:38 2006
@@ -111,7 +111,7 @@
 		AST_LIST_INSERT_HEAD(&aslist, as, list);
 		res = 0;
 		if (asthread == AST_PTHREADT_NULL) { /* need start the thread */
-			if (ast_pthread_create(&asthread, NULL, autoservice_run, NULL)) {
+			if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) {
 				ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
 				/* There will only be a single member in the list at this point,
 				   the one we just added. */

Modified: trunk/main/cdr.c
URL: http://svn.digium.com/view/asterisk/trunk/main/cdr.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/main/cdr.c (original)
+++ trunk/main/cdr.c Wed Oct  4 14:51:38 2006
@@ -853,7 +853,7 @@
 	} else {
 		pthread_attr_init(&attr);
 		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-		if (ast_pthread_create(&batch_post_thread, &attr, do_batch_backend_process, oldbatchitems)) {
+		if (ast_pthread_create_background(&batch_post_thread, &attr, 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 {
@@ -1101,7 +1101,7 @@
 	   if it does not exist */
 	if (enabled && batchmode && (!was_enabled || !was_batchmode) && (cdr_thread == AST_PTHREADT_NULL)) {
 		ast_cond_init(&cdr_pending_cond, NULL);
-		if (ast_pthread_create(&cdr_thread, NULL, do_cdr, NULL) < 0) {
+		if (ast_pthread_create_background(&cdr_thread, NULL, do_cdr, NULL) < 0) {
 			ast_log(LOG_ERROR, "Unable to start CDR thread.\n");
 			ast_sched_del(sched, cdr_sched);
 		} else {

Modified: trunk/main/devicestate.c
URL: http://svn.digium.com/view/asterisk/trunk/main/devicestate.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/main/devicestate.c (original)
+++ trunk/main/devicestate.c Wed Oct  4 14:51:38 2006
@@ -374,7 +374,7 @@
 int ast_device_state_engine_init(void)
 {
 	ast_cond_init(&change_pending, NULL);
-	if (ast_pthread_create(&change_thread, NULL, do_devstate_changes, NULL) < 0) {
+	if (ast_pthread_create_background(&change_thread, NULL, do_devstate_changes, NULL) < 0) {
 		ast_log(LOG_ERROR, "Unable to start device state change thread.\n");
 		return -1;
 	}

Modified: trunk/main/dnsmgr.c
URL: http://svn.digium.com/view/asterisk/trunk/main/dnsmgr.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/main/dnsmgr.c (original)
+++ trunk/main/dnsmgr.c Wed Oct  4 14:51:38 2006
@@ -390,7 +390,7 @@
 	/* if this reload enabled the manager, create the background thread
 	   if it does not exist */
 	if (enabled && !was_enabled && (refresh_thread == AST_PTHREADT_NULL)) {
-		if (ast_pthread_create(&refresh_thread, NULL, do_refresh, NULL) < 0) {
+		if (ast_pthread_create_background(&refresh_thread, NULL, do_refresh, NULL) < 0) {
 			ast_log(LOG_ERROR, "Unable to start refresh thread.\n");
 		}
 		else {

Modified: trunk/main/http.c
URL: http://svn.digium.com/view/asterisk/trunk/main/http.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/main/http.c (original)
+++ trunk/main/http.c Wed Oct  4 14:51:38 2006
@@ -510,7 +510,7 @@
 				pthread_attr_init(&attr);
 				pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 				
-				if (ast_pthread_create(&launched, &attr, ast_httpd_helper_thread, ser)) {
+				if (ast_pthread_create_background(&launched, &attr, ast_httpd_helper_thread, ser)) {
 					ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
 					fclose(ser->f);
 					free(ser);
@@ -589,7 +589,7 @@
 	}
 	flags = fcntl(httpfd, F_GETFL);
 	fcntl(httpfd, F_SETFL, flags | O_NONBLOCK);
-	if (ast_pthread_create(&master, NULL, http_root, NULL)) {
+	if (ast_pthread_create_background(&master, NULL, http_root, NULL)) {
 		ast_log(LOG_NOTICE, "Unable to launch http server on %s:%d: %s\n",
 				ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port),
 				strerror(errno));

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Wed Oct  4 14:51:38 2006
@@ -2170,7 +2170,7 @@
 			s->eventq = s->eventq->next;
 		AST_LIST_UNLOCK(&sessions);
 		ast_atomic_fetchadd_int(&s->eventq->usecount, 1);
-		if (ast_pthread_create(&s->t, &attr, session_do, s))
+		if (ast_pthread_create_background(&s->t, &attr, session_do, s))
 			destroy_session(s);
 	}
 	pthread_attr_destroy(&attr);
@@ -2785,7 +2785,7 @@
 		fcntl(asock, F_SETFL, flags | O_NONBLOCK);
 		if (option_verbose)
 			ast_verbose("Asterisk Management interface listening on port %d\n", portno);
-		ast_pthread_create(&t, NULL, accept_thread, NULL);
+		ast_pthread_create_background(&t, NULL, accept_thread, NULL);
 	}
 	return 0;
 }

Modified: trunk/main/utils.c
URL: http://svn.digium.com/view/asterisk/trunk/main/utils.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Wed Oct  4 14:51:38 2006
@@ -525,31 +525,38 @@
  * are odd macros which start and end a block, so they _must_ be
  * used in pairs (the latter with a '1' argument to call the
  * handler on exit.
- * On BSD we don't need this, but we keep it for compatibility with the MAC.
+ * On BSD we don't need this, but we keep it for compatibility.
  */
 static void *dummy_start(void *data)
 {
 	void *ret;
-	struct thr_arg a = *((struct thr_arg *)data);	/* make a local copy */
-
+	struct thr_arg a = *((struct thr_arg *) data);	/* make a local copy */
+
+	/* note that even though data->name is a pointer to allocated memory,
+	   we are not freeing it here because ast_register_thread is going to
+	   keep a copy of the pointer and then ast_unregister_thread will
+	   free the memory
+	*/
 	free(data);
 	ast_register_thread(a.name);
-	pthread_cleanup_push(ast_unregister_thread, (void *)pthread_self());	/* on unregister */
+	pthread_cleanup_push(ast_unregister_thread, (void *) pthread_self());
 	ret = a.start_routine(a.data);
 	pthread_cleanup_pop(1);
+
 	return ret;
 }
 
-int ast_pthread_create_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)
+int ast_pthread_create_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)
 {
 	struct thr_arg *a;
 
-	pthread_attr_t lattr;
 	if (!attr) {
-		pthread_attr_init(&lattr);
-		attr = &lattr;
-	}
+		attr = alloca(sizeof(*attr));
+		pthread_attr_init(attr);
+	}
+
 #ifdef __linux__
 	/* On Linux, pthread_attr_init() defaults to PTHREAD_EXPLICIT_SCHED,
 	   which is kind of useless. Change this here to
@@ -558,27 +565,25 @@
 	   This does mean that callers cannot set a different priority using
 	   PTHREAD_EXPLICIT_SCHED in the attr argument; instead they must set
 	   the priority afterwards with pthread_setschedparam(). */
-	errno = pthread_attr_setinheritsched(attr, PTHREAD_INHERIT_SCHED);
-	if (errno)
-		ast_log(LOG_WARNING, "pthread_attr_setinheritsched returned non-zero: %s\n", strerror(errno));
+	if ((errno = pthread_attr_setinheritsched(attr, PTHREAD_INHERIT_SCHED)))
+		ast_log(LOG_WARNING, "pthread_attr_setinheritsched: %s\n", strerror(errno));
 #endif
 
 	if (!stacksize)
 		stacksize = AST_STACKSIZE;
-	errno = pthread_attr_setstacksize(attr, stacksize);
-	if (errno)
-		ast_log(LOG_WARNING, "pthread_attr_setstacksize returned non-zero: %s\n", strerror(errno));
-	a = ast_malloc(sizeof(*a));
-	if (!a)
-		ast_log(LOG_WARNING, "no memory, thread %s will not be listed\n", start_fn);
-	else {	/* remap parameters */
+
+	if ((errno = pthread_attr_setstacksize(attr, stacksize ? stacksize : AST_STACKSIZE)))
+		ast_log(LOG_WARNING, "pthread_attr_setstacksize: %s\n", strerror(errno));
+
+	if ((a = ast_malloc(sizeof(*a)))) {
 		a->start_routine = start_routine;
 		a->data = data;
 		start_routine = dummy_start;
 		asprintf(&a->name, "%-20s started at [%5d] %s %s()",
-			start_fn, line, file, caller);
+			 start_fn, line, file, caller);
 		data = a;
 	}
+
 	return pthread_create(thread, attr, start_routine, data); /* We're in ast_pthread_create, so it's okay */
 }
 

Modified: trunk/pbx/pbx_dundi.c
URL: http://svn.digium.com/view/asterisk/trunk/pbx/pbx_dundi.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/pbx/pbx_dundi.c (original)
+++ trunk/pbx/pbx_dundi.c Wed Oct  4 14:51:38 2006
@@ -2151,8 +2151,8 @@
 
 static int start_network_thread(void)
 {
-	ast_pthread_create(&netthreadid, NULL, network_thread, NULL);
-	ast_pthread_create(&precachethreadid, NULL, process_precache, NULL);
+	ast_pthread_create_background(&netthreadid, NULL, network_thread, NULL);
+	ast_pthread_create_background(&precachethreadid, NULL, process_precache, NULL);
 	return 0;
 }
 

Modified: trunk/pbx/pbx_spool.c
URL: http://svn.digium.com/view/asterisk/trunk/pbx/pbx_spool.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/pbx/pbx_spool.c (original)
+++ trunk/pbx/pbx_spool.c Wed Oct  4 14:51:38 2006
@@ -495,7 +495,7 @@
 	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(&thread,&attr,scan_thread, NULL)) != 0) {
+	if ((ret = ast_pthread_create_background(&thread,&attr,scan_thread, NULL)) != 0) {
 		ast_log(LOG_WARNING, "Unable to create thread :( (returned error: %d)\n", ret);
 		return -1;
 	}

Modified: trunk/res/res_jabber.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_jabber.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/res/res_jabber.c (original)
+++ trunk/res/res_jabber.c Wed Oct  4 14:51:38 2006
@@ -2368,7 +2368,7 @@
 		ASTOBJ_RDLOCK(iterator);
 		if(iterator->state == AJI_DISCONNECTED) {
 			if (!iterator->thread)
-				ast_pthread_create(&iterator->thread, NULL, aji_recv_loop, iterator);
+				ast_pthread_create_background(&iterator->thread, NULL, aji_recv_loop, iterator);
 		} else if (iterator->state == AJI_CONNECTING)
 			aji_get_roster(iterator);
 		ASTOBJ_UNLOCK(iterator);

Modified: trunk/res/res_musiconhold.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_musiconhold.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/res/res_musiconhold.c (original)
+++ trunk/res/res_musiconhold.c Wed Oct  4 14:51:38 2006
@@ -867,7 +867,7 @@
 #else
 		moh->pseudofd = -1;
 #endif
-		if (ast_pthread_create(&moh->thread, NULL, monmp3thread, moh)) {
+		if (ast_pthread_create_background(&moh->thread, NULL, monmp3thread, moh)) {
 			ast_log(LOG_WARNING, "Unable to create moh...\n");
 			if (moh->pseudofd > -1)
 				close(moh->pseudofd);

Modified: trunk/res/res_smdi.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_smdi.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/res/res_smdi.c (original)
+++ trunk/res/res_smdi.c Wed Oct  4 14:51:38 2006
@@ -682,7 +682,7 @@
                         /* start the listner thread */
 			if (option_verbose > 2)
 				ast_verbose(VERBOSE_PREFIX_3 "Starting SMDI monitor thread for %s\n", iface->name);
-			if (ast_pthread_create(&iface->thread, NULL, smdi_read, iface)) {
+			if (ast_pthread_create_background(&iface->thread, NULL, smdi_read, iface)) {
 				ast_log(LOG_ERROR, "Error starting SMDI monitor thread for %s\n", iface->name);
 				ASTOBJ_UNREF(iface, ast_smdi_interface_destroy);
 				continue;

Modified: trunk/res/res_snmp.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_snmp.c?rev=44379&r1=44378&r2=44379&view=diff
==============================================================================
--- trunk/res/res_snmp.c (original)
+++ trunk/res/res_snmp.c Wed Oct  4 14:51:38 2006
@@ -96,7 +96,7 @@
 
 	res_snmp_dont_stop = 1;
 	if (res_snmp_enabled)
-		return ast_pthread_create(&thread, NULL, agent_thread, NULL);
+		return ast_pthread_create_background(&thread, NULL, agent_thread, NULL);
 	else
 		return 0;
 }
@@ -121,7 +121,7 @@
 
 	res_snmp_dont_stop = 1;
 	if (res_snmp_enabled)
-		return ast_pthread_create(&thread, NULL, agent_thread, NULL);
+		return ast_pthread_create_background(&thread, NULL, agent_thread, NULL);
 	else
 		return 0;
 }



More information about the asterisk-commits mailing list