From eb0d9537d6b49be40684e31915ce44a889aecd15 Mon Sep 17 00:00:00 2001 From: Rodrigo Moya Date: Thu, 27 Jan 2005 12:55:32 +0000 Subject: [PATCH] added a GMutex for the idle saving callback. (save_file_when_idle, save): 2005-01-27 Rodrigo Moya * backends/file/e-cal-backend-file.c: added a GMutex for the idle saving callback. (save_file_when_idle, save): lock/unlock the mutex while setting values. (e_cal_backend_file_finalize): unref the mutex. (e_cal_backend_file_init): create the mutex. --- calendar/ChangeLog | 8 ++++++++ calendar/backends/file/e-cal-backend-file.c | 26 ++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 5ea070b..30cd6bf 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,11 @@ +2005-01-27 Rodrigo Moya + + * backends/file/e-cal-backend-file.c: added a GMutex for the idle saving + callback. + (save_file_when_idle, save): lock/unlock the mutex while setting values. + (e_cal_backend_file_finalize): unref the mutex. + (e_cal_backend_file_init): create the mutex. + 2005-01-26 Rodrigo Moya * backends/file/e-cal-backend-file.c (add_component): save the file diff --git a/calendar/backends/file/e-cal-backend-file.c b/calendar/backends/file/e-cal-backend-file.c index f06f830..070eae3 100644 --- a/calendar/backends/file/e-cal-backend-file.c +++ b/calendar/backends/file/e-cal-backend-file.c @@ -61,6 +61,8 @@ struct _ECalBackendFilePrivate { gboolean is_dirty; guint dirty_idle_id; + GMutex *idle_save_mutex; + /* Toplevel VCALENDAR component */ icalcomponent *icalcomp; @@ -122,8 +124,12 @@ save_file_when_idle (gpointer user_data) g_assert (priv->uri != NULL); g_assert (priv->icalcomp != NULL); - if (!priv->is_dirty) + g_mutex_lock (priv->idle_save_mutex); + if (!priv->is_dirty) { + priv->dirty_idle_id = 0; + g_mutex_unlock (priv->idle_save_mutex); return FALSE; + } uri = gnome_vfs_uri_new (priv->uri); if (!uri) @@ -176,14 +182,18 @@ save_file_when_idle (gpointer user_data) priv->is_dirty = FALSE; priv->dirty_idle_id = 0; + g_mutex_unlock (priv->idle_save_mutex); + return FALSE; error_malformed_uri: + g_mutex_unlock (priv->idle_save_mutex); e_cal_backend_notify_error (E_CAL_BACKEND (cbfile), _("Can't save calendar data: Malformed URI.")); return TRUE; error: + g_mutex_unlock (priv->idle_save_mutex); e_cal_backend_notify_error (E_CAL_BACKEND (cbfile), gnome_vfs_result_to_string (result)); return TRUE; } @@ -195,11 +205,13 @@ save (ECalBackendFile *cbfile) priv = cbfile->priv; - if (!priv->dirty_idle_id) { + g_mutex_lock (priv->idle_save_mutex); + priv->is_dirty = TRUE; + + if (!priv->dirty_idle_id) priv->dirty_idle_id = g_idle_add ((GSourceFunc) save_file_when_idle, cbfile); - } - priv->is_dirty = TRUE; + g_mutex_unlock (priv->idle_save_mutex); } static void @@ -270,6 +282,11 @@ e_cal_backend_file_finalize (GObject *object) priv->dirty_idle_id = 0; } + if (priv->idle_save_mutex) { + g_mutex_free (priv->idle_save_mutex); + priv->idle_save_mutex = NULL; + } + if (priv->uri) { g_free (priv->uri); priv->uri = NULL; @@ -2458,6 +2475,7 @@ e_cal_backend_file_init (ECalBackendFile *cbfile, ECalBackendFileClass *class) priv->read_only = FALSE; priv->is_dirty = FALSE; priv->dirty_idle_id = 0; + priv->idle_save_mutex = g_mutex_new (); priv->icalcomp = NULL; priv->comp_uid_hash = NULL; priv->comp = NULL; -- 2.7.4