[evolution-data-server] re-arrange the locks



commit 4a4e2b85f63ddbba377a9251ea6556c59f7a17d6
Author: Chenthill Palanisamy <pchenthill novell com>
Date:   Thu Apr 8 16:47:39 2010 +0530

    re-arrange the locks

 .../groupwise/e-cal-backend-groupwise-utils.c      |   35 ++++++++--
 .../groupwise/e-cal-backend-groupwise-utils.h      |    2 +-
 .../backends/groupwise/e-cal-backend-groupwise.c   |   73 ++++++++-----------
 .../backends/groupwise/e-cal-backend-groupwise.h   |    3 +
 4 files changed, 65 insertions(+), 48 deletions(-)
---
diff --git a/calendar/backends/groupwise/e-cal-backend-groupwise-utils.c b/calendar/backends/groupwise/e-cal-backend-groupwise-utils.c
index a22f377..c7a2003 100644
--- a/calendar/backends/groupwise/e-cal-backend-groupwise-utils.c
+++ b/calendar/backends/groupwise/e-cal-backend-groupwise-utils.c
@@ -825,9 +825,15 @@ e_gw_item_new_from_cal_component (const gchar *container, ECalBackendGroupwise *
 
 	g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);
 
+	e_cal_backend_groupwise_priv_lock (cbgw);
+	
 	item = e_gw_item_new_empty ();
 	e_gw_item_set_container_id (item, container);
-	return set_properties_from_cal_component (item, comp, cbgw);
+	item = set_properties_from_cal_component (item, comp, cbgw);
+
+	e_cal_backend_groupwise_priv_unlock (cbgw);
+
+	return item;
 }
 
 /* Set the attendee list and send options to EGwItem */
@@ -844,8 +850,10 @@ e_gw_item_new_for_delegate_from_cal (ECalBackendGroupwise *cbgw, ECalComponent *
 	e_gw_item_set_id (item, e_cal_component_get_gw_id (comp));
 	user_email = e_gw_connection_get_user_email (e_cal_backend_groupwise_get_connection (cbgw));
 
+	e_cal_backend_groupwise_priv_lock (cbgw);
 	set_attendees_to_item (item, comp, default_zone, TRUE, user_email);
 	add_send_options_data_to_item (item, comp, default_zone);
+	e_cal_backend_groupwise_priv_unlock (cbgw);
 
 	return item;
 }
@@ -1035,11 +1043,13 @@ e_gw_item_to_cal_component (EGwItem *item, ECalBackendGroupwise *cbgw)
 	EGwItemOrganizer *organizer;
 	EGwItemType item_type;
 
+	g_return_val_if_fail (E_IS_GW_ITEM (item), NULL);
+	
+	e_cal_backend_groupwise_priv_lock (cbgw);
+	
 	default_zone = e_cal_backend_groupwise_get_default_zone (cbgw);
 	categories_by_id = e_cal_backend_groupwise_get_categories_by_id (cbgw);
 
-	g_return_val_if_fail (E_IS_GW_ITEM (item), NULL);
-
 	comp = e_cal_component_new ();
 
 	item_type = e_gw_item_get_item_type (item);
@@ -1052,6 +1062,7 @@ e_gw_item_to_cal_component (EGwItem *item, ECalBackendGroupwise *cbgw)
 		e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_JOURNAL);
 	else {
 		g_object_unref (comp);
+		e_cal_backend_groupwise_priv_unlock (cbgw);
 		return NULL;
 	}
 
@@ -1175,8 +1186,10 @@ e_gw_item_to_cal_component (EGwItem *item, ECalBackendGroupwise *cbgw)
 		}
 
 		e_cal_component_set_dtstart (comp, &dt);
-	} else
+	} else {
+		e_cal_backend_groupwise_priv_unlock (cbgw);
 		return NULL;
+	}
 
 	/* UID */
 	if (e_gw_item_get_recurrence_key (item) != 0) {
@@ -1200,6 +1213,7 @@ e_gw_item_to_cal_component (EGwItem *item, ECalBackendGroupwise *cbgw)
 			e_cal_component_set_uid (comp, e_gw_item_get_icalid (item));
 		else {
 			g_object_unref (comp);
+			e_cal_backend_groupwise_priv_unlock (cbgw);
 			return NULL;
 		}
 	}
@@ -1405,10 +1419,12 @@ e_gw_item_to_cal_component (EGwItem *item, ECalBackendGroupwise *cbgw)
 	case E_GW_ITEM_TYPE_NOTE:
 		break;
 	default :
+		e_cal_backend_groupwise_priv_unlock (cbgw);
 		return NULL;
 	}
 
 	e_cal_component_commit_sequence (comp);
+	e_cal_backend_groupwise_priv_unlock (cbgw);
 
 	return comp;
 }
@@ -1726,17 +1742,22 @@ close_freebusy_session (EGwConnection *cnc, const gchar *session)
 }
 
 EGwConnectionStatus
-e_gw_connection_get_freebusy_info (EGwConnection *cnc, GList *users, time_t start, time_t end, GList **freebusy, icaltimezone *default_zone)
+e_gw_connection_get_freebusy_info (ECalBackendGroupwise *cbgw, GList *users, time_t start, time_t end, GList **freebusy)
 {
         SoupSoapMessage *msg;
         SoupSoapResponse *response;
         EGwConnectionStatus status;
         SoupSoapParameter *param, *subparam, *param_outstanding;
+	EGwConnection *cnc;
         gchar *session;
 	gchar *outstanding = NULL;
 	gboolean resend_request = TRUE;
 	gint request_iteration = 0;
+	icaltimezone *default_zone;
 
+	default_zone = e_cal_backend_groupwise_get_default_zone (cbgw);
+	cnc = e_cal_backend_groupwise_get_connection (cbgw);
+	
 	g_return_val_if_fail (E_IS_GW_CONNECTION (cnc), E_GW_CONNECTION_STATUS_INVALID_CONNECTION);
 
 	/* Perform startFreeBusySession */
@@ -1815,6 +1836,8 @@ e_gw_connection_get_freebusy_info (EGwConnection *cnc, GList *users, time_t star
 		GSList *attendee_list = NULL;
 		icalcomponent *icalcomp = NULL;
 		icaltimetype start_time, end_time;
+	
+		e_cal_backend_groupwise_priv_lock (cbgw);
 
 		tmp = soup_soap_parameter_get_first_child_by_name (subparam, "email");
 		if (tmp)
@@ -1861,6 +1884,7 @@ e_gw_connection_get_freebusy_info (EGwConnection *cnc, GList *users, time_t star
 		if (!param_blocks) {
 			g_object_unref (response);
 			g_object_unref (msg);
+			e_cal_backend_groupwise_priv_unlock (cbgw);
 			return E_GW_CONNECTION_STATUS_INVALID_RESPONSE;
 		}
 
@@ -1932,6 +1956,7 @@ e_gw_connection_get_freebusy_info (EGwConnection *cnc, GList *users, time_t star
 		e_cal_component_commit_sequence (comp);
 		*freebusy = g_list_append (*freebusy, e_cal_component_get_as_string (comp));
 		g_object_unref (comp);
+		e_cal_backend_groupwise_priv_unlock (cbgw);
 	}
 
         g_object_unref (msg);
diff --git a/calendar/backends/groupwise/e-cal-backend-groupwise-utils.h b/calendar/backends/groupwise/e-cal-backend-groupwise-utils.h
index 7dbd605..838f846 100644
--- a/calendar/backends/groupwise/e-cal-backend-groupwise-utils.h
+++ b/calendar/backends/groupwise/e-cal-backend-groupwise-utils.h
@@ -52,7 +52,7 @@ void          e_gw_item_set_changes (EGwItem *item, EGwItem *cached_item);
  */
 EGwConnectionStatus e_gw_connection_create_appointment (EGwConnection *cnc, const gchar *container, ECalBackendGroupwise *cbgw, ECalComponent *comp, GSList **id_list);
 EGwConnectionStatus e_gw_connection_send_appointment (ECalBackendGroupwise *cbgw, const gchar *container, ECalComponent *comp, icalproperty_method method, gboolean all_instances, ECalComponent **created_comp, icalparameter_partstat *pstatus);
-EGwConnectionStatus e_gw_connection_get_freebusy_info (EGwConnection *cnc, GList *users, time_t start, time_t end, GList **freebusy, icaltimezone *default_zone);
+EGwConnectionStatus e_gw_connection_get_freebusy_info (ECalBackendGroupwise *cbgw, GList *users, time_t start, time_t end, GList **freebusy);
 gboolean e_cal_backend_groupwise_store_settings (GwSettings *hold);
 gboolean e_cal_backend_groupwise_utils_check_delegate (ECalComponent *comp, const gchar *email);
 
diff --git a/calendar/backends/groupwise/e-cal-backend-groupwise.c b/calendar/backends/groupwise/e-cal-backend-groupwise.c
index 5316b6a..74809b8 100644
--- a/calendar/backends/groupwise/e-cal-backend-groupwise.c
+++ b/calendar/backends/groupwise/e-cal-backend-groupwise.c
@@ -71,8 +71,6 @@ typedef struct {
 
 /* Private part of the CalBackendGroupwise structure */
 struct _ECalBackendGroupwisePrivate {
-	/* A mutex to control access to the private structure */
-	GStaticRecMutex rec_mutex;
 	EGwConnection *cnc;
 	ECalBackendStore *store;
 	gboolean read_only;
@@ -82,7 +80,6 @@ struct _ECalBackendGroupwisePrivate {
 	gchar *container_id;
 	CalMode mode;
 	gboolean mode_changed;
-	icaltimezone *default_zone;
 	GHashTable *categories_by_id;
 	GHashTable *categories_by_name;
 
@@ -96,6 +93,9 @@ struct _ECalBackendGroupwisePrivate {
 	gchar *user_email;
 	gchar *local_attachments_store;
 
+	/* A mutex to control access to the private structure for the following */
+	GStaticRecMutex rec_mutex;
+	icaltimezone *default_zone;
 	guint timeout_id;
 	GThread *dthread;
 	SyncDelta *dlock;
@@ -155,6 +155,18 @@ e_cal_backend_groupwise_get_default_zone (ECalBackendGroupwise *cbgw) {
 	return cbgw->priv->default_zone;
 }
 
+void
+e_cal_backend_groupwise_priv_lock (ECalBackendGroupwise *cbgw)
+{
+       PRIV_LOCK (cbgw->priv);
+}
+
+void
+e_cal_backend_groupwise_priv_unlock (ECalBackendGroupwise *cbgw)
+{
+       PRIV_UNLOCK (cbgw->priv);
+}
+
 static const gchar *
 get_element_type (icalcomponent_kind kind)
 {
@@ -198,7 +210,6 @@ populate_cache (ECalBackendGroupwise *cbgw)
 	kind = e_cal_backend_get_kind (E_CAL_BACKEND (cbgw));
 	total = priv->total_count;
 
-	PRIV_LOCK (priv);
 
 	type = get_element_type (kind);
 
@@ -236,7 +247,6 @@ populate_cache (ECalBackendGroupwise *cbgw)
 				"recipients message recipientStatus attachments default peek", filter[i], &cursor);
 		if (status != E_GW_CONNECTION_STATUS_OK) {
 			e_cal_backend_groupwise_notify_error_code (cbgw, status);
-			PRIV_UNLOCK (priv);
 			return status;
 		}
 		done = FALSE;
@@ -256,7 +266,6 @@ populate_cache (ECalBackendGroupwise *cbgw)
 			status = e_gw_connection_read_cursor (priv->cnc, priv->container_id, cursor, forward, CURSOR_ITEM_LIMIT, position, &list);
 			if (status != E_GW_CONNECTION_STATUS_OK) {
 				e_cal_backend_groupwise_notify_error_code (cbgw, status);
-				PRIV_UNLOCK (priv);
 				return status;
 			}
 			for (l = list; l != NULL; l = g_list_next(l)) {
@@ -304,7 +313,6 @@ populate_cache (ECalBackendGroupwise *cbgw)
 	}
 	e_cal_backend_notify_view_progress (E_CAL_BACKEND (cbgw), "", 100);
 
-	PRIV_UNLOCK (priv);
 	return E_GW_CONNECTION_STATUS_OK;
 }
 
@@ -345,7 +353,6 @@ get_deltas (gpointer handle)
 	gchar *time_string = NULL;
 	gchar t_str [26];
 	gchar *attempts;
-	gchar *container_id;
 	const gchar *serv_time;
 	const gchar *position;
 
@@ -366,11 +373,8 @@ get_deltas (gpointer handle)
 	if (priv->mode == CAL_MODE_LOCAL)
 		return FALSE;
 
-	PRIV_LOCK (priv);
-
 	kind = e_cal_backend_get_kind (E_CAL_BACKEND (cbgw));
 	cnc = priv->cnc;
-	container_id = g_strdup (cbgw->priv->container_id);
 
 	store = priv->store;
 	item_list = NULL;
@@ -406,13 +410,10 @@ get_deltas (gpointer handle)
 	e_gw_filter_add_filter_component (filter, E_GW_FILTER_OP_EQUAL, "@type", get_element_type (kind));
 	e_gw_filter_group_conditions (filter, E_GW_FILTER_OP_AND, 2);
 
-	PRIV_UNLOCK (priv);
-
-	status = e_gw_connection_get_items (cnc, container_id, "attachments recipients message recipientStatus default peek", filter, &item_list);
+	status = e_gw_connection_get_items (cnc, priv->container_id, "attachments recipients message recipientStatus default peek", filter, &item_list);
 	if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
-		status = e_gw_connection_get_items (cnc, container_id, "attachments recipients message recipientStatus default peek", filter, &item_list);
+		status = e_gw_connection_get_items (cnc, priv->container_id, "attachments recipients message recipientStatus default peek", filter, &item_list);
 
-	PRIV_LOCK (priv);
 
 	g_object_unref (filter);
 
@@ -430,16 +431,12 @@ get_deltas (gpointer handle)
 		e_cal_backend_store_put_key_value (store, ATTEMPTS_KEY, attempts);
 		g_free (attempts);
 
-		g_free (container_id);
-
 		if (status == E_GW_CONNECTION_STATUS_NO_RESPONSE) {
-			PRIV_UNLOCK (priv);
 			return TRUE;
 		}
 
 		msg = e_gw_connection_get_error_message (status);
 
-		PRIV_UNLOCK (priv);
 		return TRUE;
 	}
 
@@ -536,23 +533,16 @@ get_deltas (gpointer handle)
 	filter = e_gw_filter_new ();
 	e_gw_filter_add_filter_component (filter, E_GW_FILTER_OP_EQUAL, "@type", get_element_type (kind));
 
-	PRIV_UNLOCK (priv);
-	status = e_gw_connection_create_cursor (cnc, container_id, "id iCalId recurrenceKey startDate", filter, &cursor);
-	PRIV_LOCK (priv);
+	status = e_gw_connection_create_cursor (cnc, priv->container_id, "id iCalId recurrenceKey startDate", filter, &cursor);
 
 	g_object_unref (filter);
 
 	if (status != E_GW_CONNECTION_STATUS_OK) {
-
-		g_free (container_id);
-
 		if (status == E_GW_CONNECTION_STATUS_NO_RESPONSE) {
-			PRIV_UNLOCK (priv);
 			return TRUE;
 		}
 
 		e_cal_backend_groupwise_notify_error_code (cbgw, status);
-		PRIV_UNLOCK (priv);
 		return TRUE;
 	}
 
@@ -560,9 +550,7 @@ get_deltas (gpointer handle)
 
 	done = FALSE;
 	while (!done) {
-		PRIV_UNLOCK (priv);
-		status = e_gw_connection_read_cal_ids (cnc, container_id, cursor, FALSE, CURSOR_ICALID_LIMIT, position, &item_list);
-		PRIV_LOCK (priv);
+		status = e_gw_connection_read_cal_ids (cnc, priv->container_id, cursor, FALSE, CURSOR_ICALID_LIMIT, position, &item_list);
 		if (status != E_GW_CONNECTION_STATUS_OK) {
 			if (status == E_GW_CONNECTION_STATUS_NO_RESPONSE) {
 				goto err_done;
@@ -585,9 +573,7 @@ get_deltas (gpointer handle)
 		position = E_GW_CURSOR_POSITION_CURRENT;
 
 	}
-	PRIV_UNLOCK (priv);
-	e_gw_connection_destroy_cursor (cnc, container_id, cursor);
-	PRIV_LOCK (priv);
+	e_gw_connection_destroy_cursor (cnc, priv->container_id, cursor);
 	e_cal_backend_store_freeze_changes (store);
 
 	uid_array = g_ptr_array_new ();
@@ -598,6 +584,8 @@ get_deltas (gpointer handle)
 
 		id = g_new0 (ECalComponentId, 1);
 
+		PRIV_LOCK (priv);
+		
 		if (calid->recur_key && calid->start_date) {
 			gchar *rid = NULL;
 
@@ -611,6 +599,8 @@ get_deltas (gpointer handle)
 			id->rid = rid;
 		} else
 			id->uid = g_strdup (calid->ical_id);
+		
+		PRIV_UNLOCK (priv);
 
 		if (!(remove = g_slist_find_custom (cache_ids, id,  (GCompareFunc) compare_ids))) {
 			g_ptr_array_add (uid_array, g_strdup (calid->item_id));
@@ -650,12 +640,10 @@ get_deltas (gpointer handle)
 	}
 
 	if (needs_to_get) {
-		PRIV_UNLOCK (priv);
 		e_gw_connection_get_items_from_ids (
-			cnc, container_id,
+			cnc, priv->container_id,
 			"attachments recipients message recipientStatus default peek",
 			uid_array, &item_list);
-		PRIV_LOCK (priv);
 
 		for (l = item_list; l != NULL; l = l->next) {
 			ECalComponent *comp = NULL;
@@ -687,8 +675,6 @@ get_deltas (gpointer handle)
 	g_ptr_array_free (uid_array, TRUE);
 
  err_done:
-	g_free (container_id);
-
 	if (item_list) {
 		g_list_free (item_list);
 		item_list = NULL;
@@ -704,7 +690,6 @@ get_deltas (gpointer handle)
 		g_slist_free (cache_ids);
 	}
 
-	PRIV_UNLOCK (priv);
 	return TRUE;
 }
 
@@ -1654,12 +1639,16 @@ e_cal_backend_groupwise_set_default_zone (ECalBackendSync *backend, EDataCal *ca
 	zone = icaltimezone_new ();
 	icaltimezone_set_component (zone, tz_comp);
 
+	PRIV_LOCK (priv);
+	
 	if (priv->default_zone)
 		icaltimezone_free (priv->default_zone, 1);
 
 	/* Set the default timezone to it. */
 	priv->default_zone = zone;
 
+	PRIV_UNLOCK (priv);
+
 	return GNOME_Evolution_Calendar_Success;
 }
 
@@ -1773,10 +1762,10 @@ e_cal_backend_groupwise_get_free_busy (ECalBackendSync *backend, EDataCal *cal,
 	       return GNOME_Evolution_Calendar_RepositoryOffline;
        }
 
-       status = e_gw_connection_get_freebusy_info (cnc, users, start, end, freebusy, cbgw->priv->default_zone);
+       status = e_gw_connection_get_freebusy_info (cbgw, users, start, end, freebusy);
 
        if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
-	       status = e_gw_connection_get_freebusy_info (cnc, users, start, end, freebusy, cbgw->priv->default_zone);
+	       status = e_gw_connection_get_freebusy_info (cbgw, users, start, end, freebusy);
 
        if (status != E_GW_CONNECTION_STATUS_OK)
                return GNOME_Evolution_Calendar_OtherError;
diff --git a/calendar/backends/groupwise/e-cal-backend-groupwise.h b/calendar/backends/groupwise/e-cal-backend-groupwise.h
index 2b74b78..939d5ef 100644
--- a/calendar/backends/groupwise/e-cal-backend-groupwise.h
+++ b/calendar/backends/groupwise/e-cal-backend-groupwise.h
@@ -63,6 +63,9 @@ GHashTable* e_cal_backend_groupwise_get_categories_by_name (ECalBackendGroupwise
 icaltimezone* e_cal_backend_groupwise_get_default_zone (ECalBackendGroupwise *cbgw);
 void    e_cal_backend_groupwise_notify_error_code (ECalBackendGroupwise *cbgw, EGwConnectionStatus status);
 const gchar * e_cal_backend_groupwise_get_local_attachments_store (ECalBackendGroupwise *cbgw);
+void e_cal_backend_groupwise_priv_lock (ECalBackendGroupwise *cbgw);
+void e_cal_backend_groupwise_priv_unlock (ECalBackendGroupwise *cbgw);
+
 G_END_DECLS
 
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]