--- a/addressbook/e-book-backend-exchange.c.orig 2007-10-12 09:05:18.000000000 +0200 +++ b/addressbook/e-book-backend-exchange.c 2008-01-21 11:02:48.000000000 +0100 @@ -84,12 +84,15 @@ gboolean is_cache_ready; gboolean marked_for_offline; - GMutex *create_mutex; + GMutex *cache_lock; EBookBackendSummary *summary; EBookBackendCache *cache; }; +#define LOCK(x) g_mutex_lock (x->cache_lock) +#define UNLOCK(x) g_mutex_unlock (x->cache_lock) + typedef struct PropMapping PropMapping; static void subscription_notify (E2kContext *ctx, const char *uri, E2kContextChangeType type, gpointer user_data); @@ -477,6 +480,7 @@ field_names, n_field_names, bepriv->base_rn, NULL, TRUE); + LOCK (bepriv); e_file_cache_freeze_changes (E_FILE_CACHE (bepriv->cache)); while ((result = e2k_result_iter_next (iter))) { contact = e_contact_from_props (be, result); @@ -488,6 +492,7 @@ e_book_backend_cache_set_populated (bepriv->cache); bepriv->is_cache_ready=TRUE; e_file_cache_thaw_changes (E_FILE_CACHE (bepriv->cache)); + UNLOCK (bepriv); return NULL; } @@ -520,6 +525,7 @@ field_names, n_field_names, bepriv->base_rn, NULL, TRUE); + LOCK (bepriv); e_file_cache_freeze_changes (E_FILE_CACHE (bepriv->cache)); while ((result = e2k_result_iter_next (iter))) { contact = e_contact_from_props (be, result); @@ -531,7 +537,7 @@ e_book_backend_cache_set_populated (bepriv->cache); bepriv->is_cache_ready=TRUE; e_file_cache_thaw_changes (E_FILE_CACHE (bepriv->cache)); - + UNLOCK (bepriv); return TRUE; } @@ -1319,13 +1325,13 @@ d(printf("ebbe_create_contact(%p, %p, %s)\n", backend, book, vcard)); - g_mutex_lock (bepriv->create_mutex); + LOCK (bepriv); switch (bepriv->mode) { case GNOME_Evolution_Addressbook_MODE_LOCAL: *contact = NULL; - g_mutex_unlock (bepriv->create_mutex); + UNLOCK (bepriv); return GNOME_Evolution_Addressbook_RepositoryOffline; case GNOME_Evolution_Addressbook_MODE_REMOTE: @@ -1346,6 +1353,7 @@ state = e_book_backend_exchange_connect (be); if ( state != GNOME_Evolution_Addressbook_Success) { d(printf("Returning status %d while creating contact\n", state)); + UNLOCK (bepriv); return state; } } @@ -1375,18 +1383,18 @@ e_book_backend_summary_add_contact (bepriv->summary, *contact); e_book_backend_cache_add_contact (bepriv->cache, *contact); - g_mutex_unlock (bepriv->create_mutex); + UNLOCK (bepriv); return GNOME_Evolution_Addressbook_Success; } else { g_object_unref (*contact); *contact = NULL; - g_mutex_unlock (bepriv->create_mutex); + UNLOCK (bepriv); return http_status_to_pas (status); } default: break; } - g_mutex_unlock (bepriv->create_mutex); + UNLOCK (bepriv); return GNOME_Evolution_Addressbook_Success; } @@ -1501,13 +1509,14 @@ e2k_results_free (results, nresults); if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) { + LOCK (bepriv); e_book_backend_summary_remove_contact (bepriv->summary, uri); e_book_backend_summary_add_contact (bepriv->summary, *contact); e_book_backend_cache_remove_contact (bepriv->cache, uri); e_book_backend_cache_add_contact (bepriv->cache, *contact); - + UNLOCK (bepriv); return GNOME_Evolution_Addressbook_Success; } else { g_object_unref (*contact); @@ -1550,11 +1559,13 @@ uri = l->data; status = e2k_context_delete (bepriv->ctx, NULL, uri); if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) { + LOCK (bepriv); e_book_backend_summary_remove_contact ( bepriv->summary, uri); e_book_backend_cache_remove_contact (bepriv->cache, uri); *removed_ids = g_list_append ( *removed_ids, g_strdup (uri)); + UNLOCK (bepriv); } else ret_status = http_status_to_pas (status); } @@ -2537,8 +2548,8 @@ if (be->priv->cache) g_object_unref (be->priv->cache); - if (be->priv->create_mutex) - g_mutex_free (be->priv->create_mutex); + if (be->priv->cache_lock) + g_mutex_free (be->priv->cache_lock); g_free (be->priv); @@ -2608,7 +2619,7 @@ priv->original_uri = NULL; priv->is_writable = TRUE; - priv->create_mutex = g_mutex_new (); + priv->cache_lock = g_mutex_new (); backend->priv = priv; }