Blob Blame History Raw
--- /dev/null	2007-05-24 18:15:54.361082488 -0400
+++ evolution-data-server-1.10.2/libedataserver/e-flag.c	2007-05-28 19:24:40.000000000 -0400
@@ -0,0 +1,171 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* 
+ * Copyright (C) 2007 Novell, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "e-flag.h"
+
+struct _EFlag {
+	GCond *cond;
+	GMutex *mutex;
+	gboolean is_set;
+};
+
+/**
+ * e_flag_new:
+ *
+ * Creates a new #EFlag object.  It is initially unset.
+ *
+ * Returns: a new #EFlag
+ **/
+EFlag *
+e_flag_new (void)
+{
+	EFlag *flag;
+
+	flag = g_slice_new (EFlag);
+	flag->cond = g_cond_new ();
+	flag->mutex = g_mutex_new ();
+	flag->is_set = FALSE;
+
+	return flag;
+}
+
+/**
+ * e_flag_is_set:
+ * @flag: an #EFlag
+ *
+ * Returns the state of @flag.
+ *
+ * Returns: %TRUE if @flag is set
+ **/
+gboolean
+e_flag_is_set (EFlag *flag)
+{
+	gboolean is_set;
+
+	g_return_val_if_fail (flag != NULL, FALSE);
+
+	g_mutex_lock (flag->mutex);
+	is_set = flag->is_set;
+	g_mutex_unlock (flag->mutex);
+
+	return is_set;
+}
+
+/**
+ * e_flag_set:
+ * @flag: an #EFlag
+ *
+ * Sets @flag.  All threads waiting on @flag are woken up.  Threads that
+ * call e_flag_wait() or e_flag_timed_wait() once @flag is set will not
+ * block at all.
+ **/
+void
+e_flag_set (EFlag *flag)
+{
+	g_return_if_fail (flag != NULL);
+
+	g_mutex_lock (flag->mutex);
+	flag->is_set = TRUE;
+	g_cond_broadcast (flag->cond);
+	g_mutex_unlock (flag->mutex);
+}
+
+/**
+ * e_flag_clear:
+ * @flag: an #EFlag
+ *
+ * Unsets @flag.  Subsequent calls to e_flag_wait() or e_flag_timed_wait()
+ * will block until @flag is set.
+ **/
+void
+e_flag_clear (EFlag *flag)
+{
+	g_return_if_fail (flag != NULL);
+
+	g_mutex_lock (flag->mutex);
+	flag->is_set = FALSE;
+	g_mutex_unlock (flag->mutex);
+}
+
+/**
+ * e_flag_wait:
+ * @flag: an #EFlag
+ *
+ * Blocks until @flag is set.  If @flag is already set, the function returns
+ * immediately.
+ **/
+void
+e_flag_wait (EFlag *flag)
+{
+	g_return_if_fail (flag != NULL);
+
+	g_mutex_lock (flag->mutex);
+	while (!flag->is_set)
+		g_cond_wait (flag->cond, flag->mutex);
+	g_mutex_unlock (flag->mutex);
+}
+
+/**
+ * e_flag_timed_wait:
+ * @flag: an #EFlag
+ * @abs_time: a #GTimeVal, determining the final time
+ *
+ * Blocks until @flag is set, or until the time specified by @abs_time.
+ * If @flag is already set, the function returns immediately.  The return
+ * value indicates the state of @flag after waiting.
+ *
+ * If @abs_time is %NULL, e_flag_timed_wait() acts like e_flag_wait().
+ *
+ * To easily calculate @abs_time, a combination of g_get_current_time() and
+ * g_time_val_add() can be used.
+ *
+ * Returns: %TRUE if @flag is now set
+ **/
+gboolean
+e_flag_timed_wait (EFlag *flag, GTimeVal *abs_time)
+{
+	gboolean is_set;
+
+	g_return_val_if_fail (flag != NULL, FALSE);
+
+	g_mutex_lock (flag->mutex);
+	while (!flag->is_set)
+		if (!g_cond_timed_wait (flag->cond, flag->mutex, abs_time))
+			break;
+	is_set = flag->is_set;
+	g_mutex_unlock (flag->mutex);
+
+	return is_set;
+}
+
+/**
+ * e_flag_free:
+ * @flag: an #EFlag
+ *
+ * Destroys @flag.
+ **/
+void
+e_flag_free (EFlag *flag)
+{
+	g_return_if_fail (flag != NULL);
+
+	g_cond_free (flag->cond);
+	g_mutex_free (flag->mutex);
+	g_slice_free (EFlag, flag);
+}
--- /dev/null	2007-05-24 18:15:54.361082488 -0400
+++ evolution-data-server-1.10.2/libedataserver/e-flag.h	2007-05-28 19:24:40.000000000 -0400
@@ -0,0 +1,43 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* 
+ * Copyright (C) 2007 Novell, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef E_FLAG_H
+#define E_FLAG_H
+
+/* An EFlag is essentially a binary semaphore with a more intuitive interface.
+ * Based on Python's threading.Event class ("EEvent" was already taken). */
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct _EFlag EFlag;
+
+EFlag *		e_flag_new			(void);
+gboolean	e_flag_is_set			(EFlag *flag);
+void		e_flag_set			(EFlag *flag);
+void		e_flag_clear			(EFlag *flag);
+void		e_flag_wait			(EFlag *flag);
+gboolean	e_flag_timed_wait		(EFlag *flag,
+						 GTimeVal *abs_time);
+void		e_flag_free			(EFlag *flag);
+
+G_END_DECLS
+
+#endif /* E_FLAG_H */
--- evolution-data-server-1.10.2/libedataserver/Makefile.in.e-flag	2007-05-28 03:48:00.000000000 -0400
+++ evolution-data-server-1.10.2/libedataserver/Makefile.in	2007-05-28 19:24:40.000000000 -0400
@@ -69,7 +69,7 @@
 am_libedataserver_1_2_la_OBJECTS = $(am__objects_1) e-account-list.lo \
 	e-account.lo e-categories.lo e-component-listener.lo \
 	e-data-server-module.lo e-dbhash.lo e-db3-utils.lo \
-	e-file-cache.lo e-iconv.lo e-iterator.lo e-list.lo \
+	e-file-cache.lo e-flag.lo e-iconv.lo e-iterator.lo e-list.lo \
 	e-list-iterator.lo e-memory.lo e-msgport.lo e-sexp.lo \
 	e-source-group.lo e-source-list.lo e-source.lo e-time-utils.lo \
 	e-uid.lo e-url.lo e-data-server-util.lo e-trie.lo \
@@ -422,6 +422,7 @@
 	e-dbhash.c			\
 	e-db3-utils.c			\
 	e-file-cache.c			\
+	e-flag.c			\
 	e-iconv.c			\
 	e-iterator.c			\
 	e-list.c			\
@@ -461,6 +462,7 @@
 	e-db3-utils.h			\
 	e-dbhash.h			\
 	e-file-cache.h			\
+	e-flag.h			\
 	e-iconv.h			\
 	e-iterator.h			\
 	e-list.h			\
@@ -579,6 +581,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e-db3-utils.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e-dbhash.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e-file-cache.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e-flag.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e-iconv.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e-iterator.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e-list-iterator.Plo@am__quote@
--- evolution-data-server-1.10.2/libedataserver/Makefile.am.e-flag	2007-04-09 08:42:55.000000000 -0400
+++ evolution-data-server-1.10.2/libedataserver/Makefile.am	2007-05-28 19:24:40.000000000 -0400
@@ -26,6 +26,7 @@
 	e-dbhash.c			\
 	e-db3-utils.c			\
 	e-file-cache.c			\
+	e-flag.c			\
 	e-iconv.c			\
 	e-iterator.c			\
 	e-list.c			\
@@ -66,6 +67,7 @@
 	e-db3-utils.h			\
 	e-dbhash.h			\
 	e-file-cache.h			\
+	e-flag.h			\
 	e-iconv.h			\
 	e-iterator.h			\
 	e-list.h			\
--- evolution-data-server-1.10.2/addressbook/backends/file/e-book-backend-file.c.e-flag	2007-04-09 08:42:57.000000000 -0400
+++ evolution-data-server-1.10.2/addressbook/backends/file/e-book-backend-file.c	2007-05-28 19:24:40.000000000 -0400
@@ -43,6 +43,7 @@
 #include "libedataserver/e-dbhash.h"
 #include "libedataserver/e-db3-utils.h"
 #include "libedataserver/e-data-server-util.h"
+#include "libedataserver/e-flag.h"
 
 #include "libebook/e-contact.h"
 
@@ -479,18 +480,15 @@
 
 typedef struct {
 	EBookBackendFile *bf;
-	GMutex *mutex;
-	GCond *cond;
 	GThread *thread;
-	gboolean stopped;
+	EFlag *running;
 } FileBackendSearchClosure;
 
 static void
 closure_destroy (FileBackendSearchClosure *closure)
 {
 	d(printf ("destroying search closure\n"));
-	g_mutex_free (closure->mutex);
-	g_cond_free (closure->cond);
+	e_flag_free (closure->running);
 	g_free (closure);
 }
 
@@ -500,10 +498,8 @@
 	FileBackendSearchClosure *closure = g_new (FileBackendSearchClosure, 1);
 
 	closure->bf = bf;
-	closure->mutex = g_mutex_new ();
-	closure->cond = g_cond_new ();
 	closure->thread = NULL;
-	closure->stopped = FALSE;
+	closure->running = e_flag_new ();
 
 	g_object_set_data_full (G_OBJECT (book_view), "EBookBackendFile.BookView::closure",
 				closure, (GDestroyNotify)closure_destroy);
@@ -527,7 +523,7 @@
 	DB  *db;
 	DBT id_dbt, vcard_dbt;
 	int db_error;
-	gboolean stopped = FALSE, allcontacts;
+	gboolean allcontacts;
 
 	d(printf ("starting initial population of book view\n"));
 
@@ -547,9 +543,7 @@
 	}
 
 	d(printf ("signalling parent thread\n"));
-	g_mutex_lock (closure->mutex);
-	g_cond_signal (closure->cond);
-	g_mutex_unlock (closure->mutex);
+	e_flag_set (closure->running);
 
 	if (e_book_backend_summary_is_summary_query (bf->priv->summary, query)) {
 		/* do a summary query */
@@ -558,11 +552,8 @@
 
 		for (i = 0; i < ids->len; i ++) {
 			char *id = g_ptr_array_index (ids, i);
-			g_mutex_lock (closure->mutex);
-			stopped = closure->stopped;
-			g_mutex_unlock (closure->mutex);
 
-			if (stopped)
+			if (!e_flag_is_set (closure->running))
 				break;
 
 			string_to_dbt (id, &id_dbt);
@@ -595,11 +586,7 @@
 			db_error = dbc->c_get(dbc, &id_dbt, &vcard_dbt, DB_FIRST);
 			while (db_error == 0) {
 
-				g_mutex_lock (closure->mutex);
-				stopped = closure->stopped;
-				g_mutex_unlock (closure->mutex);
-
-				if (stopped)
+				if (!e_flag_is_set (closure->running))
 					break;
 
 				/* don't include the version in the list of cards */
@@ -628,7 +615,7 @@
 
 	}
 
-	if (!stopped)
+	if (e_flag_is_set (closure->running))
 		e_data_book_view_notify_complete (book_view, GNOME_Evolution_Addressbook_Success);
 
 	/* unref the */
@@ -646,15 +633,12 @@
 {
 	FileBackendSearchClosure *closure = init_closure (book_view, E_BOOK_BACKEND_FILE (backend));
 
-	g_mutex_lock (closure->mutex);
-
 	d(printf ("starting book view thread\n"));
 	closure->thread = g_thread_create (book_view_thread, book_view, TRUE, NULL);
 
-	g_cond_wait (closure->cond, closure->mutex);
+	e_flag_wait (closure->running);
 
 	/* at this point we know the book view thread is actually running */
-	g_mutex_unlock (closure->mutex);
 	d(printf ("returning from start_book_view\n"));
 }
 
@@ -663,14 +647,11 @@
 				    EDataBookView *book_view)
 {
 	FileBackendSearchClosure *closure = get_closure (book_view);
-	gboolean need_join = FALSE;
+	gboolean need_join;
 
 	d(printf ("stopping query\n"));
-	g_mutex_lock (closure->mutex);
-	if (!closure->stopped)
-		need_join = TRUE;
-	closure->stopped = TRUE;
-	g_mutex_unlock (closure->mutex);
+	need_join = e_flag_is_set (closure->running);
+	e_flag_clear (closure->running);
 
 	if (need_join)
 		g_thread_join (closure->thread);
--- evolution-data-server-1.10.2/addressbook/backends/groupwise/e-book-backend-groupwise.c.e-flag	2007-04-09 08:42:58.000000000 -0400
+++ evolution-data-server-1.10.2/addressbook/backends/groupwise/e-book-backend-groupwise.c	2007-05-28 19:24:40.000000000 -0400
@@ -40,6 +40,7 @@
 #include "libedataserver/e-sexp.h"
 #include "libedataserver/e-data-server-util.h"
 #include "libedataserver/e-db3-utils.h"
+#include "libedataserver/e-flag.h"
 #include "libedataserver/e-url.h" 
 #include "libebook/e-contact.h"
 #include "libedata-book/e-book-backend-sexp.h"
@@ -2070,17 +2071,14 @@
 	
 typedef struct {
 	EBookBackendGroupwise *bg;
-	GMutex *mutex;
-	GCond *cond;
 	GThread *thread;
-	gboolean stopped;
+	EFlag *running;
 } GroupwiseBackendSearchClosure;
 
 static void
 closure_destroy (GroupwiseBackendSearchClosure *closure)
 {
-	g_mutex_free (closure->mutex);
-	g_cond_free (closure->cond);
+	e_flag_free (closure->running);
 	g_free (closure);
 }
 
@@ -2090,10 +2088,8 @@
 	GroupwiseBackendSearchClosure *closure = g_new (GroupwiseBackendSearchClosure, 1);
 
 	closure->bg = bg;
-	closure->mutex = g_mutex_new ();
-	closure->cond = g_cond_new ();
 	closure->thread = NULL;
-	closure->stopped = FALSE;
+	closure->running = e_flag_new ();
 
 	g_object_set_data_full (G_OBJECT (book_view), "EBookBackendGroupwise.BookView::closure",
 				closure, (GDestroyNotify)closure_destroy);
@@ -2115,19 +2111,14 @@
 			 GroupwiseBackendSearchClosure *closure)
 {
 	int i;
-	gboolean stopped = FALSE;
 
 	if (enable_debug)
 		printf ("\nread contacts from cache for the ids found in summary\n");
 	for (i = 0; i < ids->len; i ++) {
 		char *uid = g_ptr_array_index (ids, i);
 
-		g_mutex_lock (closure->mutex);
-		stopped = closure->stopped;
-		g_mutex_unlock (closure->mutex);
-
-		if (stopped)
-			break;	
+		if (!e_flag_is_set (closure->running))
+			break;
 
 		EContact *contact = 
 			e_book_backend_db_cache_get_contact (ebgw->priv->file_db, uid);
@@ -2136,7 +2127,7 @@
 			g_object_unref (contact);
 		}
 	}
-	if (!stopped)
+	if (e_flag_is_set (closure->running))
 		e_data_book_view_notify_complete (book_view, 
 						  GNOME_Evolution_Addressbook_Success);
 }
@@ -2151,7 +2142,6 @@
 	const char *query = NULL;
 	EGwFilter *filter = NULL;
 	GPtrArray *ids = NULL;
-	gboolean stopped = FALSE;
 	EDataBookView *book_view = data;
 	GroupwiseBackendSearchClosure *closure = get_closure (book_view);
 	char *view = NULL;
@@ -2166,9 +2156,7 @@
 	if (enable_debug)
 		printf ("start book view for %s \n", gwb->priv->book_name);
        	bonobo_object_ref (book_view);
-	g_mutex_lock (closure->mutex);
-	g_cond_signal (closure->cond);
-	g_mutex_unlock (closure->mutex);
+	e_flag_set (closure->running);
 	
 	query = e_data_book_view_get_card_query (book_view);
 	if (enable_debug)
@@ -2200,10 +2188,7 @@
 		contacts = e_book_backend_db_cache_get_contacts (gwb->priv->file_db, query);
 		temp_list = contacts;
 		for (; contacts != NULL; contacts = g_list_next(contacts)) {
-			g_mutex_lock (closure->mutex);
-			stopped = closure->stopped;
-			g_mutex_unlock (closure->mutex);
-			if (stopped) {
+			if (!e_flag_is_set (closure->running)) {
 				for (;contacts != NULL; contacts = g_list_next (contacts))
 					g_object_unref (contacts->data);
 				break;
@@ -2211,7 +2196,7 @@
 			e_data_book_view_notify_update (book_view, E_CONTACT(contacts->data));
 			g_object_unref (contacts->data);
 		}
-		if (!stopped)
+		if (e_flag_is_set (closure->running))
 			e_data_book_view_notify_complete (book_view, GNOME_Evolution_Addressbook_Success);
 		if (temp_list)
 			g_list_free (temp_list);
@@ -2339,10 +2324,7 @@
 		temp_list = gw_items;
 		for (; gw_items != NULL; gw_items = g_list_next(gw_items)) { 
 
-			g_mutex_lock (closure->mutex);
-			stopped = closure->stopped;
-			g_mutex_unlock (closure->mutex);
-			if (stopped) {
+			if (!e_flag_is_set (closure->running)) {
 				for (;gw_items != NULL; gw_items = g_list_next (gw_items))
 					g_object_unref (gw_items->data);
 				break;
@@ -2363,7 +2345,7 @@
 		}
 		if (temp_list)
 			g_list_free (temp_list);
-		if (!stopped)
+		if (e_flag_is_set (closure->running))
 			e_data_book_view_notify_complete (book_view, GNOME_Evolution_Addressbook_Success);
 		if (filter)
 			g_object_unref (filter);
@@ -2392,12 +2374,10 @@
 
 	if (enable_debug)
 		printf ("\ne_book_backend_groupwise_start_book_view...\n");
-	g_mutex_lock (closure->mutex);
 	closure->thread = g_thread_create (book_view_thread, book_view, FALSE, NULL);
-	g_cond_wait (closure->cond, closure->mutex);
+	e_flag_wait (closure->running);
 	
 	/* at this point we know the book view thread is actually running */
-	g_mutex_unlock (closure->mutex);
 }
   
 static void
@@ -2408,10 +2388,7 @@
 	
 	if (enable_debug)
 		printf ("\ne_book_backend_groupwise_stop_book_view...\n");
-	g_mutex_lock (closure->mutex);
-	if (!closure->stopped)
-		closure->stopped = TRUE;
-	g_mutex_unlock (closure->mutex);
+	e_flag_clear (closure->running);
 }
 
 static void
@@ -2650,11 +2627,8 @@
 	if (book_view) {
 		closure = get_closure (book_view);
 		bonobo_object_ref (book_view);
-		if (closure) {
-			g_mutex_lock (closure->mutex);
-			g_cond_signal (closure->cond);
-			g_mutex_unlock (closure->mutex);
-		}
+		if (closure)
+			e_flag_set (closure->running);
 	}
 
 	while (!done) {
@@ -2799,11 +2773,8 @@
 	if (book_view) {
 		closure = get_closure (book_view);
 		bonobo_object_ref (book_view);
-		if (closure) {
-			g_mutex_lock (closure->mutex);
-			g_cond_signal (closure->cond);
-			g_mutex_unlock (closure->mutex);
-		}
+		if (closure)
+			e_flag_set (closure->running);
 	}
 
 	cache_file_name = e_book_backend_db_cache_get_filename(ebgw->priv->file_db);
@@ -2967,11 +2938,8 @@
 	if (book_view) {
 		closure = get_closure (book_view);
 		bonobo_object_ref (book_view);
-		if (closure){
-			g_mutex_lock (closure->mutex);
-			g_cond_signal (closure->cond);
-			g_mutex_unlock (closure->mutex);
-		}
+		if (closure)
+			e_flag_set (closure->running);
 	}
 
 	/* update the cache */
--- evolution-data-server-1.10.2/addressbook/backends/vcf/e-book-backend-vcf.c.e-flag	2007-04-09 08:42:58.000000000 -0400
+++ evolution-data-server-1.10.2/addressbook/backends/vcf/e-book-backend-vcf.c	2007-05-28 19:24:40.000000000 -0400
@@ -41,6 +41,7 @@
 #include <glib/gi18n-lib.h>
 
 #include "libedataserver/e-data-server-util.h"
+#include "libedataserver/e-flag.h"
 
 #include "libebook/e-contact.h"
  
@@ -427,18 +428,15 @@
 typedef struct {
 	EBookBackendVCF *bvcf;
 	EDataBookView *view;
-	GMutex *mutex;
-	GCond *cond;
 	GThread *thread;
-	gboolean stopped;
+	EFlag *running;
 } VCFBackendSearchClosure;
 
 static void
 closure_destroy (VCFBackendSearchClosure *closure)
 {
 	d(printf ("destroying search closure\n"));
-	g_mutex_free (closure->mutex);
-	g_cond_free (closure->cond);
+	e_flag_free (closure->running);
 	g_free (closure);
 }
 
@@ -449,10 +447,8 @@
 
 	closure->bvcf = bvcf;
 	closure->view = book_view;
-	closure->mutex = g_mutex_new ();
-	closure->cond = g_cond_new ();
 	closure->thread = NULL;
-	closure->stopped = FALSE;
+	closure->running = e_flag_new ();
 
 	g_object_set_data_full (G_OBJECT (book_view), "EBookBackendVCF.BookView::closure",
 				closure, (GDestroyNotify)closure_destroy);
@@ -486,9 +482,7 @@
 		e_data_book_view_notify_status_message (book_view, _("Searching..."));
 
 	d(printf ("signalling parent thread\n"));
-	g_mutex_lock (closure->mutex);
-	g_cond_signal (closure->cond);
-	g_mutex_unlock (closure->mutex);
+	e_flag_set (closure->running);
 
 	for (l = closure->bvcf->priv->contact_list; l; l = l->next) {
 		char *vcard_string = l->data;
@@ -496,11 +490,11 @@
 		e_data_book_view_notify_update (closure->view, contact);
 		g_object_unref (contact);
 
-		if (closure->stopped)
+		if (!e_flag_is_set (closure->running))
 			break;
 	}
 
-	if (!closure->stopped)
+	if (e_flag_is_set (closure->running))
 		e_data_book_view_notify_complete (closure->view, GNOME_Evolution_Addressbook_Success);
 
 	/* unref the book view */
@@ -518,15 +512,12 @@
 {
 	VCFBackendSearchClosure *closure = init_closure (book_view, E_BOOK_BACKEND_VCF (backend));
 
-	g_mutex_lock (closure->mutex);
-
 	d(printf ("starting book view thread\n"));
 	closure->thread = g_thread_create (book_view_thread, book_view, TRUE, NULL);
 
-	g_cond_wait (closure->cond, closure->mutex);
+	e_flag_wait (closure->running);
 
 	/* at this point we know the book view thread is actually running */
-	g_mutex_unlock (closure->mutex);
 	d(printf ("returning from start_book_view\n"));
 
 }
@@ -536,14 +527,11 @@
 				   EDataBookView *book_view)
 {
 	VCFBackendSearchClosure *closure = get_closure (book_view);
-	gboolean need_join = FALSE;
+	gboolean need_join;
 
 	d(printf ("stopping query\n"));
-	g_mutex_lock (closure->mutex);
-	if (!closure->stopped)
-		need_join = TRUE;
-	closure->stopped = TRUE;
-	g_mutex_unlock (closure->mutex);
+	need_join = e_flag_is_set (closure->running);
+	e_flag_clear (closure->running);
 
 	if (need_join)
 		g_thread_join (closure->thread);
--- evolution-data-server-1.10.2/docs/reference/libedataserver/libedataserver-docs.sgml.e-flag	2007-04-09 08:42:50.000000000 -0400
+++ evolution-data-server-1.10.2/docs/reference/libedataserver/libedataserver-docs.sgml	2007-05-28 19:24:40.000000000 -0400
@@ -16,6 +16,7 @@
     <xi:include href="xml/e-db3-utils.xml"/>
     <xi:include href="xml/e-dbhash.xml"/>
     <xi:include href="xml/e-file-cache.xml"/>
+    <xi:include href="xml/e-flag.xml"/>
     <xi:include href="xml/e-iconv.xml"/>
     <xi:include href="xml/e-iterator.xml"/>
     <xi:include href="xml/e-list.xml"/>
--- /dev/null	2007-05-24 18:15:54.361082488 -0400
+++ evolution-data-server-1.10.2/docs/reference/libedataserver/tmpl/e-flag.sgml	2007-05-28 19:24:40.000000000 -0400
@@ -0,0 +1,89 @@
+<!-- ##### SECTION Title ##### -->
+EFlag
+
+<!-- ##### SECTION Short_Description ##### -->
+Simple thread synchronization
+
+<!-- ##### SECTION Long_Description ##### -->
+<para>
+An #EFlag is a simple thread synchronization mechanism. It implements a
+thread-safe flag that can be blocked on.
+</para>
+
+
+<!-- ##### SECTION See_Also ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### SECTION Stability_Level ##### -->
+
+
+<!-- ##### STRUCT EFlag ##### -->
+<para>
+The <structname>EFlag</structname> struct is an opaque data structure
+representing a thread-safe flag.  It should be accessed only by using
+the following functions.
+</para>
+
+
+<!-- ##### FUNCTION e_flag_new ##### -->
+<para>
+
+</para>
+
+@Returns: 
+
+
+<!-- ##### FUNCTION e_flag_is_set ##### -->
+<para>
+
+</para>
+
+@flag: 
+@Returns: 
+
+
+<!-- ##### FUNCTION e_flag_set ##### -->
+<para>
+
+</para>
+
+@flag: 
+
+
+<!-- ##### FUNCTION e_flag_clear ##### -->
+<para>
+
+</para>
+
+@flag: 
+
+
+<!-- ##### FUNCTION e_flag_wait ##### -->
+<para>
+
+</para>
+
+@flag: 
+
+
+<!-- ##### FUNCTION e_flag_timed_wait ##### -->
+<para>
+
+</para>
+
+@flag: 
+@abs_time: 
+@Returns: 
+
+
+<!-- ##### FUNCTION e_flag_free ##### -->
+<para>
+
+</para>
+
+@flag: 
+
+
--- evolution-data-server-1.10.2/docs/reference/libedataserver/libedataserver-sections.txt.e-flag	2007-04-09 08:42:50.000000000 -0400
+++ evolution-data-server-1.10.2/docs/reference/libedataserver/libedataserver-sections.txt	2007-05-28 19:24:40.000000000 -0400
@@ -109,6 +109,19 @@
 </SECTION>
 
 <SECTION>
+<FILE>e-flag</FILE>
+<TITLE>EFlag</TITLE>
+EFlag
+e_flag_new
+e_flag_is_set
+e_flag_set
+e_flag_clear
+e_flag_wait
+e_flag_timed_wait
+e_flag_free
+</SECTION>
+
+<SECTION>
 <FILE>e-iterator</FILE>
 <TITLE>EIterator</TITLE>
 EIterator
--- evolution-data-server-1.10.2/calendar/libecal/e-cal.c.e-flag	2007-05-25 02:42:39.000000000 -0400
+++ evolution-data-server-1.10.2/calendar/libecal/e-cal.c	2007-05-28 19:26:08.000000000 -0400
@@ -33,6 +33,7 @@
 #include <bonobo/bonobo-main.h>
 
 #include <libedataserver/e-component-listener.h>
+#include <libedataserver/e-flag.h>
 #include <libedataserver/e-url.h>
 #include "e-cal-marshal.h"
 #include "e-cal-time-util.h"
@@ -49,8 +50,7 @@
 
 
 typedef struct {
-	GMutex *mutex;
-	GCond *cond;
+	EFlag *done;
 	ECalendarStatus status;
 
 	char *uid;
@@ -303,8 +303,7 @@
 {
 	ECalendarOp *op = g_new0 (ECalendarOp, 1);
 
-	op->mutex = g_mutex_new ();
-	op->cond = g_cond_new ();
+	op->done = e_flag_new ();
 
 	ecal->priv->current_op = op;
 
@@ -326,8 +325,7 @@
 e_calendar_free_op (ECalendarOp *op)
 {
 	/* XXX more stuff here */
-	g_cond_free (op->cond);
-	g_mutex_free (op->mutex);
+	e_flag_free (op->done);
 	g_free (op);
 }
 
@@ -445,14 +443,10 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->bool = read_only;
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -474,14 +468,10 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->string = g_strdup (address);
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -497,14 +487,10 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->string = g_strdup (address);
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -520,14 +506,10 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->string = g_strdup (attribute);
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -543,14 +525,10 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->string = g_strdup (capabilities);
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -566,13 +544,9 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -588,13 +562,9 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -610,14 +580,10 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->uid = g_strdup (uid);
 	
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -633,13 +599,9 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -655,13 +617,9 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -677,13 +635,9 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -699,13 +653,9 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -722,8 +672,6 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->list = g_list_copy (users);
 	op->string = g_strdup (object);
@@ -731,9 +679,7 @@
 	for (l = op->list; l; l = l->next)
 		l->data = g_strdup (l->data);
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -749,14 +695,10 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->string = g_strdup (object);
 	
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -772,14 +714,10 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->string = g_strdup (object);
 	
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -796,17 +734,13 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->list = g_list_copy (objects);
 	
 	for (l = op->list; l; l = l->next)
 		l->data = icalcomponent_new_clone (l->data);
 	
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -822,14 +756,10 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->slist = g_slist_copy (attachments);
 	
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -845,15 +775,10 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->string = g_strdup (object);
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
-
+	e_flag_set (op->done);
 }
 
 static void
@@ -869,15 +794,10 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->uid = g_strdup (tzid);
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
-
+	e_flag_set (op->done);
 }
 
 static void
@@ -893,13 +813,9 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -916,8 +832,6 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->list = g_list_copy (changes);
 
@@ -931,9 +845,7 @@
 		l->data = new_ccc;
 	}
 	
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -950,17 +862,13 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->list = g_list_copy (freebusy);
 
 	for (l = op->list; l; l = l->next)
 		l->data = e_cal_component_clone (l->data);
 
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);
+	e_flag_set (op->done);
 }
 
 static void
@@ -976,14 +884,10 @@
 		return;
 	}
 
-	g_mutex_lock (op->mutex);
-
 	op->status = status;
 	op->query = e_cal_view_new (query, op->listener, ecal);
 	
-	g_cond_signal (op->cond);
-
-	g_mutex_unlock (op->mutex);	
+	e_flag_set (op->done);
 }
 
 static gboolean  
@@ -1714,7 +1618,6 @@
 	}
 	/* start the open operation */
 	our_op = e_calendar_new_op (ecal);
-	g_mutex_lock (our_op->mutex);
 
 	g_mutex_unlock (priv->mutex);
 
@@ -1727,7 +1630,6 @@
 
 		if (priv->auth_func == NULL) {
 			e_calendar_remove_op (ecal, our_op);
-			g_mutex_unlock (our_op->mutex);
 			e_calendar_free_op (our_op);
 			priv->load_state = E_CAL_LOAD_NOT_LOADED;
 			*status = E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED;
@@ -1737,7 +1639,6 @@
 		username = e_source_get_property (priv->source, "username");
 		if (!username) {
 			e_calendar_remove_op (ecal, our_op);
-			g_mutex_unlock (our_op->mutex);
 			e_calendar_free_op (our_op);
 			priv->load_state = E_CAL_LOAD_NOT_LOADED;
 			*status = E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED;
@@ -1765,7 +1666,6 @@
 
 		if (!key) {
 			e_calendar_remove_op (ecal, our_op);
-			g_mutex_unlock (our_op->mutex);
 			e_calendar_free_op (our_op);
 			priv->load_state = E_CAL_LOAD_NOT_LOADED;
 			*status = E_CALENDAR_STATUS_URI_NOT_LOADED;
@@ -1776,7 +1676,6 @@
 
 		if (!password) {
 			e_calendar_remove_op (ecal, our_op);
-			g_mutex_unlock (our_op->mutex);
 			e_calendar_free_op (our_op);
 			priv->load_state = E_CAL_LOAD_NOT_LOADED;
 			*status = E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED; 
@@ -1801,7 +1700,6 @@
 
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 		
 		CORBA_exception_free (&ev);
@@ -1815,14 +1713,11 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	*status = our_op->status;
 	
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 	if (*status == E_CALENDAR_STATUS_OK) {
 		priv->load_state = E_CAL_LOAD_LOADED;
@@ -1978,8 +1873,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 
@@ -1988,7 +1881,6 @@
 	GNOME_Evolution_Calendar_Cal_remove (priv->cal, &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -2000,14 +1892,11 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -2239,8 +2128,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	/* set it to true so that op does not emit cond signals for all notifications
 	   from the backend */
 	our_op->bool = TRUE;
@@ -2253,7 +2140,6 @@
 	GNOME_Evolution_Calendar_Cal_isReadOnly (priv->cal, &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -2265,9 +2151,7 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	
@@ -2275,7 +2159,6 @@
 		*read_only = our_op->bool;
 
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 	E_CALENDAR_CHECK_STATUS (status, error);
 }
@@ -2318,8 +2201,6 @@
 
 		our_op = e_calendar_new_op (ecal);
 
-		g_mutex_lock (our_op->mutex);
-
 		g_mutex_unlock (ecal->priv->mutex);
 
 
@@ -2328,7 +2209,6 @@
 		GNOME_Evolution_Calendar_Cal_getCalAddress (priv->cal, &ev);
 		if (BONOBO_EX (&ev)) {
 			e_calendar_remove_op (ecal, our_op);
-			g_mutex_unlock (our_op->mutex);
 			e_calendar_free_op (our_op);
 
 			CORBA_exception_free (&ev);
@@ -2340,14 +2220,11 @@
 
 		CORBA_exception_free (&ev);
 
-		/* wait for something to happen (both cancellation and a
-		   successful response will notity us via our cv */
-		g_cond_wait (our_op->cond, our_op->mutex);
+		e_flag_wait (our_op->done);
 
 		status = our_op->status;
 		*cal_address = our_op->string;
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		E_CALENDAR_CHECK_STATUS (status, error);
@@ -2395,8 +2272,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 
@@ -2405,7 +2280,6 @@
 	GNOME_Evolution_Calendar_Cal_getAlarmEmailAddress (priv->cal, &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -2417,15 +2291,12 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	*alarm_address = our_op->string;
 	
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -2468,8 +2339,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 
@@ -2478,7 +2347,6 @@
 	GNOME_Evolution_Calendar_Cal_getLdapAttribute (priv->cal, &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -2490,15 +2358,12 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	*ldap_attribute = our_op->string;
 	
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -2531,8 +2396,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 
@@ -2541,7 +2404,6 @@
 	GNOME_Evolution_Calendar_Cal_getStaticCapabilities (priv->cal, &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -2553,15 +2415,12 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	priv->capabilities = our_op->string;
 	
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -2770,8 +2629,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 	CORBA_exception_init (&ev);
@@ -2779,7 +2636,6 @@
 	GNOME_Evolution_Calendar_Cal_getDefaultObject (priv->cal, &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -2791,9 +2647,7 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
         if (status != E_CALENDAR_STATUS_OK) {
@@ -2806,7 +2660,6 @@
 	g_free (our_op->string);
 
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -2851,15 +2704,12 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 	CORBA_exception_init (&ev);
 	GNOME_Evolution_Calendar_Cal_getAttachmentList (priv->cal, uid, rid ? rid : "", &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -2871,9 +2721,7 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
         if (status != E_CALENDAR_STATUS_OK){ 
@@ -2883,7 +2731,6 @@
 	}
 
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -2928,8 +2775,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 	CORBA_exception_init (&ev);
@@ -2937,7 +2782,6 @@
 	GNOME_Evolution_Calendar_Cal_getObject (priv->cal, uid, rid ? rid : "", &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -2949,9 +2793,7 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
         if (status != E_CALENDAR_STATUS_OK){ 
@@ -2999,7 +2841,6 @@
 	g_free (our_op->string);
 
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -3045,8 +2886,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 	CORBA_exception_init (&ev);
@@ -3054,7 +2893,6 @@
 	GNOME_Evolution_Calendar_Cal_getObject (priv->cal, uid, "", &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -3066,9 +2904,7 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
         if (status != E_CALENDAR_STATUS_OK){ 
@@ -3126,7 +2962,6 @@
 	g_free (our_op->string);
 
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -3196,8 +3031,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 	CORBA_exception_init (&ev);
@@ -3206,7 +3039,6 @@
 
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -3218,15 +3050,12 @@
 	
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	*changes = our_op->list;
 
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -3296,8 +3125,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 	CORBA_exception_init (&ev);
@@ -3306,7 +3133,6 @@
 
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -3318,15 +3144,12 @@
 	
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	*objects = our_op->list;
 
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -3429,8 +3252,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 	/* create the CORBA user list to be passed to the backend */
@@ -3450,7 +3271,6 @@
 	
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -3462,15 +3282,12 @@
 	
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	*freebusy = our_op->list;
 
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -4161,8 +3978,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 	e_cal_component_get_uid (comp, &uid);
@@ -4172,7 +3987,6 @@
 	GNOME_Evolution_Calendar_Cal_discardAlarm (priv->cal, uid, auid, &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -4184,14 +3998,11 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -4407,8 +4218,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 	CORBA_exception_init (&ev);
@@ -4416,7 +4225,6 @@
 	GNOME_Evolution_Calendar_Cal_createObject (priv->cal, icalcomponent_as_ical_string (icalcomp), &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -4428,9 +4236,7 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+        e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	if (uid)
@@ -4440,7 +4246,6 @@
 	}
 	
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -4490,8 +4295,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 	CORBA_exception_init (&ev);
@@ -4499,7 +4302,6 @@
 	GNOME_Evolution_Calendar_Cal_modifyObject (priv->cal, icalcomponent_as_ical_string (icalcomp), mod, &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -4511,14 +4313,11 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -4571,8 +4370,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 
@@ -4581,7 +4378,6 @@
 	GNOME_Evolution_Calendar_Cal_removeObject (priv->cal, uid, rid ? rid : "", mod, &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -4593,14 +4389,11 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -4665,8 +4458,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 	CORBA_exception_init (&ev);
@@ -4674,7 +4465,6 @@
 	GNOME_Evolution_Calendar_Cal_receiveObjects (priv->cal, icalcomponent_as_ical_string (icalcomp), &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -4686,14 +4476,11 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -4739,8 +4526,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 	CORBA_exception_init (&ev);
@@ -4748,7 +4533,6 @@
 	GNOME_Evolution_Calendar_Cal_sendObjects (priv->cal, icalcomponent_as_ical_string (icalcomp), &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -4760,9 +4544,7 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	*users = our_op->list;
@@ -4783,7 +4565,6 @@
 	g_free (our_op->string);
 	
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -4828,8 +4609,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (priv->mutex);
 
 	/* Check for well known zones and in the cache */
@@ -4838,7 +4617,6 @@
 	/* If tzid is NULL or "" we return NULL, since it is a 'local time'. */
 	if (!tzid || !tzid[0]) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		*zone = NULL;
@@ -4856,7 +4634,6 @@
 	
 	if (*zone) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_OK, error);	
@@ -4868,7 +4645,6 @@
 	GNOME_Evolution_Calendar_Cal_getTimezone (priv->cal, tzid, &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -4880,9 +4656,7 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
         if (status != E_CALENDAR_STATUS_OK){ 
@@ -4896,7 +4670,6 @@
 	
 	if (!icalcomp) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		E_CALENDAR_CHECK_STATUS (status, error);
@@ -4907,7 +4680,6 @@
 		icaltimezone_free (*zone, 1);
 
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_OBJECT_NOT_FOUND, error);
@@ -4917,7 +4689,6 @@
 	g_hash_table_insert (priv->timezones, icaltimezone_get_tzid (*zone), *zone);
 
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -4962,15 +4733,12 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (priv->mutex);
 
 	/* Make sure we have a valid component - UTC doesn't, nor do
 	 * we really have to add it */
 	if (izone == icaltimezone_get_utc_timezone ()) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 		
 		E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_OK, error);
@@ -4979,7 +4747,6 @@
 	icalcomp = icaltimezone_get_component (izone);
 	if (!icalcomp) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_INVALID_ARG, error);
@@ -4994,7 +4761,6 @@
 	GNOME_Evolution_Calendar_Cal_addTimezone (priv->cal, tzobj, &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -5006,14 +4772,11 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -5055,8 +4818,6 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (ecal->priv->mutex);
 
 	CORBA_exception_init (&ev);
@@ -5066,7 +4827,6 @@
 
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -5078,9 +4838,7 @@
 	
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 	*query = our_op->query;
@@ -5088,7 +4846,6 @@
 	bonobo_object_unref (BONOBO_OBJECT (our_op->listener));
 	
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);
@@ -5169,15 +4926,12 @@
 
 	our_op = e_calendar_new_op (ecal);
 
-	g_mutex_lock (our_op->mutex);
-
 	g_mutex_unlock (priv->mutex);
 
 	/* FIXME Adding it to the server to change the tzid */
 	icalcomp = icaltimezone_get_component (zone);
 	if (!icalcomp) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_INVALID_ARG, error);
@@ -5192,7 +4946,6 @@
 	GNOME_Evolution_Calendar_Cal_setDefaultTimezone (priv->cal, tzobj, &ev);
 	if (BONOBO_EX (&ev)) {
 		e_calendar_remove_op (ecal, our_op);
-		g_mutex_unlock (our_op->mutex);
 		e_calendar_free_op (our_op);
 
 		CORBA_exception_free (&ev);
@@ -5204,9 +4957,7 @@
 
 	CORBA_exception_free (&ev);
 
-	/* wait for something to happen (both cancellation and a
-	   successful response will notity us via our cv */
-	g_cond_wait (our_op->cond, our_op->mutex);
+	e_flag_wait (our_op->done);
 
 	status = our_op->status;
 
@@ -5218,7 +4969,6 @@
 	}
 
 	e_calendar_remove_op (ecal, our_op);
-	g_mutex_unlock (our_op->mutex);
 	e_calendar_free_op (our_op);
 
 	E_CALENDAR_CHECK_STATUS (status, error);