[svn-commits] russell: branch group/timing r122925 - /team/group/timing/res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jun 16 07:58:16 CDT 2008


Author: russell
Date: Mon Jun 16 07:58:15 2008
New Revision: 122925

URL: http://svn.digium.com/view/asterisk?view=rev&rev=122925
Log:
- Try a little bit harder to ensure we wake up every 10 ms
- make the timing thread go to sleep when no timers are open

Modified:
    team/group/timing/res/res_timing_pthread.c

Modified: team/group/timing/res/res_timing_pthread.c
URL: http://svn.digium.com/view/asterisk/team/group/timing/res/res_timing_pthread.c?view=diff&rev=122925&r1=122924&r2=122925
==============================================================================
--- team/group/timing/res/res_timing_pthread.c (original)
+++ team/group/timing/res/res_timing_pthread.c Mon Jun 16 07:58:15 2008
@@ -92,6 +92,16 @@
 static void write_byte(int wr_fd);
 static void read_pipe(int rd_fd, unsigned int num, int clear);
 
+/*!
+ * \brief Data for the timing thread
+ */
+static struct {
+	pthread_t thread;
+	ast_mutex_t lock;
+	ast_cond_t cond;
+	unsigned int stop:1;
+} timing_thread;
+
 static int pthread_timer_open(void)
 {
 	struct pthread_timer *timer;
@@ -109,7 +119,14 @@
 		return -1;
 	}
 
+	ao2_lock(pthread_timers);
+	if (!ao2_container_count(pthread_timers)) {
+		ast_mutex_lock(&timing_thread.lock);
+		ast_cond_signal(&timing_thread.cond);
+		ast_mutex_unlock(&timing_thread.lock);
+	}
 	ao2_link(pthread_timers, timer);
+	ao2_unlock(pthread_timers);
 
 	return timer->pipe[PIPE_READ];
 }
@@ -390,32 +407,27 @@
 	return 0;
 }
 
-/*!
- * \brief Data for the timing thread
- */
-static struct {
-	pthread_t thread;
-	ast_mutex_t lock;
-	ast_cond_t cond;
-	unsigned int stop:1;
-} timing_thread;
-
 static void *do_timing(void *arg)
 {
+	struct timeval next_wakeup = ast_tvnow();
+
 	while (!timing_thread.stop) {
-		struct timeval next_wakeup;
 		struct timespec ts = { 0, };
 
 		ao2_callback(pthread_timers, 0, run_timer, NULL);
 
-		next_wakeup = ast_tvadd(ast_tvnow(), ast_tv(0, 10000));
+		next_wakeup = ast_tvadd(next_wakeup, ast_tv(0, 10000));
 
 		ts.tv_sec = next_wakeup.tv_sec;
 		ts.tv_nsec = next_wakeup.tv_usec * 1000;
 
 		ast_mutex_lock(&timing_thread.lock);
 		if (!timing_thread.stop) {
-			ast_cond_timedwait(&timing_thread.cond, &timing_thread.lock, &ts);
+			if (ao2_container_count(pthread_timers)) {
+				ast_cond_timedwait(&timing_thread.cond, &timing_thread.lock, &ts);
+			} else {
+				ast_cond_wait(&timing_thread.cond, &timing_thread.lock);
+			}
 		}
 		ast_mutex_unlock(&timing_thread.lock);
 	}




More information about the svn-commits mailing list