[asterisk-commits] jpeeler: branch jpeeler/feature14882 r286500 - in /team/jpeeler/feature14882:...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Sep 13 17:17:43 CDT 2010
Author: jpeeler
Date: Mon Sep 13 17:17:39 2010
New Revision: 286500
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=286500
Log:
sync with trunk
Modified:
team/jpeeler/feature14882/ (props changed)
team/jpeeler/feature14882/main/db.c
Propchange: team/jpeeler/feature14882/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.
Propchange: team/jpeeler/feature14882/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Sep 13 17:17:39 2010
@@ -1,1 +1,1 @@
-/trunk:1-286496
+/trunk:1-286498
Modified: team/jpeeler/feature14882/main/db.c
URL: http://svnview.digium.com/svn/asterisk/team/jpeeler/feature14882/main/db.c?view=diff&rev=286500&r1=286499&r2=286500
==============================================================================
--- team/jpeeler/feature14882/main/db.c (original)
+++ team/jpeeler/feature14882/main/db.c Mon Sep 13 17:17:39 2010
@@ -102,6 +102,9 @@
static DB *astdb;
AST_MUTEX_DEFINE_STATIC(dblock);
+static ast_cond_t dbcond;
+
+static void db_sync(void);
static int dbinit(void)
{
@@ -182,7 +185,7 @@
counter++;
}
}
- astdb->sync(astdb, 0);
+ db_sync();
ast_mutex_unlock(&dblock);
return counter;
}
@@ -207,7 +210,7 @@
data.data = (char *) value;
data.size = strlen(value) + 1;
res = astdb->put(astdb, &key, &data, 0);
- astdb->sync(astdb, 0);
+ db_sync();
ast_mutex_unlock(&dblock);
if (res)
ast_log(LOG_WARNING, "Unable to put value '%s' for key '%s' in family '%s'\n", value, keys, family);
@@ -276,7 +279,7 @@
key.size = fullkeylen + 1;
res = astdb->del(astdb, &key, 0);
- astdb->sync(astdb, 0);
+ db_sync();
ast_mutex_unlock(&dblock);
@@ -718,8 +721,50 @@
return 0;
}
+/*!
+ * \internal
+ * \brief Signal the astdb sync thread to do its thing.
+ *
+ * \note dblock is assumed to be held when calling this function.
+ */
+static void db_sync(void)
+{
+ ast_cond_signal(&dbcond);
+}
+
+/*!
+ * \internal
+ * \brief astdb sync thread
+ *
+ * This thread is in charge of syncing astdb to disk after a change.
+ * By pushing it off to this thread to take care of, this I/O bound operation
+ * will not block other threads from performing other critical processing.
+ * If changes happen rapidly, this thread will also ensure that the sync
+ * operations are rate limited.
+ */
+static void *db_sync_thread(void *data)
+{
+ ast_mutex_lock(&dblock);
+ for (;;) {
+ ast_cond_wait(&dbcond, &dblock);
+ ast_mutex_unlock(&dblock);
+ sleep(1);
+ ast_mutex_lock(&dblock);
+ astdb->sync(astdb, 0);
+ }
+
+ return NULL;
+}
+
int astdb_init(void)
{
+ pthread_t dont_care;
+
+ ast_cond_init(&dbcond, NULL);
+ if (ast_pthread_create_background(&dont_care, NULL, db_sync_thread, NULL)) {
+ return -1;
+ }
+
dbinit();
ast_cli_register_multiple(cli_database, ARRAY_LEN(cli_database));
ast_manager_register_xml("DBGet", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_dbget);
More information about the asterisk-commits
mailing list