[svn-commits] twilson: branch twilson/calendaring r166945 - /team/twilson/calendaring/main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Dec 30 18:05:21 CST 2008


Author: twilson
Date: Tue Dec 30 18:05:20 2008
New Revision: 166945

URL: http://svn.digium.com/view/asterisk?view=rev&rev=166945
Log:
Avoid race condition when sleeping for refresh as pointed out by russell on reviewboard

Modified:
    team/twilson/calendaring/main/calendar.c

Modified: team/twilson/calendaring/main/calendar.c
URL: http://svn.digium.com/view/asterisk/team/twilson/calendaring/main/calendar.c?view=diff&rev=166945&r1=166944&r2=166945
==============================================================================
--- team/twilson/calendaring/main/calendar.c (original)
+++ team/twilson/calendaring/main/calendar.c Tue Dec 30 18:05:20 2008
@@ -542,8 +542,10 @@
 			if (alarm_notify_sched <= 0) {
 				alarm_notify_sched = 1;
 			}
+			ast_mutex_lock(&refreshlock);
 			AST_SCHED_REPLACE(old_event->notify_sched, sched, alarm_notify_sched, calendar_event_notify, old_event);
-			ast_debug(3, "(1)Calendar alarm event notification scheduled to happen in %ld ms\n", alarm_notify_sched);
+			ast_mutex_unlock(&refreshlock);
+			ast_debug(3, "Calendar alarm event notification scheduled to happen in %ld ms\n", alarm_notify_sched);
 		}
 	}
 
@@ -555,15 +557,19 @@
 			devstate_sched_start = 1;
 		}
 
+		ast_mutex_lock(&refreshlock);
 		AST_SCHED_REPLACE(old_event->bs_start_sched, sched, devstate_sched_start, calendar_devstate_change, old_event);
-		ast_debug(3, "(1)Calendar bs_start event notification scheduled to happen in %ld ms\n", devstate_sched_start);
+		ast_mutex_unlock(&refreshlock);
+		ast_debug(3, "Calendar bs_start event notification scheduled to happen in %ld ms\n", devstate_sched_start);
 	}
 
 	if (!cmp_event || old_event->end != event->end) {
 		changed = 1;
 		devstate_sched_end = (event->end - now.tv_sec) * 1000;
+		ast_mutex_lock(&refreshlock);
 		AST_SCHED_REPLACE(old_event->bs_end_sched, sched, devstate_sched_end, calendar_devstate_change, old_event);
-		ast_debug(3, "(1)Calendar bs_start event notification scheduled to happen in %ld ms\n", devstate_sched_end);
+		ast_mutex_unlock(&refreshlock);
+		ast_debug(3, "Calendar bs_end event notification scheduled to happen in %ld ms\n", devstate_sched_end);
 	}
 
 	if (changed) {
@@ -1388,15 +1394,17 @@
 		struct timespec ts = {0,};
 		int res, wait;
 
+		ast_mutex_lock(&refreshlock);
+
 		if ((wait = ast_sched_wait(sched)) < 0) {
 			wait = 1000;
 		}
 
 		ts.tv_sec = (now.tv_sec + wait / 1000) + 1;
-
-		ast_mutex_lock(&refreshlock);
 		res = ast_cond_timedwait(&refresh_condition, &refreshlock, &ts);
+
 		ast_mutex_unlock(&refreshlock);
+
 		ast_sched_runq(sched);
 	}
 




More information about the svn-commits mailing list