[asterisk-commits] russell: branch russell/iax2-sched-1.4 r171119 - /team/russell/iax2-sched-1.4...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Jan 25 12:24:45 CST 2009


Author: russell
Date: Sun Jan 25 12:24:45 2009
New Revision: 171119

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=171119
Log:
Re-work the scheduler handling in chan_iax2 to avoid some race conditions.

Modified:
    team/russell/iax2-sched-1.4/channels/chan_iax2.c

Modified: team/russell/iax2-sched-1.4/channels/chan_iax2.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/iax2-sched-1.4/channels/chan_iax2.c?view=diff&rev=171119&r1=171118&r2=171119
==============================================================================
--- team/russell/iax2-sched-1.4/channels/chan_iax2.c (original)
+++ team/russell/iax2-sched-1.4/channels/chan_iax2.c Sun Jan 25 12:24:45 2009
@@ -986,8 +986,10 @@
 {
 	int res;
 
+	ast_mutex_lock(&sched_lock);
 	res = ast_sched_add(con, when, callback, data);
-	signal_condition(&sched_lock, &sched_cond);
+	ast_cond_signal(&sched_cond);
+	ast_mutex_unlock(&sched_lock);
 
 	return res;
 }
@@ -3467,7 +3469,7 @@
 				ast_log(LOG_DEBUG, "Really destroying %s now...\n", c->name);
 			iax2_destroy(callno);
 		} else if (iaxs[callno]) {
-			ast_sched_add(sched, 10000, scheduled_destroy, CALLNO_TO_PTR(callno));
+			iax2_sched_add(sched, 10000, scheduled_destroy, CALLNO_TO_PTR(callno));
 		}
 	} else if (c->tech_pvt) {
 		/* If this call no longer exists, but the channel still
@@ -9163,28 +9165,36 @@
 
 static void *sched_thread(void *ignore)
 {
-	int count;
-	int res;
-	struct timeval tv;
-	struct timespec ts;
-
 	for (;;) {
+		int ms, count;
+		struct timespec ts;
+
 		pthread_testcancel();
+
 		ast_mutex_lock(&sched_lock);
-		res = ast_sched_wait(sched);
-		if ((res > 1000) || (res < 0))
-			res = 1000;
-		tv = ast_tvadd(ast_tvnow(), ast_samp2tv(res, 1000));
-		ts.tv_sec = tv.tv_sec;
-		ts.tv_nsec = tv.tv_usec * 1000;
-		ast_cond_timedwait(&sched_cond, &sched_lock, &ts);
+
+		ms = ast_sched_wait(sched);
+
+		if (ms == -1) {
+			ast_cond_wait(&sched_cond, &sched_lock);
+		} else {
+			struct timeval tv;
+			tv = ast_tvadd(ast_tvnow(), ast_samp2tv(ms, 1000));
+			ts.tv_sec = tv.tv_sec;
+			ts.tv_nsec = tv.tv_usec * 1000;
+			ast_cond_timedwait(&sched_cond, &sched_lock, &ts);
+		}
+
 		ast_mutex_unlock(&sched_lock);
+
 		pthread_testcancel();
 
 		count = ast_sched_runq(sched);
-		if (option_debug && count >= 20)
+		if (option_debug && count >= 20) {
 			ast_log(LOG_DEBUG, "chan_iax2: ast_sched_runq ran %d scheduled tasks all at once\n", count);
-	}
+		}
+	}
+
 	return NULL;
 }
 




More information about the asterisk-commits mailing list