Re: [evolution-patches] Fix for the bug #274409 [calendar]



Attached the modified patch. Added a static mutex lock. The timeout
function is called only for the calendar backend. But initially in the
open method get_deltas would be called for both the backends, so the
static mutex lock will prevent both the backends accessing the
get_deltas at the same time. 

thanks, chenthill.

On Wed, 2005-04-13 at 23:42 +0200, Rodrigo Moya wrote:
> On Wed, 2005-04-13 at 14:45 +0530, chenthill wrote:
> > Resending the patch. Running the get_deltas in seperate thread instead
> > of the main loop would be the right fix. Have attached the patch.
> > 
> also, another thing:
> 
> > +static gboolean
> > +get_deltas_timeout (gpointer cbgw)
> > +{
> > +       GThread *thread;
> > +       GError *error = NULL;
> > +
> > +       if (!cbgw)
> > +               return FALSE;
> > +
> > +       thread = g_thread_create ((GThreadFunc) get_deltas, cbgw,
> > FALSE, &error);
> > +       if (!thread) {
> > +               g_warning (G_STRLOC ": %s", error->message);
> > +               g_error_free (error);
> > +               
> > +               return GNOME_Evolution_Calendar_OtherError;
> > 
> the function is a gboolean, so you should return just TRUE or FALSE.
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/ChangeLog,v
retrieving revision 1.432.2.11
diff -u -p -r1.432.2.11 ChangeLog
--- ChangeLog	8 Apr 2005 16:16:04 -0000	1.432.2.11
+++ ChangeLog	14 Apr 2005 06:17:54 -0000
@@ -1,3 +1,12 @@
+2005-04-13  Chenthill Palanisamy  <pchenthill novell com>
+
+	Fixes #274409
+	* backends/groupwise/e-cal-backend-groupwise.c:
+	(get_deltas_timeout), (cache_init), (connect_to_server):
+	Run the get_deltas in a seperate thread instead of the main
+	loop.
+	(get_deltas): Added a static mutex lock.
+
 2005-04-08  Rodrigo Moya <rodrigo novell com>
 
 	* libecal/e-cal-util.h: added new function's prototype.
Index: backends/groupwise/e-cal-backend-groupwise.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/backends/groupwise/e-cal-backend-groupwise.c,v
retrieving revision 1.136.2.4
diff -u -p -r1.136.2.4 e-cal-backend-groupwise.c
--- backends/groupwise/e-cal-backend-groupwise.c	6 Apr 2005 15:12:09 -0000	1.136.2.4
+++ backends/groupwise/e-cal-backend-groupwise.c	14 Apr 2005 06:17:55 -0000
@@ -197,6 +197,7 @@ get_deltas (gpointer handle)
 	char *time_string = NULL;
 	char t_str [100]; 
 	struct stat buf;
+	static GStaticMutex connecting = G_STATIC_MUTEX_INIT;
         
 	if (!handle)
 		return FALSE;
@@ -210,6 +211,8 @@ get_deltas (gpointer handle)
 	if (priv->mode == CAL_MODE_LOCAL)
 		return FALSE;
 
+	g_static_mutex_lock (&connecting);
+
 	g_strlcpy (t_str, e_cal_backend_cache_get_server_utc_time (cache), 100);
 	if (!*t_str || !strcmp (t_str, "")) {
 		icaltimetype temp;
@@ -231,10 +234,13 @@ get_deltas (gpointer handle)
 	
 	if (status != E_GW_CONNECTION_STATUS_OK) {
 				
-		if (status == E_GW_CONNECTION_STATUS_NO_RESPONSE) 
+		if (status == E_GW_CONNECTION_STATUS_NO_RESPONSE) {
+			g_static_mutex_unlock (&connecting);
 			return TRUE;
+		}
 
 		e_cal_backend_groupwise_notify_error_code (cbgw, status);
+		g_static_mutex_unlock (&connecting);
 		return TRUE;
 	}
 	/* store the timestamp in the cache */	
@@ -282,10 +288,13 @@ get_deltas (gpointer handle)
 		
 	g_free (time_string);
 	if (status != E_GW_CONNECTION_STATUS_OK) {
-		if (status == E_GW_CONNECTION_STATUS_NO_RESPONSE) 
+		if (status == E_GW_CONNECTION_STATUS_NO_RESPONSE) { 
+			g_static_mutex_unlock (&connecting);
 			return TRUE;
+		}
 
 		e_cal_backend_groupwise_notify_error_code (cbgw, status);
+		g_static_mutex_unlock (&connecting);
 		return TRUE;
 	}
 
@@ -328,10 +337,13 @@ get_deltas (gpointer handle)
 		status = e_gw_connection_get_quick_messages (cnc, cbgw->priv->container_id, "iCalId", NULL, "All", "CalendarItem", NULL,  -1,  &item_list);
 
 	if (status != E_GW_CONNECTION_STATUS_OK) {
-		if (status == E_GW_CONNECTION_STATUS_NO_RESPONSE) 
+		if (status == E_GW_CONNECTION_STATUS_NO_RESPONSE) {
+			g_static_mutex_unlock (&connecting);
 			return TRUE;
+		}
 
 		e_cal_backend_groupwise_notify_error_code (cbgw, status);
+		g_static_mutex_unlock (&connecting);
 		return TRUE;
 	}
 
@@ -378,10 +390,33 @@ get_deltas (gpointer handle)
 		g_slist_free (cache_keys);
 		item_list = NULL;
 	}
+	
+	g_static_mutex_unlock (&connecting);
 		
         return TRUE;        
 }
 
+static gboolean
+get_deltas_timeout (gpointer cbgw)
+{
+	GThread *thread;
+	GError *error = NULL;
+
+	if (!cbgw)
+		return FALSE;
+
+	thread = g_thread_create ((GThreadFunc) get_deltas, cbgw, FALSE, &error);
+	if (!thread) {
+		g_warning (G_STRLOC ": %s", error->message);
+		g_error_free (error);
+		
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+
 static char* 
 form_uri (ESource *source)
 {
@@ -468,7 +503,7 @@ cache_init (ECalBackendGroupwise *cbgw)
 
 			/*  Set up deltas only if it is a Calendar backend */
 			if (kind == ICAL_VEVENT_COMPONENT)
-				priv->timeout_id = g_timeout_add (time_interval, (GSourceFunc) get_deltas, (gpointer) cbgw);
+				priv->timeout_id = g_timeout_add (time_interval, (GSourceFunc) get_deltas_timeout, (gpointer) cbgw);
 			priv->mode = CAL_MODE_REMOTE;
 			return GNOME_Evolution_Calendar_Success;
 		}
@@ -495,7 +530,7 @@ cache_init (ECalBackendGroupwise *cbgw)
 		/* get the deltas from the cache */
 		if (get_deltas (cbgw)) {
 			if (kind == ICAL_VEVENT_COMPONENT)
-				priv->timeout_id = g_timeout_add (time_interval, (GSourceFunc) get_deltas, (gpointer) cbgw);
+				priv->timeout_id = g_timeout_add (time_interval, (GSourceFunc) get_deltas_timeout, (gpointer) cbgw);
 			priv->mode = CAL_MODE_REMOTE;
 			return GNOME_Evolution_Calendar_Success;
 		} else {
@@ -559,7 +594,7 @@ connect_to_server (ECalBackendGroupwise 
 
 					return GNOME_Evolution_Calendar_OtherError;
 				}
-				priv->timeout_id = g_timeout_add (CACHE_REFRESH_INTERVAL, (GSourceFunc) get_deltas, (gpointer) cbgw);
+				priv->timeout_id = g_timeout_add (CACHE_REFRESH_INTERVAL, (GSourceFunc) get_deltas_timeout, (gpointer)cbgw);
 
 			}
 	


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