[asterisk-commits] oej: branch group/edv-appleraisin-trunk r286646 - in /team/group/edv-applerai...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Sep 14 07:35:29 CDT 2010
Author: oej
Date: Tue Sep 14 07:35:24 2010
New Revision: 286646
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=286646
Log:
Resolve conflict, move on
Added:
team/group/edv-appleraisin-trunk/contrib/realtime/mysql/voicemail_data.sql
- copied unchanged from r286618, trunk/contrib/realtime/mysql/voicemail_data.sql
team/group/edv-appleraisin-trunk/contrib/realtime/mysql/voicemail_messages.sql
- copied unchanged from r286618, trunk/contrib/realtime/mysql/voicemail_messages.sql
Modified:
team/group/edv-appleraisin-trunk/ (props changed)
team/group/edv-appleraisin-trunk/main/db.c
team/group/edv-appleraisin-trunk/main/features.c
team/group/edv-appleraisin-trunk/res/res_calendar_ews.c
Propchange: team/group/edv-appleraisin-trunk/
------------------------------------------------------------------------------
automerge = http://www.codename-pineapple.org/
Propchange: team/group/edv-appleraisin-trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.
Propchange: team/group/edv-appleraisin-trunk/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Sep 14 07:35:24 2010
@@ -1,1 +1,1 @@
-/trunk:1-286467
+/trunk:1-286645
Modified: team/group/edv-appleraisin-trunk/main/db.c
URL: http://svnview.digium.com/svn/asterisk/team/group/edv-appleraisin-trunk/main/db.c?view=diff&rev=286646&r1=286645&r2=286646
==============================================================================
--- team/group/edv-appleraisin-trunk/main/db.c (original)
+++ team/group/edv-appleraisin-trunk/main/db.c Tue Sep 14 07:35:24 2010
@@ -110,6 +110,8 @@
static DB *astdb;
AST_MUTEX_DEFINE_STATIC(dblock);
+static ast_cond_t dbcond;
+static void db_sync(void);
static int db_rt; /*!< Flag for realtime system */
static char *db_rt_rtfamily = "astdb"; /*!< Realtime name tag */
@@ -306,7 +308,7 @@
counter++;
}
}
- astdb->sync(astdb, 0);
+ db_sync();
ast_mutex_unlock(&dblock);
return counter;
}
@@ -328,6 +330,7 @@
if (db_rt) {
int rowsaffected ;
+
/* Now, the question here is if we're overwriting or adding
First, let's try updating it.
*/
@@ -345,6 +348,7 @@
} else {
int fullkeylen;
char fullkey[256];
+
fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
@@ -353,7 +357,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)
@@ -457,7 +461,7 @@
key.size = fullkeylen + 1;
res = astdb->del(astdb, &key, 0);
- astdb->sync(astdb, 0);
+ db_sync();
ast_mutex_unlock(&dblock);
}
@@ -934,6 +938,41 @@
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)
{
/* When this routine is run, the realtime modules are not loaded so we can't initialize realtime yet. */
@@ -942,6 +981,13 @@
/* If you have multiple systems using the same database, set the systemname in asterisk.conf */
db_rt_sysname = S_OR(ast_config_AST_SYSTEM_NAME, "asterisk");
+ pthread_t dont_care;
+
+ ast_cond_init(&dbcond, NULL);
+ if (ast_pthread_create_background(&dont_care, NULL, db_sync_thread, NULL)) {
+ return -1;
+ }
+
/* initialize astdb or realtime */
dbinit();
Modified: team/group/edv-appleraisin-trunk/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/group/edv-appleraisin-trunk/main/features.c?view=diff&rev=286646&r1=286645&r2=286646
==============================================================================
--- team/group/edv-appleraisin-trunk/main/features.c (original)
+++ team/group/edv-appleraisin-trunk/main/features.c Tue Sep 14 07:35:24 2010
@@ -438,7 +438,7 @@
static struct ast_parkinglot *parkinglot_addref(struct ast_parkinglot *parkinglot);
static void parkinglot_unref(struct ast_parkinglot *parkinglot);
static void parkinglot_destroy(void *obj);
-int manage_parkinglot(struct ast_parkinglot *curlot, struct pollfd **pfds, int *nfds, int *fs);
+int manage_parkinglot(struct ast_parkinglot *curlot, const struct pollfd *pfds, const int nfds, struct pollfd **new_pfds, int *new_nfds, int *fs);
struct ast_parkinglot *find_parkinglot(const char *name);
static struct ast_parkinglot *create_parkinglot(const char *name);
static struct ast_parkinglot *copy_parkinglot(const char *name, const struct ast_parkinglot *parkinglot);
@@ -3603,10 +3603,8 @@
}
/*! \brief Run management on parkinglots, called once per parkinglot */
-int manage_parkinglot(struct ast_parkinglot *curlot, struct pollfd **pfds, int *nfds, int *ms)
-{
- struct pollfd *new_fds = NULL;
- int new_nfds = 0;
+int manage_parkinglot(struct ast_parkinglot *curlot, const struct pollfd *pfds, const int nfds, struct pollfd **new_pfds, int *new_nfds, int *ms)
+{
struct parkeduser *pu;
int res = 0;
char parkingslot[AST_MAX_EXTENSION];
@@ -3719,23 +3717,23 @@
continue; /* nothing on this descriptor */
}
- for (y = 0; y < *nfds; y++) {
- if ((*pfds[y]).fd == chan->fds[x]) {
+ for (y = 0; y < nfds; y++) {
+ if (pfds[y].fd == chan->fds[x]) {
/* Found poll record! */
break;
}
}
- if (y == *nfds) {
+ if (y == nfds) {
/* Not found */
continue;
}
- if (!((*pfds[y]).revents & (POLLIN | POLLERR))) {
+ if (!(pfds[y].revents & (POLLIN | POLLERR))) {
/* Next x */
continue;
}
- if ((*pfds[y]).revents & POLLERR) {
+ if (pfds[y].revents & POLLERR) {
ast_set_flag(chan, AST_FLAG_EXCEPTION);
} else {
ast_clear_flag(chan, AST_FLAG_EXCEPTION);
@@ -3782,15 +3780,15 @@
if (x >= AST_MAX_FDS) {
std: for (x = 0; x < AST_MAX_FDS; x++) { /* mark fds for next round */
if (chan->fds[x] > -1) {
- void *tmp = ast_realloc(new_fds, (new_nfds + 1) * sizeof(*new_fds));
+ void *tmp = ast_realloc(*new_pfds, (*new_nfds + 1) * sizeof(struct pollfd));
if (!tmp) {
continue;
}
- new_fds = tmp;
- new_fds[new_nfds].fd = chan->fds[x];
- new_fds[new_nfds].events = POLLIN | POLLERR;
- new_fds[new_nfds].revents = 0;
- new_nfds++;
+ *new_pfds = tmp;
+ (*new_pfds)[*new_nfds].fd = chan->fds[x];
+ (*new_pfds)[*new_nfds].events = POLLIN | POLLERR;
+ (*new_pfds)[*new_nfds].revents = 0;
+ (*new_nfds)++;
}
}
/* Keep track of our shortest wait */
@@ -3803,9 +3801,6 @@
AST_LIST_TRAVERSE_SAFE_END;
AST_LIST_UNLOCK(&curlot->parkings);
- ast_free(*pfds);
- *pfds = new_fds;
- *nfds = new_nfds;
return res;
}
@@ -3819,8 +3814,8 @@
*/
static void *do_parking_thread(void *ignore)
{
- struct pollfd *pfds = NULL;
- int nfds = 0;
+ struct pollfd *pfds = NULL, *new_pfds = NULL;
+ int nfds = 0, new_nfds = 0;
for (;;) {
struct ao2_iterator iter;
@@ -3829,10 +3824,17 @@
iter = ao2_iterator_init(parkinglots, 0);
while ((curlot = ao2_iterator_next(&iter))) {
- manage_parkinglot(curlot, &pfds, &nfds, &ms);
+ manage_parkinglot(curlot, pfds, nfds, &new_pfds, &new_nfds, &ms);
ao2_ref(curlot, -1);
}
ao2_iterator_destroy(&iter);
+
+ /* Recycle */
+ ast_free(pfds);
+ pfds = new_pfds;
+ nfds = new_nfds;
+ new_pfds = NULL;
+ new_nfds = 0;
/* Wait for something to happen */
ast_poll(pfds, nfds, ms);
Modified: team/group/edv-appleraisin-trunk/res/res_calendar_ews.c
URL: http://svnview.digium.com/svn/asterisk/team/group/edv-appleraisin-trunk/res/res_calendar_ews.c?view=diff&rev=286646&r1=286645&r2=286646
==============================================================================
--- team/group/edv-appleraisin-trunk/res/res_calendar_ews.c (original)
+++ team/group/edv-appleraisin-trunk/res/res_calendar_ews.c Tue Sep 14 07:35:24 2010
@@ -102,6 +102,7 @@
ne_uri uri;
ne_session *session;
struct ao2_container *events;
+ unsigned int items;
};
static void ewscal_destructor(void *obj)
@@ -169,7 +170,7 @@
{
struct xml_context *ctx = userdata;
- ast_debug(3, "EWS: XML: Start: %s\n", name);
+ ast_debug(5, "EWS: XML: Start: %s\n", name);
if (ctx->op == XML_OP_CREATE) {
return NE_XML_DECLINE;
}
@@ -187,16 +188,17 @@
return 1;
} else if (!strcmp(name, "RootFolder")) {
/* Get number of events */
- int items;
+ unsigned int items;
ast_debug(3, "EWS: XML: <RootFolder>\n");
- if (sscanf(ne_xml_get_attr(ctx->parser, atts, NULL, "TotalItemsInView"), "%d", &items) != 1) {
+ if (sscanf(ne_xml_get_attr(ctx->parser, atts, NULL, "TotalItemsInView"), "%u", &items) != 1) {
/* Couldn't read enything */
ne_xml_set_error(ctx->parser, "Could't read number of events.");
return NE_XML_ABORT;
}
ast_debug(3, "EWS: %d calendar items to load\n", items);
+ ctx->pvt->items = items;
if (items < 1) {
/* Stop processing XML if there are no events */
return NE_XML_DECLINE;
@@ -434,8 +436,11 @@
}
} else if (!strcmp(name, "Envelope")) {
/* Events end */
- ast_debug(3, "EWS: XML: All events has been parsed, mergingâ¦\n");
- ast_calendar_merge_events(ctx->pvt->owner, ctx->pvt->events);
+ ast_debug(3, "EWS: XML: %d of %d event(s) has been parsedâ¦\n", ao2_container_count(ctx->pvt->events), ctx->pvt->items);
+ if (ao2_container_count(ctx->pvt->events) >= ctx->pvt->items) {
+ ast_debug(3, "EWS: XML: All events has been parsed, mergingâ¦\n");
+ ast_calendar_merge_events(ctx->pvt->owner, ctx->pvt->events);
+ }
}
return 0;
More information about the asterisk-commits
mailing list