[asterisk-commits] wedhorn: trunk r322381 - /trunk/channels/chan_skinny.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jun 8 06:39:03 CDT 2011


Author: wedhorn
Date: Wed Jun  8 06:38:56 2011
New Revision: 322381

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=322381
Log:
Remove skinny do_monitor and use ast_sched_start instead

The do_monitor seemed to be there for task scheduling and network monitoring. However, the network monitoring has a dedicated thread so the ast_io_wait was basically just a usleep as it didn't actually seem to be monitoring anything.

Review: https://reviewboard.asterisk.org/r/1256/

Modified:
    trunk/channels/chan_skinny.c

Modified: trunk/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_skinny.c?view=diff&rev=322381&r1=322380&r2=322381
==============================================================================
--- trunk/channels/chan_skinny.c (original)
+++ trunk/channels/chan_skinny.c Wed Jun  8 06:38:56 2011
@@ -1164,17 +1164,9 @@
 
 /* driver scheduler */
 static struct ast_sched_context *sched = NULL;
-static struct io_context *io;
-
-/* Protect the monitoring thread, so only one process can kill or start it, and not
-   when it's doing something critical. */
-AST_MUTEX_DEFINE_STATIC(monlock);
+
 /* Protect the network socket */
 AST_MUTEX_DEFINE_STATIC(netlock);
-
-/* This is the thread for the monitor which checks for input on the channels
-   which are not currently in use. */
-static pthread_t monitor_thread = AST_PTHREADT_NULL;
 
 /* Wait up to 16 seconds for first digit */
 static int firstdigittimeout = 16000;
@@ -6499,59 +6491,6 @@
 	return 0;
 }
 
-static void *do_monitor(void *data)
-{
-	int res;
-
-	/* This thread monitors all the interfaces which are not yet in use
-	   (and thus do not have a separate thread) indefinitely */
-	/* From here on out, we die whenever asked */
-	for(;;) {
-		pthread_testcancel();
-		/* Wait for sched or io */
-		res = ast_sched_wait(sched);
-		if ((res < 0) || (res > 1000)) {
-			res = 1000;
-		}
-		res = ast_io_wait(io, res);
-		ast_mutex_lock(&monlock);
-		if (res >= 0) {
-			ast_sched_runq(sched);
-		}
-		ast_mutex_unlock(&monlock);
-	}
-	/* Never reached */
-	return NULL;
-
-}
-
-static int restart_monitor(void)
-{
-	/* If we're supposed to be stopped -- stay stopped */
-	if (monitor_thread == AST_PTHREADT_STOP)
-		return 0;
-
-	ast_mutex_lock(&monlock);
-	if (monitor_thread == pthread_self()) {
-		ast_mutex_unlock(&monlock);
-		ast_log(LOG_WARNING, "Cannot kill myself\n");
-		return -1;
-	}
-	if (monitor_thread != AST_PTHREADT_NULL) {
-		/* Wake up the thread */
-		pthread_kill(monitor_thread, SIGURG);
-	} else {
-		/* Start a new monitor */
-		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;
-		}
-	}
-	ast_mutex_unlock(&monlock);
-	return 0;
-}
-
 static int skinny_devicestate(void *data)
 {
 	struct skinny_line *l;
@@ -6591,7 +6530,6 @@
 	if (!tmpc) {
 		ast_log(LOG_WARNING, "Unable to make channel for '%s'\n", tmp);
 	}
-	restart_monitor();
 	return tmpc;
 }
 
@@ -7425,13 +7363,13 @@
 	sched = ast_sched_context_create();
 	if (!sched) {
 		ast_log(LOG_WARNING, "Unable to create schedule context\n");
-	}
-	io = io_context_create();
-	if (!io) {
-		ast_log(LOG_WARNING, "Unable to create I/O context\n");
-	}
-	/* And start the monitor for the first time */
-	restart_monitor();
+		return AST_MODULE_LOAD_FAILURE;
+	}
+	if (ast_sched_start_thread(sched)) {
+		ast_sched_context_destroy(sched);
+		sched = NULL;
+		return AST_MODULE_LOAD_FAILURE;
+	}
 
 	return AST_MODULE_LOAD_SUCCESS;
 }
@@ -7483,15 +7421,6 @@
 
 	delete_devices();
 
-	ast_mutex_lock(&monlock);
-	if ((monitor_thread != AST_PTHREADT_NULL) && (monitor_thread != AST_PTHREADT_STOP)) {
-		pthread_cancel(monitor_thread);
-		pthread_kill(monitor_thread, SIGURG);
-		pthread_join(monitor_thread, NULL);
-	}
-	monitor_thread = AST_PTHREADT_STOP;
-	ast_mutex_unlock(&monlock);
-
 	ast_mutex_lock(&netlock);
 	if (accept_t && (accept_t != AST_PTHREADT_STOP)) {
 		pthread_cancel(accept_t);




More information about the asterisk-commits mailing list