[evolution-ews/gnome-3-4] Add locking around item_id_hash on calendar attachment fetching
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews/gnome-3-4] Add locking around item_id_hash on calendar attachment fetching
- Date: Tue, 7 Aug 2012 09:06:24 +0000 (UTC)
commit efadd5348a81269a001160c386524e38ec2ef853
Author: Milan Crha <mcrha redhat com>
Date: Tue Aug 7 11:06:06 2012 +0200
Add locking around item_id_hash on calendar attachment fetching
src/calendar/e-cal-backend-ews.c | 48 +++++++++++++++++++++++--------------
1 files changed, 30 insertions(+), 18 deletions(-)
---
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index 208e435..357c148 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -2784,9 +2784,8 @@ put_component_to_store (ECalBackendEws *cbews,
}
typedef struct {
- ECalComponent *comp;
ECalBackendEws *cbews;
- gchar * itemid;
+ gchar *itemid;
} EwsAttachmentData;
static void
@@ -2810,12 +2809,18 @@ ews_get_attachments_ready_callback (GObject *object,
if (error != NULL) {
g_clear_error (&error);
- return;
+ goto cleanup;
}
- comp_att = att_data->comp;
cbews = att_data->cbews;
itemid = att_data->itemid;
+ PRIV_LOCK (cbews->priv);
+ comp_att = g_hash_table_lookup (cbews->priv->item_id_hash, itemid);
+ if (!comp_att) {
+ PRIV_UNLOCK (cbews->priv);
+ goto cleanup;
+ }
+ PRIV_UNLOCK (cbews->priv);
e_cal_component_set_attachment_list (comp_att, uris);
@@ -2835,18 +2840,13 @@ ews_get_attachments_ready_callback (GObject *object,
put_component_to_store (cbews, comp_att);
- if (cache_comp) {
+ if (cache_comp)
e_cal_backend_notify_component_modified (E_CAL_BACKEND (cbews), cache_comp, comp_att);
- PRIV_LOCK (cbews->priv);
- g_hash_table_insert (cbews->priv->item_id_hash, g_strdup (itemid), g_object_ref (comp_att));
- PRIV_UNLOCK (cbews->priv);
- }
-
- g_slist_foreach (uris, (GFunc) g_free, NULL);
- g_slist_free (uris);
- g_free (itemid);
- g_object_unref (att_data->comp);
+ cleanup:
+ g_slist_free_full (uris, g_free);
+ g_object_unref (att_data->cbews);
+ g_free (att_data->itemid);
g_free (att_data);
}
@@ -2861,15 +2861,26 @@ ews_get_attachments (ECalBackendEws *cbews,
const GSList *attachment_ids;
const EwsId *item_id;
EwsAttachmentData *att_data;
+ ECalComponent *comp;
const gchar *uid;
- attachment_ids = e_ews_item_get_attachments_ids (item);
item_id = e_ews_item_get_id (item);
+ g_return_if_fail (item_id != NULL);
+
+ PRIV_LOCK (cbews->priv);
+ comp = g_hash_table_lookup (cbews->priv->item_id_hash, item_id->id);
+ if (!comp) {
+ PRIV_UNLOCK (cbews->priv);
+ g_warning ("%s: Failed to get component from item_id_hash", G_STRFUNC);
+ return;
+ }
+
+ e_cal_component_get_uid (comp, &uid);
+
+ attachment_ids = e_ews_item_get_attachments_ids (item);
att_data = g_new0 (EwsAttachmentData, 1);
- att_data->comp = g_hash_table_lookup (cbews->priv->item_id_hash, item_id->id);
- att_data->cbews = cbews;
+ att_data->cbews = g_object_ref (cbews);
att_data->itemid = g_strdup (item_id->id);
- e_cal_component_get_uid (att_data->comp, &uid);
e_ews_connection_get_attachments_start (cbews->priv->cnc,
EWS_PRIORITY_MEDIUM,
@@ -2880,6 +2891,7 @@ ews_get_attachments (ECalBackendEws *cbews,
ews_get_attachments_ready_callback,
NULL, NULL,
NULL, att_data);
+ PRIV_UNLOCK (cbews->priv);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]