[asterisk-commits] mmichelson: trunk r410567 - in /trunk: ./ main/db.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 14 11:19:25 CDT 2014


Author: mmichelson
Date: Fri Mar 14 11:19:21 2014
New Revision: 410567

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=410567
Log:
Prevent delayed astdb syncs.

The syncing thread sleeps for a second before waiting to be
told to attempt to sync again. If a signal were sent during this
sleeping period, we would end up having to wait until the next
sync signal occurred in order to sync up the astdb.

This code rearrangement also ensures that any pending transactions
will be synced prior to Asterisk shutting down.

Patches: db_sync.patch by John Hardin (License #6512)
........

Merged revisions 410556 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 410559 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/main/db.c

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

Modified: trunk/main/db.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/db.c?view=diff&rev=410567&r1=410566&r2=410567
==============================================================================
--- trunk/main/db.c (original)
+++ trunk/main/db.c Fri Mar 14 11:19:21 2014
@@ -112,6 +112,7 @@
 static sqlite3 *astdb;
 static pthread_t syncthread;
 static int doexit;
+static int dosync;
 
 static void db_sync(void);
 
@@ -939,6 +940,7 @@
  */
 static void db_sync(void)
 {
+	dosync = 1;
 	ast_cond_signal(&dbcond);
 }
 
@@ -957,6 +959,14 @@
 	ast_mutex_lock(&dblock);
 	ast_db_begin_transaction();
 	for (;;) {
+		/* If dosync is set, db_sync() was called during sleep(1), 
+		 * and the pending transaction should be committed. 
+		 * Otherwise, block until db_sync() is called.
+		 */
+		while (!dosync) {
+			ast_cond_wait(&dbcond, &dblock);
+		}
+		dosync = 0;
 		/* We're ok with spurious wakeups, so we don't worry about a predicate */
 		ast_cond_wait(&dbcond, &dblock);
 		if (ast_db_commit_transaction()) {
@@ -970,15 +980,6 @@
 		ast_mutex_unlock(&dblock);
 		sleep(1);
 		ast_mutex_lock(&dblock);
-		/* Unfortunately, it is possible for signaling to happen
-		 * when we're not waiting: in the bit when we're unlocked
-		 * above. Do the do-exit check here again. (We could do
-		 * it once, but that would impose a forced delay of 1
-		 * second always.) */
-		if (doexit) {
-			ast_mutex_unlock(&dblock);
-			break;
-		}
 	}
 
 	return NULL;
@@ -998,8 +999,8 @@
 
 	/* Set doexit to 1 to kill thread. db_sync must be called with
 	 * mutex held. */
+	ast_mutex_lock(&dblock);
 	doexit = 1;
-	ast_mutex_lock(&dblock);
 	db_sync();
 	ast_mutex_unlock(&dblock);
 




More information about the asterisk-commits mailing list