[evolution-data-server] EFlag is off limits in Camel, write it out by hand.



commit a377044cd37368dcc372eab766221670540f949e
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Nov 14 18:52:21 2011 -0500

    EFlag is off limits in Camel, write it out by hand.

 camel/camel-db.c                           |   52 ++++++++++++++------
 camel/providers/imapx/camel-imapx-server.c |   72 +++++++++++++++++++++------
 camel/providers/imapx/camel-imapx-server.h |    1 -
 3 files changed, 93 insertions(+), 32 deletions(-)
---
diff --git a/camel/camel-db.c b/camel/camel-db.c
index a473110..fef43c4 100644
--- a/camel/camel-db.c
+++ b/camel/camel-db.c
@@ -32,7 +32,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "libedataserver/e-flag.h"
 
 #include <glib/gi18n-lib.h>
 
@@ -69,11 +68,17 @@ call_old_file_Sync (CamelSqlite3File *cFile,
 	return cFile->old_vfs_file->pMethods->xSync (cFile->old_vfs_file, flags);
 }
 
+typedef struct {
+	GCond *cond;
+	GMutex *mutex;
+	gboolean is_set;
+} SyncDone;
+
 struct SyncRequestData
 {
 	CamelSqlite3File *cFile;
 	guint32 flags;
-	EFlag *sync_op; /* not NULL when waiting for a finish; will be freed by the caller */
+	SyncDone *done; /* not NULL when waiting for a finish; will be freed by the caller */
 };
 
 static void
@@ -81,18 +86,22 @@ sync_request_thread_cb (gpointer task_data,
                         gpointer null_data)
 {
 	struct SyncRequestData *sync_data = task_data;
-	EFlag *sync_op;
+	SyncDone *done;
 
 	g_return_if_fail (sync_data != NULL);
 	g_return_if_fail (sync_data->cFile != NULL);
 
 	call_old_file_Sync (sync_data->cFile, sync_data->flags);
 
-	sync_op = sync_data->sync_op;
+	done = sync_data->done;
 	g_free (sync_data);
 
-	if (sync_op)
-		e_flag_set (sync_op);
+	if (done != NULL) {
+		g_mutex_lock (done->mutex);
+		done->is_set = TRUE;
+		g_cond_broadcast (done->cond);
+		g_mutex_unlock (done->mutex);
+	}
 }
 
 static void
@@ -100,7 +109,7 @@ sync_push_request (CamelSqlite3File *cFile,
                    gboolean wait_for_finish)
 {
 	struct SyncRequestData *data;
-	EFlag *sync_op = NULL;
+	SyncDone *done = NULL;
 	GError *error = NULL;
 
 	g_return_if_fail (cFile != NULL);
@@ -108,13 +117,17 @@ sync_push_request (CamelSqlite3File *cFile,
 
 	g_static_rec_mutex_lock (&cFile->sync_mutex);
 
-	if (wait_for_finish)
-		sync_op = e_flag_new ();
+	if (wait_for_finish) {
+		done = g_slice_new (SyncDone);
+		done->cond = g_cond_new ();
+		done->mutex = g_mutex_new ();
+		done->is_set = FALSE;
+	}
 
 	data = g_new0 (struct SyncRequestData, 1);
 	data->cFile = cFile;
 	data->flags = cFile->flags;
-	data->sync_op = sync_op;
+	data->done = done;
 
 	cFile->flags = 0;
 
@@ -126,15 +139,24 @@ sync_push_request (CamelSqlite3File *cFile,
 		g_warning ("%s: Failed to push to thread pool: %s\n", G_STRFUNC, error->message);
 		g_error_free (error);
 
-		if (sync_op)
-			e_flag_free (sync_op);
+		if (done != NULL) {
+			g_cond_free (done->cond);
+			g_mutex_free (done->mutex);
+			g_slice_free (SyncDone, done);
+		}
 
 		return;
 	}
 
-	if (sync_op) {
-		e_flag_wait (sync_op);
-		e_flag_free (sync_op);
+	if (done != NULL) {
+		g_mutex_lock (done->mutex);
+		while (!done->is_set)
+			g_cond_wait (done->cond, done->mutex);
+		g_mutex_unlock (done->mutex);
+
+		g_cond_free (done->cond);
+		g_mutex_free (done->mutex);
+		g_slice_free (SyncDone, done);
 	}
 }
 
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index eb36800..751b205 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -151,7 +151,9 @@ struct _CamelIMAPXCommand {
 	CamelIMAPXCommandPart *current;
 
 	/* used for running some commands syncronously */
-	EFlag *flag;
+	gboolean run_sync_done;
+	GCond *run_sync_cond;
+	GMutex *run_sync_mutex;
 
 	/* responsible for free'ing the command */
 	CamelIMAPXCommandFunc complete;
@@ -329,9 +331,12 @@ enum _idle_state {
 
 struct _CamelIMAPXIdle {
 	GMutex *idle_lock;
-	EFlag *idle_start_watch;
 	GThread *idle_thread;
 
+	GCond *start_watch_cond;
+	GMutex *start_watch_mutex;
+	gboolean start_watch_is_set;
+
 	time_t started;
 	enum _idle_state state;
 	gboolean idle_exit;
@@ -2134,7 +2139,10 @@ static void
 imapx_command_complete (CamelIMAPXServer *is,
                         CamelIMAPXCommand *ic)
 {
-	e_flag_set (ic->flag);
+	g_mutex_lock (ic->run_sync_mutex);
+	ic->run_sync_done = TRUE;
+	g_cond_broadcast (ic->run_sync_cond);
+	g_mutex_unlock (ic->run_sync_mutex);
 }
 
 /* The caller should free the command as well */
@@ -2142,16 +2150,25 @@ static void
 imapx_command_run_sync (CamelIMAPXServer *is,
                         CamelIMAPXCommand *ic)
 {
-	ic->flag = e_flag_new ();
+	ic->run_sync_done = FALSE;
+	ic->run_sync_cond = g_cond_new ();
+	ic->run_sync_mutex = g_mutex_new ();
 
 	if (!ic->complete)
 		ic->complete = imapx_command_complete;
 
 	imapx_command_queue (is, ic);
-	e_flag_wait (ic->flag);
 
-	e_flag_free (ic->flag);
-	ic->flag = NULL;
+	g_mutex_lock (ic->run_sync_mutex);
+	while (!ic->run_sync_done)
+		g_cond_wait (ic->run_sync_cond, ic->run_sync_mutex);
+	g_mutex_unlock (ic->run_sync_mutex);
+
+	g_cond_free (ic->run_sync_cond);
+	g_mutex_free (ic->run_sync_mutex);
+	ic->run_sync_done = FALSE;
+	ic->run_sync_cond = NULL;
+	ic->run_sync_mutex = NULL;
 }
 
 /* ********************************************************************** */
@@ -2426,7 +2443,9 @@ imapx_idle_thread (gpointer data)
 	while (TRUE) {
 		CamelIMAPXFolder *ifolder;
 
-		e_flag_clear (is->idle->idle_start_watch);
+		g_mutex_lock (is->idle->start_watch_mutex);
+		is->idle->start_watch_is_set = FALSE;
+		g_mutex_unlock (is->idle->start_watch_mutex);
 
 		IDLE_LOCK (is->idle);
 		while ((ifolder = (CamelIMAPXFolder *) is->select_folder) &&
@@ -2457,7 +2476,12 @@ imapx_idle_thread (gpointer data)
 		}
 		IDLE_UNLOCK (is->idle);
 
-		e_flag_wait (is->idle->idle_start_watch);
+		g_mutex_lock (is->idle->start_watch_mutex);
+		while (!is->idle->start_watch_is_set)
+			g_cond_wait (
+				is->idle->start_watch_cond,
+				is->idle->start_watch_mutex);
+		g_mutex_unlock (is->idle->start_watch_mutex);
 
 		if (is->idle->idle_exit)
 			break;
@@ -2526,7 +2550,11 @@ imapx_exit_idle (CamelIMAPXServer *is)
 
 	if (idle->idle_thread) {
 		idle->idle_exit = TRUE;
-		e_flag_set (idle->idle_start_watch);
+
+		g_mutex_lock (idle->start_watch_mutex);
+		idle->start_watch_is_set = TRUE;
+		g_cond_broadcast (idle->start_watch_cond);
+		g_mutex_unlock (idle->start_watch_mutex);
 
 		thread = idle->idle_thread;
 		idle->idle_thread = 0;
@@ -2539,8 +2567,12 @@ imapx_exit_idle (CamelIMAPXServer *is)
 		g_thread_join (thread);
 
 	g_mutex_free (idle->idle_lock);
-	if (idle->idle_start_watch)
-		e_flag_free (idle->idle_start_watch);
+
+	if (idle->start_watch_cond != NULL)
+		g_cond_free (idle->start_watch_cond);
+
+	if (idle->start_watch_mutex != NULL)
+		g_mutex_free (idle->start_watch_mutex);
 
 	g_free (is->idle);
 	is->idle = NULL;
@@ -2561,10 +2593,18 @@ imapx_start_idle (CamelIMAPXServer *is)
 	idle->state = IMAPX_IDLE_PENDING;
 
 	if (!idle->idle_thread) {
-		idle->idle_start_watch = e_flag_new ();
-		idle->idle_thread = g_thread_create ((GThreadFunc) imapx_idle_thread, is, TRUE, NULL);
-	} else
-		e_flag_set (idle->idle_start_watch);
+		idle->start_watch_cond = g_cond_new ();
+		idle->start_watch_mutex = g_mutex_new ();
+		idle->start_watch_is_set = FALSE;
+
+		idle->idle_thread = g_thread_create (
+			(GThreadFunc) imapx_idle_thread, is, TRUE, NULL);
+	} else {
+		g_mutex_lock (idle->start_watch_mutex);
+		idle->start_watch_is_set = TRUE;
+		g_cond_broadcast (idle->start_watch_cond);
+		g_mutex_unlock (idle->start_watch_mutex);
+	}
 
 	IDLE_UNLOCK (idle);
 }
diff --git a/camel/providers/imapx/camel-imapx-server.h b/camel/providers/imapx/camel-imapx-server.h
index 79e76ab..f4c8fb7 100644
--- a/camel/providers/imapx/camel-imapx-server.h
+++ b/camel/providers/imapx/camel-imapx-server.h
@@ -21,7 +21,6 @@
 #define CAMEL_IMAPX_SERVER_H
 
 #include <camel/camel.h>
-#include <libedataserver/e-flag.h>
 
 #include "camel-imapx-stream.h"
 #include "camel-imapx-store-summary.h"



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