[evolution-data-server/openismus-work-master: 91/137] Changes for Review: EBookBackendFile, various changes.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work-master: 91/137] Changes for Review: EBookBackendFile, various changes.
- Date: Mon, 21 Oct 2013 22:54:13 +0000 (UTC)
commit 75446e09bc39fc6634bbaac17e3e47a8df4cb109
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Sat Oct 5 02:04:54 2013 +0200
Changes for Review: EBookBackendFile, various changes.
Adapted for new APIs and now the ->cursors and ->locale variables
are always protected by the file backend's GRWLock.
addressbook/backends/file/e-book-backend-file.c | 61 +++++++++++++++++------
1 files changed, 45 insertions(+), 16 deletions(-)
---
diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c
index 067871a..4f4a547 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -1056,8 +1056,10 @@ book_backend_file_dispose (GObject *object)
bf = E_BOOK_BACKEND_FILE (object);
+ g_rw_lock_writer_lock (&(bf->priv->lock));
+
if (bf->priv->cursors) {
- g_list_free_full (bf->priv->cursors, (GDestroyNotify)g_object_unref);
+ g_list_free_full (bf->priv->cursors, g_object_unref);
bf->priv->cursors = NULL;
}
@@ -1066,6 +1068,7 @@ book_backend_file_dispose (GObject *object)
bf->priv->sqlitedb = NULL;
}
+ g_rw_lock_writer_unlock (&(bf->priv->lock));
G_OBJECT_CLASS (e_book_backend_file_parent_class)->dispose (object);
}
@@ -1366,8 +1369,6 @@ book_backend_file_modify_contacts_sync (EBookBackend *backend,
}
}
- g_rw_lock_writer_unlock (&(bf->priv->lock));
-
if (status != STATUS_ERROR)
e_queue_transfer (&mod_contact_queue, out_contacts);
@@ -1387,6 +1388,8 @@ book_backend_file_modify_contacts_sync (EBookBackend *backend,
}
}
+ g_rw_lock_writer_unlock (&(bf->priv->lock));
+
while (!g_queue_is_empty (&old_contact_queue))
g_object_unref (g_queue_pop_head (&old_contact_queue));
@@ -1487,8 +1490,6 @@ book_backend_file_remove_contacts_sync (EBookBackend *backend,
}
}
- g_rw_lock_writer_unlock (&(bf->priv->lock));
-
/* After removing any contacts, notify any cursors that the new contacts are added */
if (success) {
for (l = removed_contacts; l; l = l->next) {
@@ -1496,6 +1497,8 @@ book_backend_file_remove_contacts_sync (EBookBackend *backend,
}
}
+ g_rw_lock_writer_unlock (&(bf->priv->lock));
+
g_slist_free_full (removed_ids, (GDestroyNotify) g_free);
g_slist_free_full (removed_contacts, (GDestroyNotify) g_object_unref);
@@ -1832,8 +1835,6 @@ book_backend_file_set_locale (EBookBackend *backend,
}
}
- g_rw_lock_writer_unlock (&(bf->priv->lock));
-
cursors_locale_changed (bf);
/* We set the new locale, now update our local variable */
@@ -1841,26 +1842,35 @@ book_backend_file_set_locale (EBookBackend *backend,
g_free (bf->priv->locale);
bf->priv->locale = g_strdup (locale);
}
+
+ g_rw_lock_writer_unlock (&(bf->priv->lock));
}
-static const gchar *
-book_backend_file_get_locale (EBookBackend *backend)
+static gchar *
+book_backend_file_dup_locale (EBookBackend *backend)
{
EBookBackendFile *bf = E_BOOK_BACKEND_FILE (backend);
+ gchar *locale;
+
+ g_rw_lock_reader_lock (&(bf->priv->lock));
+ locale = g_strdup (bf->priv->locale);
+ g_rw_lock_reader_unlock (&(bf->priv->lock));
- return bf->priv->locale;
+ return locale;
}
static EDataBookCursor *
book_backend_file_create_cursor (EBookBackend *backend,
EContactField *sort_fields,
- EBookSortType *sort_types,
+ EBookCursorSortType *sort_types,
guint n_fields,
GError **error)
{
EBookBackendFile *bf = E_BOOK_BACKEND_FILE (backend);
EDataBookCursor *cursor;
+ g_rw_lock_writer_lock (&(bf->priv->lock));
+
cursor = e_data_book_cursor_sqlite_new (backend,
bf->priv->sqlitedb,
SQLITEDB_FOLDER_ID,
@@ -1873,17 +1883,36 @@ book_backend_file_create_cursor (EBookBackend *backend,
bf->priv->cursors =
g_list_prepend (bf->priv->cursors, cursor);
+ g_rw_lock_writer_unlock (&(bf->priv->lock));
+
return cursor;
}
-static void
+static gboolean
book_backend_file_delete_cursor (EBookBackend *backend,
- EDataBookCursor *cursor)
+ EDataBookCursor *cursor,
+ GError **error)
{
EBookBackendFile *bf = E_BOOK_BACKEND_FILE (backend);
+ GList *link;
+
+ g_rw_lock_writer_lock (&(bf->priv->lock));
+
+ link = g_list_find (bf->priv->cursors, cursor);
+
+ if (link != NULL) {
+ bf->priv->cursors = g_list_delete_link (bf->priv->cursors, link);
+ g_object_unref (cursor);
+ } else {
+ g_set_error_literal (error,
+ E_CLIENT_ERROR,
+ E_CLIENT_ERROR_INVALID_ARG,
+ _("Requested to delete an unrelated cursor"));
+ }
+
+ g_rw_lock_writer_unlock (&(bf->priv->lock));
- bf->priv->cursors = g_list_remove (bf->priv->cursors, cursor);
- g_object_unref (cursor);
+ return link != NULL;
}
static gboolean
@@ -2051,7 +2080,7 @@ e_book_backend_file_class_init (EBookBackendFileClass *class)
backend_class->configure_direct = book_backend_file_configure_direct;
backend_class->sync = book_backend_file_sync;
backend_class->set_locale = book_backend_file_set_locale;
- backend_class->get_locale = book_backend_file_get_locale;
+ backend_class->dup_locale = book_backend_file_dup_locale;
backend_class->create_cursor = book_backend_file_create_cursor;
backend_class->delete_cursor = book_backend_file_delete_cursor;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]