evolution/evolution-2.8.1-kill-ethread.patch

2606 lines
74 KiB
Diff
Raw Normal View History

--- evolution-2.10.0/mail/mail-send-recv.c.kill-ethread 2007-01-03 10:34:12.000000000 -0500
+++ evolution-2.10.0/mail/mail-send-recv.c 2007-03-30 15:47:31.000000000 -0400
@@ -819,7 +819,7 @@
m->folders = folders;
m->info = sinfo;
- e_thread_put(mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
} else {
receive_done ("", data);
}
--- evolution-2.10.0/mail/mail-component.c.kill-ethread 2007-03-12 16:13:58.000000000 -0400
+++ evolution-2.10.0/mail/mail-component.c 2007-03-30 15:47:31.000000000 -0400
@@ -965,7 +965,7 @@
if (camel_url_get_param(url, "uid") != NULL) {
char *curi = em_uri_to_camel(uri);
- mail_get_folder(curi, 0, handleuri_got_folder, url, mail_thread_new);
+ mail_get_folder(curi, 0, handleuri_got_folder, url, mail_msg_unordered_push);
g_free(curi);
} else {
g_warning("email uri's must include a uid parameter");
--- evolution-2.10.0/mail/mail-ops.c.kill-ethread 2007-01-03 10:34:12.000000000 -0500
+++ evolution-2.10.0/mail/mail-ops.c 2007-03-30 15:47:31.000000000 -0400
@@ -221,7 +221,7 @@
camel_filter_driver_remove_rule_by_name (m->driver, "new-mail-notification");
}
- e_thread_put (mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
}
/* convenience functions for it */
@@ -426,7 +426,7 @@
if (status)
camel_filter_driver_set_status_func (fm->driver, status, status_data);
- e_thread_put (mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
}
/* ********************************************************************** */
@@ -839,7 +839,7 @@
m->driver = camel_session_get_filter_driver (session, type, NULL);
camel_filter_driver_set_folder_func (m->driver, get_folder, get_data);
- e_thread_put(mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
}
/* ** APPEND MESSAGE TO FOLDER ******************************************** */
@@ -921,7 +921,7 @@
m->done = done;
m->data = data;
- e_thread_put (mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
}
/* ** TRANSFER MESSAGES **************************************************** */
@@ -1036,7 +1036,7 @@
m->done = done;
m->data = data;
- e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+ mail_msg_slow_ordered_push ((mail_msg_t *) m);
}
/* ** SCAN SUBFOLDERS ***************************************************** */
@@ -1124,7 +1124,7 @@
m->data = data;
id = m->msg.seq;
- e_thread_put(mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
return id;
}
@@ -1250,7 +1250,7 @@
int
mail_get_folder (const char *uri, guint32 flags,
void (*done)(char *uri, CamelFolder *folder, void *data),
- void *data, EThread *thread)
+ void *data, MailMsgDispatchFunc dispatch)
{
struct _get_folder_msg *m;
int id;
@@ -1262,7 +1262,7 @@
m->done = done;
id = m->msg.seq;
- e_thread_put(thread, (EMsg *)m);
+ dispatch ((mail_msg_t *) m);
return id;
}
@@ -1340,7 +1340,7 @@
m->done = done;
id = m->msg.seq;
- e_thread_put (mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
return id;
}
@@ -1437,7 +1437,7 @@
m->data = data;
m->done = done;
- e_thread_put (mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
}
/* ** SYNC FOLDER ********************************************************* */
@@ -1498,7 +1498,7 @@
m->data = data;
m->done = done;
- e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+ mail_msg_slow_ordered_push ((mail_msg_t *) m);
}
/* ** SYNC STORE ********************************************************* */
@@ -1568,7 +1568,7 @@
m->data = data;
m->done = done;
- e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+ mail_msg_slow_ordered_push ((mail_msg_t *) m);
}
/* ******************************************************************************** */
@@ -1604,7 +1604,7 @@
m->data = data;
m->done = done;
- e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+ mail_msg_slow_ordered_push ((mail_msg_t *) m);
}
/* ******************************************************************************** */
@@ -1640,7 +1640,7 @@
m->data = data;
m->done = done;
- e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+ mail_msg_slow_ordered_push ((mail_msg_t *) m);
}
/* ******************************************************************************** */
@@ -1723,7 +1723,7 @@
m->data = data;
m->done = done;
- e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+ mail_msg_slow_ordered_push ((mail_msg_t *) m);
}
/* ** GET MESSAGE(s) ***************************************************** */
@@ -1783,7 +1783,7 @@
void
mail_get_message(CamelFolder *folder, const char *uid, void (*done) (CamelFolder *folder, const char *uid,
CamelMimeMessage *msg, void *data),
- void *data, EThread *thread)
+ void *data, MailMsgDispatchFunc dispatch)
{
struct _get_message_msg *m;
@@ -1795,7 +1795,7 @@
m->done = done;
m->cancel = camel_operation_new(NULL, NULL);
- e_thread_put(thread, (EMsg *)m);
+ dispatch ((mail_msg_t *) m);
}
typedef void (*get_done)(CamelFolder *folder, const char *uid, CamelMimeMessage *msg, void *data, CamelException *);
@@ -1821,7 +1821,7 @@
mail_get_message; it adds an exception argument to the callback */
void
mail_get_messagex(CamelFolder *folder, const char *uid, void (*done) (CamelFolder *folder, const char *uid, CamelMimeMessage *msg, void *data, CamelException *),
- void *data, EThread *thread)
+ void *data, MailMsgDispatchFunc dispatch)
{
struct _get_message_msg *m;
@@ -1833,7 +1833,7 @@
m->done = done;
m->cancel = camel_operation_new(NULL, NULL);
- e_thread_put(thread, (EMsg *)m);
+ dispatch ((mail_msg_t *) m);
}
/* ********************************************************************** */
@@ -1920,7 +1920,7 @@
m->data = data;
m->done = done;
- e_thread_put(mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
}
/* ** SAVE MESSAGES ******************************************************* */
@@ -2063,7 +2063,7 @@
m->done = done;
id = m->msg.seq;
- e_thread_put(mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
return id;
}
@@ -2156,7 +2156,7 @@
m->readonly = readonly;
id = m->msg.seq;
- e_thread_put (mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
return id;
}
@@ -2240,7 +2240,7 @@
m->data = data;
m->done = done;
- e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+ mail_msg_slow_ordered_push ((mail_msg_t *) m);
}
/* ** GO OFFLINE ***************************************************** */
@@ -2345,7 +2345,7 @@
m->done = done;
id = m->msg.seq;
- e_thread_put(mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
return id;
}
@@ -2433,7 +2433,7 @@
m->data = data;
id = m->msg.seq;
- e_thread_put(mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
return id;
}
--- evolution-2.10.0/mail/em-folder-utils.c.kill-ethread 2007-01-03 10:34:12.000000000 -0500
+++ evolution-2.10.0/mail/em-folder-utils.c 2007-03-30 15:47:31.000000000 -0400
@@ -260,7 +260,7 @@
m->delete = delete;
seq = m->msg.seq;
- e_thread_put (mail_thread_new, (EMsg *) m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
return seq;
}
@@ -652,7 +652,7 @@
g_free (namebuf);
id = m->msg.seq;
- e_thread_put (mail_thread_new, (EMsg *) m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
return id;
}
--- evolution-2.10.0/mail/importers/elm-importer.c.kill-ethread 2007-01-03 10:34:11.000000000 -0500
+++ evolution-2.10.0/mail/importers/elm-importer.c 2007-03-30 15:47:31.000000000 -0400
@@ -312,7 +312,7 @@
id = m->msg.seq;
- e_thread_put(mail_thread_queued, (EMsg *)m);
+ mail_msg_fast_ordered_push ((mail_msg_t *) m);
return id;
}
--- evolution-2.10.0/mail/importers/mail-importer.c.kill-ethread 2007-01-03 10:34:11.000000000 -0500
+++ evolution-2.10.0/mail/importers/mail-importer.c 2007-03-30 15:47:31.000000000 -0400
@@ -329,7 +329,7 @@
}
id = m->msg.seq;
- e_thread_put(mail_thread_queued, (EMsg *)m);
+ mail_msg_fast_ordered_push ((mail_msg_t *) m);
return id;
}
--- evolution-2.10.0/mail/importers/pine-importer.c.kill-ethread 2007-01-03 10:34:11.000000000 -0500
+++ evolution-2.10.0/mail/importers/pine-importer.c 2007-03-30 15:47:31.000000000 -0400
@@ -350,7 +350,7 @@
id = m->msg.seq;
- e_thread_put(mail_thread_queued, (EMsg *)m);
+ mail_msg_fast_ordered_push ((mail_msg_t *) m);
return id;
}
--- evolution-2.10.0/mail/mail-vfolder.c.kill-ethread 2007-01-03 10:34:12.000000000 -0500
+++ evolution-2.10.0/mail/mail-vfolder.c 2007-03-30 15:47:31.000000000 -0400
@@ -188,7 +188,7 @@
m->sources_folder = sources_folder;
id = m->msg.seq;
- e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+ mail_msg_slow_ordered_push ((mail_msg_t *) m);
return id;
}
@@ -323,7 +323,7 @@
m->remove = remove;
id = m->msg.seq;
- e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+ mail_msg_slow_ordered_push ((mail_msg_t *) m);
return id;
}
@@ -447,7 +447,7 @@
return;
}
- g_assert(pthread_equal(pthread_self(), mail_gui_thread));
+ g_assert(mail_in_main_thread());
is_ignore = uri_is_ignore(store, curi);
@@ -540,7 +540,7 @@
d(printf ("Deleting uri to check: %s\n", uri));
- g_assert (pthread_equal(pthread_self(), mail_gui_thread));
+ g_assert (mail_in_main_thread());
changed = g_string_new ("");
@@ -615,7 +615,7 @@
if (context == NULL || uri_is_spethal(store, cfrom) || uri_is_spethal(store, cto))
return;
- g_assert(pthread_equal(pthread_self(), mail_gui_thread));
+ g_assert(mail_in_main_thread());
from = em_uri_from_camel(cfrom);
to = em_uri_from_camel(cto);
--- evolution-2.10.0/mail/em-format-html.c.kill-ethread 2007-02-26 04:59:59.000000000 -0500
+++ evolution-2.10.0/mail/em-format-html.c 2007-03-30 15:47:31.000000000 -0400
@@ -1375,7 +1375,7 @@
}
efh->priv->format_id = m->msg.seq;
- e_thread_put(mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
}
efh->priv->format_timeout_id = 0;
--- evolution-2.10.0/mail/em-folder-properties.c.kill-ethread 2007-01-03 10:34:12.000000000 -0500
+++ evolution-2.10.0/mail/em-folder-properties.c 2007-03-30 15:47:31.000000000 -0400
@@ -379,7 +379,7 @@
}
if (folder == NULL)
- mail_get_folder(uri, 0, emfp_dialog_got_folder, NULL, mail_thread_new);
+ mail_get_folder(uri, 0, emfp_dialog_got_folder, NULL, mail_msg_unordered_push);
else
emfp_dialog_got_folder((char *)uri, folder, NULL);
}
--- evolution-2.10.0/mail/em-folder-tree.c.kill-ethread 2007-01-03 10:34:12.000000000 -0500
+++ evolution-2.10.0/mail/em-folder-tree.c 2007-03-30 15:47:31.000000000 -0400
@@ -966,7 +966,7 @@
tree_drag_data_action(struct _DragDataReceivedAsync *m)
{
m->move = m->action == GDK_ACTION_MOVE;
- e_thread_put (mail_thread_new, (EMsg *) m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
}
static void
@@ -1891,7 +1891,7 @@
m->top = full_name;
m->flags = CAMEL_STORE_FOLDER_INFO_RECURSIVE|CAMEL_STORE_FOLDER_INFO_FAST;
- e_thread_put (mail_thread_new, (EMsg *) m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
}
static gboolean
--- evolution-2.10.0/mail/em-folder-browser.c.kill-ethread 2007-02-26 04:59:59.000000000 -0500
+++ evolution-2.10.0/mail/em-folder-browser.c 2007-03-30 15:47:31.000000000 -0400
@@ -948,7 +948,7 @@
m->sources_folder = sources_folder;
id = m->msg.seq;
- e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+ mail_msg_slow_ordered_push ((mail_msg_t *) m);
return id;
}
--- evolution-2.10.0/mail/message-list.c.kill-ethread 2007-01-23 03:23:43.000000000 -0500
+++ evolution-2.10.0/mail/message-list.c 2007-03-30 15:47:31.000000000 -0400
@@ -1888,7 +1888,7 @@
ml_drop_action(struct _drop_msg *m)
{
m->move = m->action == GDK_ACTION_MOVE;
- e_thread_put (mail_thread_new, (EMsg *) m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
}
static void
@@ -3922,7 +3922,7 @@
m->ml->regen = g_list_prepend(m->ml->regen, m);
/* TODO: we should manage our own thread stuff, would make cancelling outstanding stuff easier */
- e_thread_put (mail_thread_queued, (EMsg *)m);
+ mail_msg_fast_ordered_push ((mail_msg_t *) m);
m->ml->regen_timeout_msg = NULL;
m->ml->regen_timeout_id = 0;
--- evolution-2.10.0/mail/em-sync-stream.h.kill-ethread 2007-01-03 10:34:12.000000000 -0500
+++ evolution-2.10.0/mail/em-sync-stream.h 2007-03-30 15:47:31.000000000 -0400
@@ -29,41 +29,45 @@
#ifndef EM_SYNC_STREAM_H
#define EM_SYNC_STREAM_H
-#ifdef __cplusplus
-extern "C" {
-#pragma }
-#endif /* __cplusplus */
-
-#define EM_SYNC_STREAM_TYPE (em_sync_stream_get_type ())
-#define EM_SYNC_STREAM(obj) (CAMEL_CHECK_CAST((obj), EM_SYNC_STREAM_TYPE, EMSyncStream))
-#define EM_SYNC_STREAM_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), EM_SYNC_STREAM_TYPE, EMSyncStreamClass))
-#define EM_IS_SYNC_STREAM(o) (CAMEL_CHECK_TYPE((o), EM_SYNC_STREAM_TYPE))
-
#include <glib.h>
#include <camel/camel-stream.h>
-typedef struct _EMSyncStream {
- CamelStream parent_stream;
-
- struct _EMSyncStreamPrivate *priv;
+#define EM_SYNC_STREAM_TYPE \
+ (em_sync_stream_get_type ())
+#define EM_SYNC_STREAM(obj) \
+ (CAMEL_CHECK_CAST \
+ ((obj), EM_SYNC_STREAM_TYPE, EMSyncStream))
+#define EM_SYNC_STREAM_CLASS(cls) \
+ (CAMEL_CHECK_CLASS_CAST \
+ ((cls), EM_SYNC_STREAM_TYPE, EMSyncStreamClass))
+#define EM_IS_SYNC_STREAM(obj) \
+ (CAMEL_CHECK_TYPE ((obj), EM_SYNC_STREAM_TYPE))
+
+G_BEGIN_DECLS
+
+typedef struct _EMSyncStream EMSyncStream;
+typedef struct _EMSyncStreamClass EMSyncStreamClass;
+
+struct _EMSyncStream {
+ CamelStream parent;
+ GString *buffer;
+ gboolean cancel;
+};
- int cancel;
-} EMSyncStream;
-
-typedef struct {
+struct _EMSyncStreamClass {
CamelStreamClass parent_class;
- ssize_t (*sync_write) (CamelStream *stream, const char *buffer, size_t n);
- int (*sync_close) (CamelStream *stream);
- int (*sync_flush) (CamelStream *stream);
-
-} EMSyncStreamClass;
-
-CamelType em_sync_stream_get_type (void);
-void em_sync_stream_set_buffer_size(EMSyncStream *, size_t size);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+ gssize (*sync_write) (CamelStream *stream,
+ const gchar *string,
+ gsize len);
+ int (*sync_close) (CamelStream *stream);
+ int (*sync_flush) (CamelStream *stream);
+};
+
+CamelType em_sync_stream_get_type (void);
+void em_sync_stream_set_buffer_size (EMSyncStream *stream,
+ gsize size);
+
+G_END_DECLS
#endif /* EM_SYNC_STREAM_H */
--- evolution-2.10.0/mail/em-format-html-print.c.kill-ethread 2007-02-26 04:59:59.000000000 -0500
+++ evolution-2.10.0/mail/em-format-html-print.c 2007-03-30 15:47:31.000000000 -0400
@@ -262,7 +262,7 @@
g_object_ref(source);
g_object_ref(efhp);
- mail_get_message(folder, uid, emfhp_got_message, efhp, mail_thread_new);
+ mail_get_message(folder, uid, emfhp_got_message, efhp, mail_msg_unordered_push);
return 0; /* damn async ... */
}
--- evolution-2.10.0/mail/em-sync-stream.c.kill-ethread 2007-02-26 04:59:59.000000000 -0500
+++ evolution-2.10.0/mail/em-sync-stream.c 2007-03-30 15:47:31.000000000 -0400
@@ -25,42 +25,17 @@
#include <config.h>
#endif
-#include <string.h>
+#include "em-sync-stream.h"
+
#include <stdio.h>
-#include <camel/camel-stream.h>
+#include <string.h>
#include <camel/camel-object.h>
-#include <gtk/gtkmain.h>
-#include "em-sync-stream.h"
+#include <libedataserver/e-flag.h>
#include "mail-mt.h"
-#define LOG_STREAM
-
-#define d(x)
-
#define EMSS_CLASS(x) ((EMSyncStreamClass *)(((CamelObject *)(x))->klass))
-struct _EMSyncStreamPrivate {
- /* FIXME: use a single data port/gui channel for all instances */
- /* TODO: possibly just use one of the mail-mt ports ... */
- struct _EMsgPort *data_port, *reply_port;
- struct _GIOChannel *gui_channel;
- guint gui_watch;
-
- char *buf_data;
- int buf_used;
- int buf_size;
-
-#ifdef LOG_STREAM
- FILE *logfd;
-#endif
-};
-
-#ifdef LOG_STREAM
-int dolog;
-#endif
-
-/* Should probably expose messages to outside world ... so subclasses can extend */
enum _write_msg_t {
EMSS_WRITE,
EMSS_FLUSH,
@@ -68,275 +43,168 @@
};
struct _write_msg {
- EMsg msg;
+ EMSyncStream *emss;
+ EFlag *processed;
enum _write_msg_t op;
- const char *data;
- size_t n;
+ const gchar *string;
+ gsize len;
};
-static void em_sync_stream_class_init (EMSyncStreamClass *klass);
-static void em_sync_stream_init (CamelObject *object);
-static void em_sync_stream_finalize (CamelObject *object);
-
-static ssize_t stream_write(CamelStream *stream, const char *buffer, size_t n);
-static int stream_close(CamelStream *stream);
-static int stream_flush(CamelStream *stream);
-
static CamelStreamClass *parent_class = NULL;
-CamelType
-em_sync_stream_get_type (void)
-{
- static CamelType type = CAMEL_INVALID_TYPE;
-
- if (type == CAMEL_INVALID_TYPE) {
-#ifdef LOG_STREAM
- dolog = getenv("EVOLUTION_MAIL_LOG_HTML") != NULL;
-#endif
- type = camel_type_register (CAMEL_STREAM_TYPE,
- "EMSyncStream",
- sizeof (EMSyncStream),
- sizeof (EMSyncStreamClass),
- (CamelObjectClassInitFunc) em_sync_stream_class_init,
- NULL,
- (CamelObjectInitFunc) em_sync_stream_init,
- (CamelObjectFinalizeFunc) em_sync_stream_finalize);
- }
-
- return type;
-}
-
-static void
-em_sync_stream_class_init (EMSyncStreamClass *klass)
-{
- CamelStreamClass *stream_class = CAMEL_STREAM_CLASS (klass);
-
- parent_class = (CamelStreamClass *) CAMEL_STREAM_TYPE;
-
- /* virtual method overload */
- stream_class->write = stream_write;
- stream_class->flush = stream_flush;
- stream_class->close = stream_close;
-}
-
static gboolean
-emcs_gui_received(GIOChannel *source, GIOCondition cond, void *data)
+emss_process_message (struct _write_msg *msg)
{
- EMSyncStream *emss = data;
- struct _EMSyncStreamPrivate *p = emss->priv;
- struct _write_msg *msg;
-
- d(printf("%p: gui sync op job waiting\n", emss));
-
- msg = (struct _write_msg *)e_msgport_get(p->data_port);
- /* Should never happen ... */
- if (msg == NULL)
- return TRUE;
-
- d(printf("%p: running sync op %d\n", emss, msg->op));
-
- /* force out any pending data before doing anything else */
- if (p->buf_used > 0) {
- EMSS_CLASS(emss)->sync_write((CamelStream *)emss, p->buf_data, p->buf_used);
-#ifdef LOG_STREAM
- if (p->logfd)
- fwrite(p->buf_data, 1, p->buf_used, p->logfd);
-#endif
- p->buf_used = 0;
- }
+ struct _EMSyncStream *emss = msg->emss;
- /* FIXME: need to handle return values */
+ /* Force out any pending data before doing anything else. */
+ if (emss->buffer != NULL && emss->buffer->len > 0) {
+ EMSS_CLASS (emss)->sync_write (
+ CAMEL_STREAM (emss), emss->buffer->str,
+ emss->buffer->len);
+ g_string_set_size (emss->buffer, 0);
+ }
switch (msg->op) {
- case EMSS_WRITE:
- EMSS_CLASS(emss)->sync_write((CamelStream *)emss, msg->data, msg->n);
-#ifdef LOG_STREAM
- if (p->logfd)
- fwrite(msg->data, 1, msg->n, p->logfd);
-#endif
- break;
- case EMSS_FLUSH:
- EMSS_CLASS(emss)->sync_flush((CamelStream *)emss);
- break;
- case EMSS_CLOSE:
- EMSS_CLASS(emss)->sync_close((CamelStream *)emss);
-#ifdef LOG_STREAM
- if (p->logfd) {
- fclose(p->logfd);
- p->logfd = NULL;
- }
-#endif
- break;
+ case EMSS_WRITE:
+ EMSS_CLASS (emss)->sync_write (
+ CAMEL_STREAM (emss), msg->string, msg->len);
+ break;
+ case EMSS_FLUSH:
+ EMSS_CLASS (emss)->sync_flush (
+ CAMEL_STREAM (emss));
+ break;
+ case EMSS_CLOSE:
+ EMSS_CLASS (emss)->sync_close (
+ CAMEL_STREAM (emss));
+ break;
}
-
- e_msgport_reply((EMsg *)msg);
- d(printf("%p: gui sync op jobs done\n", emss));
-
- return TRUE;
-}
-
-static void
-em_sync_stream_init (CamelObject *object)
-{
- EMSyncStream *emss = (EMSyncStream *)object;
- struct _EMSyncStreamPrivate *p;
-
- p = emss->priv = g_malloc0(sizeof(*p));
- p->data_port = e_msgport_new();
- p->reply_port = e_msgport_new();
+ e_flag_set (msg->processed);
-#ifndef G_OS_WIN32
- p->gui_channel = g_io_channel_unix_new(e_msgport_fd(p->data_port));
-#else
- p->gui_channel = g_io_channel_win32_new_socket(e_msgport_fd(p->data_port));
-#endif
- p->gui_watch = g_io_add_watch(p->gui_channel, G_IO_IN, emcs_gui_received, emss);
-
-#ifdef LOG_STREAM
- if (dolog) {
- char name[32];
- static int count;
-
- sprintf(name, "sync-stream.%d.html", count++);
- printf("Saving raw data stream to '%s'\n", name);
- p->logfd = fopen(name, "w");
- }
-#endif
-
- d(printf("%p: new emss\n", emss));
+ return FALSE;
}
static void
-sync_op(EMSyncStream *emss, enum _write_msg_t op, const char *data, size_t n)
+emss_sync_op (EMSyncStream *emss, enum _write_msg_t op,
+ const gchar *string, gsize len)
{
- struct _EMSyncStreamPrivate *p = emss->priv;
struct _write_msg msg;
- EMsg *reply_msg;
-
- d(printf("%p: launching sync op %d\n", emss, op));
- /* we do everything synchronous, we should never have any locks, and
- this prevents overflow from banked up data */
-
- msg.msg.reply_port = p->reply_port;
+ msg.processed = e_flag_new ();
+ msg.emss = emss;
msg.op = op;
- msg.data = data;
- msg.n = n;
-
- e_msgport_put(p->data_port, &msg.msg);
- reply_msg = e_msgport_wait(p->reply_port);
- g_assert(reply_msg == &msg.msg);
-
- d(printf("%p: returned sync op %d\n", emss, op));
-}
-
-static void
-em_sync_stream_finalize (CamelObject *object)
-{
- EMSyncStream *emss = (EMSyncStream *)object;
- struct _EMSyncStreamPrivate *p = emss->priv;
-
- /* TODO: is this stuff safe to do in another thread? */
- g_source_remove(p->gui_watch);
- g_io_channel_unref(p->gui_channel);
+ msg.string = string;
+ msg.len = len;
- e_msgport_destroy(p->data_port);
- e_msgport_destroy(p->reply_port);
+ camel_object_ref (emss);
- p->data_port = NULL;
- p->reply_port = NULL;
+ g_idle_add ((GSourceFunc) emss_process_message, &msg);
- g_free(p->buf_data);
+ e_flag_wait (msg.processed);
+ e_flag_free (msg.processed);
-#ifdef LOG_STREAM
- if (p->logfd)
- fclose(p->logfd);
-#endif
-
- g_free(p);
+ camel_object_unref (emss);
}
-static ssize_t
-stream_write (CamelStream *stream, const char *buffer, size_t n)
+static gssize
+emss_stream_write (CamelStream *stream, const gchar *string, gsize len)
{
EMSyncStream *emss = EM_SYNC_STREAM (stream);
- struct _EMSyncStreamPrivate *p = emss->priv;
if (emss->cancel)
return -1;
- if (pthread_equal(pthread_self(), mail_gui_thread)) {
- EMSS_CLASS(emss)->sync_write(stream, buffer, n);
-#ifdef LOG_STREAM
- if (p->logfd)
- fwrite(buffer, 1, n, p->logfd);
-#endif
- } else if (p->buf_size > 0) {
- size_t left = p->buf_size-p->buf_used;
-
- if (n >= left) {
- sync_op(emss, EMSS_WRITE, buffer, n);
- } else {
- memcpy(p->buf_data + p->buf_used, buffer, n);
- p->buf_used += n;
- }
+ if (mail_in_main_thread ()) {
+ EMSS_CLASS (emss)->sync_write (stream, string, len);
+ } else if (emss->buffer != NULL) {
+ if (len < (emss->buffer->allocated_len - emss->buffer->len))
+ g_string_append_len (emss->buffer, string, len);
+ else
+ emss_sync_op (emss, EMSS_WRITE, string, len);
} else {
- sync_op(emss, EMSS_WRITE, buffer, n);
+ emss_sync_op(emss, EMSS_WRITE, string, len);
}
- return (ssize_t) n;
+ return (gssize) len;
}
static int
-stream_flush(CamelStream *stream)
+emss_stream_flush (CamelStream *stream)
{
- EMSyncStream *emss = (EMSyncStream *)stream;
+ EMSyncStream *emss = EM_SYNC_STREAM (stream);
if (emss->cancel)
return -1;
- if (pthread_equal(pthread_self(), mail_gui_thread))
- return ((EMSyncStreamClass *)(((CamelObject *)emss)->klass))->sync_flush(stream);
+ if (mail_in_main_thread ())
+ return EMSS_CLASS (emss)->sync_flush (stream);
else
- sync_op(emss, EMSS_FLUSH, NULL, 0);
+ emss_sync_op (emss, EMSS_FLUSH, NULL, 0);
return 0;
}
static int
-stream_close(CamelStream *stream)
+emss_stream_close (CamelStream *stream)
{
- EMSyncStream *emss = (EMSyncStream *)stream;
+ EMSyncStream *emss = EM_SYNC_STREAM (stream);
if (emss->cancel)
return -1;
- d(printf("%p: closing stream\n", stream));
-
- if (pthread_equal(pthread_self(), mail_gui_thread)) {
-#ifdef LOG_STREAM
- if (emss->priv->logfd) {
- fclose(emss->priv->logfd);
- emss->priv->logfd = NULL;
- }
-#endif
- return ((EMSyncStreamClass *)(((CamelObject *)emss)->klass))->sync_close(stream);
- } else
- sync_op(emss, EMSS_CLOSE, NULL, 0);
+ if (mail_in_main_thread ())
+ return EMSS_CLASS (emss)->sync_close (stream);
+ else
+ emss_sync_op (emss, EMSS_CLOSE, NULL, 0);
return 0;
}
-void
-em_sync_stream_set_buffer_size(EMSyncStream *emss, size_t size)
+static void
+em_sync_stream_class_init (EMSyncStreamClass *class)
+{
+ CamelStreamClass *stream_class = CAMEL_STREAM_CLASS (class);
+
+ parent_class = (CamelStreamClass *) CAMEL_STREAM_TYPE;
+
+ stream_class->write = emss_stream_write;
+ stream_class->flush = emss_stream_flush;
+ stream_class->close = emss_stream_close;
+}
+
+static void
+em_sync_stream_finalize (EMSyncStream *emss)
+{
+ if (emss->buffer != NULL)
+ g_string_free (emss->buffer, TRUE);
+}
+
+CamelType
+em_sync_stream_get_type (void)
{
- struct _EMSyncStreamPrivate *p = emss->priv;
+ static CamelType type = CAMEL_INVALID_TYPE;
+
+ if (G_UNLIKELY (type == CAMEL_INVALID_TYPE))
+ type = camel_type_register (
+ CAMEL_STREAM_TYPE,
+ "EMSyncStream",
+ sizeof (EMSyncStream),
+ sizeof (EMSyncStreamClass),
+ (CamelObjectClassInitFunc) em_sync_stream_class_init,
+ NULL,
+ (CamelObjectInitFunc) NULL,
+ (CamelObjectFinalizeFunc) em_sync_stream_finalize);
- g_free(p->buf_data);
- p->buf_data = g_malloc(size);
- p->buf_size = size;
- p->buf_used = 0;
+ return type;
+}
+
+void
+em_sync_stream_set_buffer_size (EMSyncStream *emss, gsize size)
+{
+ if (emss->buffer != NULL)
+ g_string_free (emss->buffer, TRUE);
+ emss->buffer = g_string_sized_new (size);
}
--- evolution-2.10.0/mail/em-subscribe-editor.c.kill-ethread 2007-01-08 11:54:43.000000000 -0500
+++ evolution-2.10.0/mail/em-subscribe-editor.c 2007-03-30 15:47:31.000000000 -0400
@@ -229,7 +229,7 @@
next = (struct _zsubscribe_msg *)e_dlist_remhead(&m->sub->subscribe);
if (next) {
next->sub->subscribe_id = next->msg.seq;
- e_thread_put(mail_thread_new, (EMsg *)next);
+ mail_msg_unordered_push ((mail_msg_t *) next);
} else {
/* should it go off the model instead? */
sub_selection_changed(gtk_tree_view_get_selection(m->sub->tree), m->sub);
@@ -270,7 +270,7 @@
if (sub->subscribe_id == -1) {
sub->subscribe_id = id;
d(printf("running subscribe folder '%s'\n", spath));
- e_thread_put (mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
} else {
d(printf("queueing subscribe folder '%s'\n", spath));
e_dlist_addtail(&sub->subscribe, (EDListNode *)m);
@@ -443,7 +443,7 @@
id = m->msg.seq;
- e_thread_put (mail_thread_new, (EMsg *)m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
return id;
}
--- evolution-2.10.0/mail/mail-mt.h.kill-ethread 2007-01-03 10:34:12.000000000 -0500
+++ evolution-2.10.0/mail/mail-mt.h 2007-03-30 15:47:31.000000000 -0400
@@ -25,14 +25,15 @@
#include <pthread.h>
#include "camel/camel-exception.h"
-#include "libedataserver/e-msgport.h"
+#include "libedataserver/e-flag.h"
#include "camel/camel-object.h"
#include "camel/camel-operation.h"
typedef struct _mail_msg {
- EMsg msg; /* parent type */
+ EFlag *processed; /* optional */
struct _mail_msg_op *ops; /* operation functions */
unsigned int seq; /* seq number for synchronisation */
+ gint priority; /* priority (default = 0) */
CamelOperation *cancel; /* a cancellation/status handle */
CamelException ex; /* an initialised camel exception, upto the caller to use this */
struct _mail_msg_priv *priv; /* private for internal use */
@@ -51,8 +52,10 @@
void mail_msg_init(void);
void mail_msg_cleanup (void);
+gboolean mail_in_main_thread (void);
+
/* allocate a new message */
-void *mail_msg_new(mail_msg_op_t *ops, EMsgPort *reply_port, size_t size);
+void *mail_msg_new(mail_msg_op_t *ops, EFlag *processed, size_t size);
void mail_msg_free(void *msg);
void mail_msg_check_error(void *msg);
void mail_msg_cancel(unsigned int msgid);
@@ -60,6 +63,14 @@
void mail_msg_wait_all(void);
int mail_msg_active(unsigned int msgid);
+/* dispatch a message */
+void mail_msg_main_loop_push (mail_msg_t *msg);
+void mail_msg_unordered_push (mail_msg_t *msg);
+void mail_msg_fast_ordered_push (mail_msg_t *msg);
+void mail_msg_slow_ordered_push (mail_msg_t *msg);
+
+typedef void (*MailMsgDispatchFunc) (mail_msg_t *msg);
+
/* To implement the stop button */
void *mail_cancel_hook_add(GDestroyNotify func, void *data);
void mail_cancel_hook_remove(void *handle);
@@ -112,24 +123,6 @@
void mail_enable_stop(void);
void mail_disable_stop(void);
-/* a message port that receives messages in the gui thread, used for sending port */
-extern EMsgPort *mail_gui_port;
-/* a message port that receives messages in the gui thread, used for the reply port */
-extern EMsgPort *mail_gui_reply_port;
-
-/* some globally available threads */
-#ifndef G_OS_WIN32
-extern EThread *mail_thread_queued; /* for operations that can (or should) be queued */
-#else
-EThread *mail_win32_get_mail_thread_queued (void);
-#define mail_thread_queued mail_win32_get_mail_thread_queued ()
-#endif
-extern EThread *mail_thread_new; /* for operations that should run in a new thread each time */
-extern EThread *mail_thread_queued_slow; /* for operations that can (or should) be queued, but take a long time */
-
-/* The main thread. */
-extern pthread_t mail_gui_thread;
-
/* A generic proxy event for anything that can be proxied during the life of the mailer (almost nothing) */
/* Note that almost all objects care about the lifecycle of their events, so this cannot be used */
extern MailAsyncEvent *mail_async_event;
--- evolution-2.10.0/mail/mail-ops.h.kill-ethread 2007-01-03 10:34:12.000000000 -0500
+++ evolution-2.10.0/mail/mail-ops.h 2007-03-30 15:47:31.000000000 -0400
@@ -30,13 +30,14 @@
#pragma }
#endif /* __cplusplus */
+#include "mail-mt.h"
+
#include "camel/camel-store.h"
#include "camel/camel-folder.h"
#include "camel/camel-filter-driver.h"
#include "camel/camel-mime-message.h"
#include "camel/camel-operation.h"
-#include "libedataserver/e-msgport.h"
#include "libedataserver/e-account.h"
void mail_append_mail (CamelFolder *folder, CamelMimeMessage *message, CamelMessageInfo *info,
@@ -55,12 +56,12 @@
void mail_get_message (CamelFolder *folder, const char *uid,
void (*done) (CamelFolder *folder, const char *uid, CamelMimeMessage *msg, void *data),
void *data,
- EThread *thread);
+ MailMsgDispatchFunc dispatch);
void
mail_get_messagex(CamelFolder *folder, const char *uid,
void (*done) (CamelFolder *folder, const char *uid, CamelMimeMessage *msg, void *data, CamelException *),
- void *data, EThread *thread);
+ void *data, MailMsgDispatchFunc dispatch);
/* get several messages */
void mail_get_messages (CamelFolder *folder, GPtrArray *uids,
@@ -70,7 +71,7 @@
/* same for a folder */
int mail_get_folder (const char *uri, guint32 flags,
void (*done) (char *uri, CamelFolder *folder, void *data), void *data,
- EThread *thread);
+ MailMsgDispatchFunc dispatch);
/* and for a store */
int mail_get_store (const char *uri, CamelOperation *op,
--- evolution-2.10.0/mail/em-composer-utils.c.kill-ethread 2007-01-03 10:34:12.000000000 -0500
+++ evolution-2.10.0/mail/em-composer-utils.c 2007-03-30 15:47:31.000000000 -0400
@@ -534,7 +534,7 @@
strcmp (account->drafts_folder_uri, default_drafts_folder_uri) != 0) {
int id;
- id = mail_get_folder (account->drafts_folder_uri, 0, save_draft_folder, &folder, mail_thread_new);
+ id = mail_get_folder (account->drafts_folder_uri, 0, save_draft_folder, &folder, mail_msg_unordered_push);
mail_msg_wait (id);
if (!folder || !account->enabled) {
@@ -1085,7 +1085,7 @@
g_return_if_fail (CAMEL_IS_FOLDER (folder));
g_return_if_fail (uid != NULL);
- mail_get_message (folder, uid, redirect_msg, NULL, mail_thread_new);
+ mail_get_message (folder, uid, redirect_msg, NULL, mail_msg_unordered_push);
}
static void
@@ -1116,7 +1116,7 @@
}
if (msg == NULL) {
- mail_get_messagex(folder, uid, emu_handle_receipt_message, NULL, mail_thread_new);
+ mail_get_messagex(folder, uid, emu_handle_receipt_message, NULL, mail_msg_unordered_push);
camel_message_info_free(info);
return;
}
@@ -1916,7 +1916,7 @@
rd->source = source;
if (rd->source)
g_object_ref(rd->source);
- mail_get_message(folder, uid, reply_to_message, rd, mail_thread_new);
+ mail_get_message(folder, uid, reply_to_message, rd, mail_msg_unordered_push);
return;
}
@@ -2088,5 +2088,5 @@
g_return_if_fail (CAMEL_IS_FOLDER (folder));
g_return_if_fail (uid != NULL);
- mail_get_message (folder, uid, post_reply_to_message, NULL, mail_thread_new);
+ mail_get_message (folder, uid, post_reply_to_message, NULL, mail_msg_unordered_push);
}
--- evolution-2.10.0/mail/mail-folder-cache.c.kill-ethread 2007-01-03 10:34:12.000000000 -0500
+++ evolution-2.10.0/mail/mail-folder-cache.c 2007-03-30 15:47:31.000000000 -0400
@@ -907,7 +907,7 @@
m->store = store;
camel_object_ref (store);
- e_thread_put (mail_thread_queued_slow, (EMsg *) m);
+ mail_msg_slow_ordered_push ((mail_msg_t *) m);
}
static gboolean
@@ -952,7 +952,7 @@
int hook = 0;
g_assert(CAMEL_IS_STORE(store));
- g_assert(pthread_equal(pthread_self(), mail_gui_thread));
+ g_assert(mail_in_main_thread());
LOCK(info_lock);
--- evolution-2.10.0/mail/em-folder-view.c.kill-ethread 2007-03-01 01:06:14.000000000 -0500
+++ evolution-2.10.0/mail/em-folder-view.c 2007-03-30 15:47:31.000000000 -0400
@@ -68,6 +68,7 @@
#include <gtkhtml/gtkhtml-stream.h>
#include <libedataserver/e-data-server-util.h>
+#include <libedataserver/e-msgport.h>
#include "menus/gal-view-etable.h"
#include "menus/gal-view-factory-etable.h"
@@ -693,7 +694,7 @@
static void
emfv_set_folder_uri(EMFolderView *emfv, const char *uri)
{
- mail_get_folder(uri, 0, emfv_got_folder, emfv, mail_thread_queued);
+ mail_get_folder(uri, 0, emfv_got_folder, emfv, mail_msg_fast_ordered_push);
}
static void
@@ -1613,7 +1614,7 @@
data->type = type;
data->source = source;
- mail_get_message (folder, uid, filter_type_got_message, data, mail_thread_new);
+ mail_get_message (folder, uid, filter_type_got_message, data, mail_msg_unordered_push);
}
static void
@@ -1711,7 +1712,7 @@
data->type = type;
data->uri = g_strdup (uri);
- mail_get_message (folder, uid, vfolder_type_got_message, data, mail_thread_new);
+ mail_get_message (folder, uid, vfolder_type_got_message, data, mail_msg_unordered_push);
}
static void
@@ -2370,7 +2371,7 @@
g_object_ref (emfv);
/* TODO: we should manage our own thread stuff, would make cancelling outstanding stuff easier */
e_profile_event_emit("goto.load", emfv->displayed_uid, 0);
- mail_get_messagex(emfv->folder, emfv->displayed_uid, emfv_list_done_message_selected, emfv, mail_thread_queued);
+ mail_get_messagex(emfv->folder, emfv->displayed_uid, emfv_list_done_message_selected, emfv, mail_msg_fast_ordered_push);
} else {
e_profile_event_emit("goto.empty", "", 0);
g_free(emfv->priv->selected_uid);
--- evolution-2.10.0/mail/mail-session.c.kill-ethread 2007-02-26 04:59:59.000000000 -0500
+++ evolution-2.10.0/mail/mail-session.c 2007-03-30 15:47:31.000000000 -0400
@@ -35,7 +35,7 @@
#include <libgnome/gnome-sound.h>
#include <libedataserverui/e-passwords.h>
-#include <libedataserver/e-msgport.h>
+#include <libedataserver/e-flag.h>
#include <camel/camel.h> /* FIXME: this is where camel_init is defined, it shouldn't include everything else */
#include <camel/camel-filter-driver.h>
@@ -283,7 +283,7 @@
/* if !allow_cancel, then we've already replied */
if (m->allow_cancel) {
m->result = button == GTK_RESPONSE_OK;
- e_msgport_reply((EMsg *)m);
+ e_flag_set (m->msg.processed);
}
/* check for pendings */
@@ -364,17 +364,18 @@
alert_user(CamelSession *session, CamelSessionAlertType type, const char *prompt, gboolean cancel)
{
MailSession *mail_session = MAIL_SESSION (session);
- struct _user_message_msg *m, *r;
- EMsgPort *user_message_reply = NULL;
+ struct _user_message_msg *m;
+ EFlag *processed = NULL;
gboolean ret;
if (!mail_session->interactive)
return FALSE;
if (cancel)
- user_message_reply = e_msgport_new ();
- m = mail_msg_new (&user_message_op, user_message_reply, sizeof (*m));
- m->ismain = pthread_equal(pthread_self(), mail_gui_thread);
+ processed = e_flag_new ();
+
+ m = mail_msg_new (&user_message_op, processed, sizeof (*m));
+ m->ismain = mail_in_main_thread();
m->type = type;
m->prompt = g_strdup(prompt);
m->allow_cancel = cancel;
@@ -382,18 +383,14 @@
if (m->ismain)
do_user_message((struct _mail_msg *)m);
else {
- extern EMsgPort *mail_gui_port2;
-
- e_msgport_put(mail_gui_port2, (EMsg *)m);
+ mail_msg_main_loop_push((mail_msg_t *) m);
}
if (cancel) {
- r = (struct _user_message_msg *)e_msgport_wait(user_message_reply);
- g_assert(m == r);
-
+ e_flag_wait (processed);
ret = m->result;
mail_msg_free(m);
- e_msgport_destroy(user_message_reply);
+ e_flag_free (processed);
} else
ret = TRUE;
@@ -686,7 +683,7 @@
/* flush/cancel pending user messages */
while ((um = (struct _user_message_msg *) e_dlist_remhead (&message_list))) {
d(printf ("Flusing message request: %s\n", um->prompt));
- e_msgport_reply((EMsg *) um);
+ e_flag_set (um->msg.processed);
}
/* and the current */
--- evolution-2.10.0/mail/mail-mt.c.kill-ethread 2007-01-03 10:34:12.000000000 -0500
+++ evolution-2.10.0/mail/mail-mt.c 2007-03-30 15:47:31.000000000 -0400
@@ -29,7 +29,6 @@
#include <gtk/gtk.h>
#include <libgnome/gnome-i18n.h>
-#include <libedataserver/e-msgport.h>
#include <libedataserver/e-data-server-util.h>
#include <camel/camel-url.h>
@@ -82,13 +81,9 @@
static pthread_mutex_t mail_msg_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t mail_msg_cond = PTHREAD_COND_INITIALIZER;
-pthread_t mail_gui_thread;
-
MailAsyncEvent *mail_async_event;
-static void mail_msg_destroy(EThread *e, EMsg *msg, void *data);
-
-void *mail_msg_new(mail_msg_op_t *ops, EMsgPort *reply_port, size_t size)
+void *mail_msg_new(mail_msg_op_t *ops, EFlag *processed, size_t size)
{
struct _mail_msg *msg;
@@ -112,7 +107,6 @@
fprintf(log, "Logging async operations\n");
if (log_locks) {
- fprintf(log, "Logging lock operations, mail_gui_thread = %" G_GINT64_MODIFIER "x\n\n", e_util_pthread_id(mail_gui_thread));
fprintf(log, "%" G_GINT64_MODIFIER "x: lock mail_msg_lock\n", e_util_pthread_id(pthread_self()));
}
} else {
@@ -123,9 +117,9 @@
}
#endif
msg = g_malloc0(size);
+ msg->processed = processed; /* owned by caller */
msg->ops = ops;
msg->seq = mail_msg_seq++;
- msg->msg.reply_port = reply_port;
msg->cancel = camel_operation_new(mail_operation_status, GINT_TO_POINTER(msg->seq));
camel_exception_init(&msg->ex);
msg->priv = g_malloc0(sizeof(*msg->priv));
@@ -308,9 +302,8 @@
void mail_msg_wait(unsigned int msgid)
{
struct _mail_msg *m;
- int ismain = pthread_equal(pthread_self(), mail_gui_thread);
- if (ismain) {
+ if (mail_in_main_thread ()) {
MAIL_MT_LOCK(mail_msg_lock);
m = g_hash_table_lookup(mail_msg_active_table, GINT_TO_POINTER(msgid));
while (m) {
@@ -347,9 +340,7 @@
void mail_msg_wait_all(void)
{
- int ismain = pthread_equal(pthread_self(), mail_gui_thread);
-
- if (ismain) {
+ if (mail_in_main_thread ()) {
MAIL_MT_LOCK(mail_msg_lock);
while (g_hash_table_size(mail_msg_active_table) > 0) {
MAIL_MT_UNLOCK(mail_msg_lock);
@@ -420,241 +411,193 @@
MAIL_MT_UNLOCK(mail_msg_lock);
}
-EMsgPort *mail_gui_port;
-static GIOChannel *mail_gui_channel;
-static guint mail_gui_watch;
-
-/* TODO: Merge these, gui_port2 doesn't do any mail_msg processing on the request (replies, forwards, frees) */
-EMsgPort *mail_gui_port2;
-static GIOChannel *mail_gui_channel2;
-static guint mail_gui_watch2;
-
-EMsgPort *mail_gui_reply_port;
-static GIOChannel *mail_gui_reply_channel;
-
-/* a couple of global threads available */
-#ifdef G_OS_WIN32
-#undef mail_thread_queued
-static
-#endif
-EThread *mail_thread_queued; /* for operations that can (or should) be queued */
-EThread *mail_thread_queued_slow; /* for operations that can (or should) be queued, but take a long time */
-EThread *mail_thread_new; /* for operations that should run in a new thread each time */
-
-#ifdef G_OS_WIN32
-EThread *
-mail_win32_get_mail_thread_queued (void)
+#define PERIODIC_RATE_HZ 10
+static guint periodic_source_id = 0;
+static GAsyncQueue *main_loop_queue = NULL;
+static GAsyncQueue *msg_reply_queue = NULL;
+static GThread *main_thread = NULL;
+
+static void
+periodic_cleanup (void)
{
- return mail_thread_queued;
+ periodic_source_id = 0;
+
+ g_assert (main_loop_queue != NULL);
+ g_async_queue_unref (main_loop_queue);
+ main_loop_queue = NULL;
+
+ g_assert (msg_reply_queue != NULL);
+ g_async_queue_unref (msg_reply_queue);
+ msg_reply_queue = NULL;
}
-#endif
static gboolean
-mail_msgport_replied(GIOChannel *source, GIOCondition cond, void *d)
+periodic_processing (void)
{
- EMsgPort *port = (EMsgPort *)d;
- mail_msg_t *m;
+ mail_msg_t *msg;
- while (( m = (mail_msg_t *)e_msgport_get(port))) {
+ g_assert (main_loop_queue != NULL);
+ g_assert (msg_reply_queue != NULL);
-#ifdef MALLOC_CHECK
- checkmem(m);
- checkmem(m->cancel);
- checkmem(m->priv);
-#endif
-
-#ifdef LOG_OPS
- if (log_ops)
- fprintf(log, "%p: Replied to GUI thread (exception `%s'\n", m,
- camel_exception_get_description(&m->ex)?camel_exception_get_description(&m->ex):"None");
-#endif
+ /* check the main loop queue */
+ while ((msg = g_async_queue_try_pop (main_loop_queue)) != NULL) {
+
+ /* If the message has a "processed" EFlag, it must also have
+ * a receive_msg() callback. The receive_msg() callback is
+ * responsible for setting the EFlag, and thread blocked on
+ * the EFlag is reponsible for freeing it. */
+ if (msg->processed != NULL) {
+ g_assert (msg->ops->receive_msg != NULL);
+ msg->ops->receive_msg (msg);
+ } else {
+ if (msg->ops->receive_msg != NULL)
+ msg->ops->receive_msg (msg);
+ if (msg->ops->reply_msg != NULL)
+ msg->ops->reply_msg (msg);
+ mail_msg_free (msg);
+ }
+ }
- if (m->ops->reply_msg)
- m->ops->reply_msg(m);
- mail_msg_check_error(m);
- mail_msg_free(m);
+ /* check the reply queue */
+ while ((msg = g_async_queue_try_pop (msg_reply_queue)) != NULL) {
+ if (msg->ops->reply_msg != NULL)
+ msg->ops->reply_msg (msg);
+ mail_msg_check_error (msg);
+ mail_msg_free (msg);
}
return TRUE;
}
-static gboolean
-mail_msgport_received(GIOChannel *source, GIOCondition cond, void *d)
+static void
+mail_msg_proxy (mail_msg_t *msg)
{
- EMsgPort *port = (EMsgPort *)d;
- mail_msg_t *m;
+ if (msg->ops->describe_msg != NULL) {
+ gchar *text = msg->ops->describe_msg (msg, FALSE);
+ camel_operation_register (msg->cancel);
+ camel_operation_start (msg->cancel, "%s", text);
+ g_free (text);
+ }
+
+ if (msg->ops->receive_msg != NULL) {
+ mail_enable_stop ();
+ msg->ops->receive_msg (msg);
+ mail_disable_stop ();
+ }
+
+ if (msg->ops->describe_msg != NULL) {
+ camel_operation_end (msg->cancel);
+ camel_operation_unregister (msg->cancel);
+ MAIL_MT_LOCK (mail_msg_lock);
+ camel_operation_unref (msg->cancel);
+ msg->cancel = NULL;
+ MAIL_MT_UNLOCK (mail_msg_lock);
+ }
- while (( m = (mail_msg_t *)e_msgport_get(port))) {
-#ifdef MALLOC_CHECK
- checkmem(m);
- checkmem(m->cancel);
- checkmem(m->priv);
-#endif
+ g_async_queue_push (msg_reply_queue, msg);
+}
-#ifdef LOG_OPS
- if (log_ops)
- fprintf(log, "%p: Received at GUI thread\n", m);
-#endif
+void
+mail_msg_cleanup (void)
+{
+ GSource *source;
- if (m->ops->receive_msg)
- m->ops->receive_msg(m);
- if (m->msg.reply_port)
- e_msgport_reply((EMsg *)m);
- else {
- if (m->ops->reply_msg)
- m->ops->reply_msg(m);
- mail_msg_free(m);
- }
- }
+ mail_msg_wait_all();
- return TRUE;
+ /* stop periodic processing */
+ source = g_main_context_find_source_by_id (
+ g_main_context_default (), periodic_source_id);
+ g_assert (source != NULL);
+ g_source_destroy (source);
}
-/* Test code, lighterwight, more configurable calls */
-static gboolean
-mail_msgport_received2(GIOChannel *source, GIOCondition cond, void *d)
+void
+mail_msg_init (void)
{
- EMsgPort *port = (EMsgPort *)d;
- mail_msg_t *m;
+ main_loop_queue = g_async_queue_new ();
+ msg_reply_queue = g_async_queue_new ();
- while (( m = (mail_msg_t *)e_msgport_get(port))) {
-#ifdef LOG_OPS
- if (log_ops)
- fprintf(log, "%p: Received at GUI2 thread\n", m);
-#endif
+ /* start periodic processing */
+ periodic_source_id = g_timeout_add_full (
+ G_PRIORITY_DEFAULT,
+ 1000 / PERIODIC_RATE_HZ,
+ (GSourceFunc) periodic_processing, NULL,
+ (GDestroyNotify) periodic_cleanup);
- if (m->ops->receive_msg)
- m->ops->receive_msg(m);
- else
- mail_msg_free(m);
- }
+ mail_msg_active_table = g_hash_table_new (NULL, NULL);
+ main_thread = g_thread_self ();
- return TRUE;
+ mail_async_event = mail_async_event_new ();
}
-
-static void
-mail_msg_destroy(EThread *e, EMsg *msg, void *data)
+static gint
+mail_msg_compare (const mail_msg_t *msg1, const mail_msg_t *msg2)
{
- mail_msg_t *m = (mail_msg_t *)msg;
+ gint priority1 = msg1->priority;
+ gint priority2 = msg2->priority;
-#ifdef MALLOC_CHECK
- checkmem(m);
- checkmem(m->cancel);
- checkmem(m->priv);
-#endif
+ if (priority1 == priority2)
+ return 0;
- mail_msg_free(m);
+ return (priority1 < priority2) ? 1 : -1;
}
-static void
-mail_msg_received(EThread *e, EMsg *msg, void *data)
+static gpointer
+create_thread_pool (gpointer data)
{
- mail_msg_t *m = (mail_msg_t *)msg;
+ GThreadPool *thread_pool;
+ gint max_threads = GPOINTER_TO_INT (data);
-#ifdef MALLOC_CHECK
- checkmem(m);
- checkmem(m->cancel);
- checkmem(m->priv);
-#endif
+ /* once created, run forever */
+ thread_pool = g_thread_pool_new (
+ (GFunc) mail_msg_proxy, NULL, max_threads, FALSE, NULL);
+ g_thread_pool_set_sort_function (
+ thread_pool, (GCompareDataFunc) mail_msg_compare, NULL);
- if (m->ops->describe_msg) {
- char *text = m->ops->describe_msg(m, FALSE);
+ return thread_pool;
+}
-#ifdef LOG_OPS
- if (log_ops)
- fprintf(log, "%p: Received at thread %" G_GINT64_MODIFIER "x: '%s'\n", m, e_util_pthread_id(pthread_self()), text);
-#endif
+void
+mail_msg_main_loop_push (mail_msg_t *msg)
+{
+ g_async_queue_push_sorted (main_loop_queue, msg,
+ (GCompareDataFunc) mail_msg_compare, NULL);
+}
- d(printf("message received at thread\n"));
- camel_operation_register(m->cancel);
- camel_operation_start(m->cancel, "%s", text);
- g_free(text);
- }
-#ifdef LOG_OPS
- else
- if (log_ops)
- fprintf(log, "%p: Received at thread %" G_GINT64_MODIFIER "x\n", m, e_util_pthread_id(pthread_self()));
-#endif
+void
+mail_msg_unordered_push (mail_msg_t *msg)
+{
+ static GOnce once = G_ONCE_INIT;
- if (m->ops->receive_msg) {
- mail_enable_stop();
- m->ops->receive_msg(m);
- mail_disable_stop();
- }
+ g_once (&once, (GThreadFunc) create_thread_pool, GINT_TO_POINTER (10));
- if (m->ops->describe_msg) {
- camel_operation_end(m->cancel);
- camel_operation_unregister(m->cancel);
- MAIL_MT_LOCK(mail_msg_lock);
- camel_operation_unref(m->cancel);
- m->cancel = NULL;
- MAIL_MT_UNLOCK(mail_msg_lock);
- }
+ g_thread_pool_push ((GThreadPool *) once.retval, msg, NULL);
}
-void mail_msg_cleanup(void)
+void
+mail_msg_fast_ordered_push (mail_msg_t *msg)
{
- mail_msg_wait_all();
-
- e_thread_destroy(mail_thread_queued_slow);
- e_thread_destroy(mail_thread_queued);
- e_thread_destroy(mail_thread_new);
+ static GOnce once = G_ONCE_INIT;
- g_io_channel_unref(mail_gui_channel);
- g_io_channel_unref(mail_gui_reply_channel);
+ g_once (&once, (GThreadFunc) create_thread_pool, GINT_TO_POINTER (1));
- e_msgport_destroy(mail_gui_port);
- e_msgport_destroy(mail_gui_reply_port);
+ g_thread_pool_push ((GThreadPool *) once.retval, msg, NULL);
}
-static guint
-em_channel_setup(EMsgPort **port, GIOChannel **channel, GIOFunc func)
+void
+mail_msg_slow_ordered_push (mail_msg_t *msg)
{
- GSource *source;
- guint id;
+ static GOnce once = G_ONCE_INIT;
- *port = e_msgport_new();
-#ifndef G_OS_WIN32
- *channel = g_io_channel_unix_new(e_msgport_fd(*port));
-#else
- *channel = g_io_channel_win32_new_socket(e_msgport_fd(*port));
-#endif
- source = g_io_create_watch(*channel, G_IO_IN);
- g_source_set_callback(source, (GSourceFunc)func, *port, NULL);
- g_source_set_can_recurse(source, FALSE);
- id = g_source_attach(source, NULL);
- g_source_unref(source);
+ g_once (&once, (GThreadFunc) create_thread_pool, GINT_TO_POINTER (1));
- return id;
+ g_thread_pool_push ((GThreadPool *) once.retval, msg, NULL);
}
-void mail_msg_init(void)
+gboolean
+mail_in_main_thread (void)
{
- em_channel_setup(&mail_gui_reply_port, &mail_gui_reply_channel, mail_msgport_replied);
- mail_gui_watch = em_channel_setup(&mail_gui_port, &mail_gui_channel, mail_msgport_received);
- mail_gui_watch2 = em_channel_setup(&mail_gui_port2, &mail_gui_channel2, mail_msgport_received2);
-
- mail_thread_queued = e_thread_new(E_THREAD_QUEUE);
- e_thread_set_msg_destroy(mail_thread_queued, mail_msg_destroy, 0);
- e_thread_set_msg_received(mail_thread_queued, mail_msg_received, 0);
- e_thread_set_reply_port(mail_thread_queued, mail_gui_reply_port);
-
- mail_thread_queued_slow = e_thread_new(E_THREAD_QUEUE);
- e_thread_set_msg_destroy(mail_thread_queued_slow, mail_msg_destroy, 0);
- e_thread_set_msg_received(mail_thread_queued_slow, mail_msg_received, 0);
- e_thread_set_reply_port(mail_thread_queued_slow, mail_gui_reply_port);
-
- mail_thread_new = e_thread_new(E_THREAD_NEW);
- e_thread_set_msg_destroy(mail_thread_new, mail_msg_destroy, 0);
- e_thread_set_msg_received(mail_thread_new, mail_msg_received, 0);
- e_thread_set_reply_port(mail_thread_new, mail_gui_reply_port);
- e_thread_set_queue_limit(mail_thread_new, 10);
-
- mail_msg_active_table = g_hash_table_new(NULL, NULL);
- mail_gui_thread = pthread_self();
-
- mail_async_event = mail_async_event_new();
+ return (g_thread_self () == main_thread);
}
/* ********************************************************************** */
@@ -723,7 +666,6 @@
{
struct _proxy_msg *m;
int id;
- int ismain = pthread_equal(pthread_self(), mail_gui_thread);
/* we dont have a reply port for this, we dont care when/if it gets executed, just queue it */
m = mail_msg_new(&async_event_op, NULL, sizeof(*m));
@@ -743,12 +685,12 @@
/* We use an idle function instead of our own message port only because the
gui message ports's notification buffer might overflow and deadlock us */
if (type == MAIL_ASYNC_GUI) {
- if (ismain)
+ if (mail_in_main_thread ())
g_idle_add(idle_async_event, m);
else
- e_msgport_put(mail_gui_port, (EMsg *)m);
+ mail_msg_main_loop_push((mail_msg_t *) m);
} else
- e_thread_put(mail_thread_queued, (EMsg *)m);
+ mail_msg_fast_ordered_push ((mail_msg_t *) m);
return id;
}
@@ -842,6 +784,9 @@
m->ret = m->func(p1, p2, i1, p3, p4, p5);
break;
}
+
+ if (mm->processed != NULL)
+ e_flag_set (mm->processed);
}
static struct _mail_msg_op mail_call_op = {
@@ -856,23 +801,22 @@
struct _call_msg *m;
void *ret;
va_list ap;
- EMsgPort *reply = NULL;
- int ismain = pthread_equal(pthread_self(), mail_gui_thread);
+ EFlag *processed = NULL;
va_start(ap, func);
- if (!ismain)
- reply = e_msgport_new();
+ if (!mail_in_main_thread ())
+ processed = e_flag_new ();
- m = mail_msg_new(&mail_call_op, reply, sizeof(*m));
+ m = mail_msg_new(&mail_call_op, processed, sizeof(*m));
m->type = type;
m->func = func;
G_VA_COPY(m->ap, ap);
- if (!ismain) {
- e_msgport_put(mail_gui_port, (EMsg *)m);
- e_msgport_wait(reply);
- e_msgport_destroy(reply);
+ if (processed != NULL) {
+ mail_msg_main_loop_push((mail_msg_t *) m);
+ e_flag_wait (processed);
+ e_flag_free (processed);
} else {
do_call(&m->msg);
}
@@ -909,7 +853,7 @@
busy_state++;
if (busy_state == 1) {
m = mail_msg_new(&set_busy_op, NULL, sizeof(*m));
- e_msgport_put(mail_gui_port, (EMsg *)m);
+ mail_msg_main_loop_push((mail_msg_t *) m);
}
MAIL_MT_UNLOCK(status_lock);
}
@@ -922,7 +866,7 @@
busy_state--;
if (busy_state == 0) {
m = mail_msg_new(&set_busy_op, NULL, sizeof(*m));
- e_msgport_put(mail_gui_port, (EMsg *)m);
+ mail_msg_main_loop_push((mail_msg_t *) m);
}
MAIL_MT_UNLOCK(status_lock);
}
@@ -947,7 +891,7 @@
char *out, *p, *o, c;
int pc;
- g_assert (pthread_equal(mail_gui_thread, pthread_self ()));
+ g_assert (mail_in_main_thread ());
MAIL_MT_LOCK (mail_msg_lock);
@@ -1055,7 +999,7 @@
}
m->pc = pc;
m->data = data;
- e_msgport_put(mail_gui_port, (EMsg *)m);
+ mail_msg_main_loop_push((mail_msg_t *) m);
}
/* ******************** */
--- evolution-2.10.0/plugins/folder-unsubscribe/folder-unsubscribe.c.kill-ethread 2007-01-03 10:34:02.000000000 -0500
+++ evolution-2.10.0/plugins/folder-unsubscribe/folder-unsubscribe.c 2007-03-30 15:47:31.000000000 -0400
@@ -108,5 +108,5 @@
unsub = mail_msg_new (&unsubscribe_op, NULL, sizeof (struct _folder_unsub_t));
unsub->uri = g_strdup (target->uri);
- e_thread_put (mail_thread_new, (EMsg *) unsub);
+ mail_msg_unordered_push ((mail_msg_t *) unsub);
}
--- evolution-2.10.0/plugins/mark-all-read/mark-all-read.c.kill-ethread 2007-01-03 10:34:03.000000000 -0500
+++ evolution-2.10.0/plugins/mark-all-read/mark-all-read.c 2007-03-30 15:47:31.000000000 -0400
@@ -44,7 +44,7 @@
return;
}
- mail_get_folder(t->uri, 0, mar_got_folder, NULL, mail_thread_new);
+ mail_get_folder(t->uri, 0, mar_got_folder, NULL, mail_msg_unordered_push);
}
static void
--- evolution-2.10.0/plugins/exchange-operations/exchange-folder.c.kill-ethread 2007-01-03 10:34:03.000000000 -0500
+++ evolution-2.10.0/plugins/exchange-operations/exchange-folder.c 2007-03-30 15:47:31.000000000 -0400
@@ -134,7 +134,7 @@
inbox_physical_uri = e_folder_get_physical_uri (inbox);
/* To get the CamelStore/Folder */
- mail_get_folder (inbox_physical_uri, 0, exchange_get_folder, target_uri, mail_thread_new);
+ mail_get_folder (inbox_physical_uri, 0, exchange_get_folder, target_uri, mail_msg_unordered_push);
}
--- evolution-2.10.0/plugins/save-attachments/save-attachments.c.kill-ethread 2007-02-26 04:59:58.000000000 -0500
+++ evolution-2.10.0/plugins/save-attachments/save-attachments.c 2007-03-30 15:47:31.000000000 -0400
@@ -407,5 +407,5 @@
camel_object_ref(data->folder);
data->uid = g_strdup(target->uids->pdata[0]);
- mail_get_message(data->folder, data->uid, save_got_message, data, mail_thread_new);
+ mail_get_message(data->folder, data->uid, save_got_message, data, mail_msg_unordered_push);
}
--- evolution-2.10.0/plugins/mailing-list-actions/mailing-list-actions.c.kill-ethread 2007-01-03 10:34:04.000000000 -0500
+++ evolution-2.10.0/plugins/mailing-list-actions/mailing-list-actions.c 2007-03-30 15:47:31.000000000 -0400
@@ -89,7 +89,7 @@
data->uri = strdup (sel->uri);
mail_get_message (sel->folder, (const char*) g_ptr_array_index (sel->uids, 0),
- emla_list_action_do, data, mail_thread_new);
+ emla_list_action_do, data, mail_msg_unordered_push);
}
void emla_list_action_do (CamelFolder *folder, const char *uid, CamelMimeMessage *msg, void *data)
--- evolution-2.10.0/plugins/groupwise-features/share-folder-common.c.kill-ethread 2007-01-03 10:34:02.000000000 -0500
+++ evolution-2.10.0/plugins/groupwise-features/share-folder-common.c 2007-03-30 15:47:31.000000000 -0400
@@ -239,7 +239,7 @@
m->done = done;
g_free (namebuf);
id = m->msg.seq;
- e_thread_put (mail_thread_new, (EMsg *) m);
+ mail_msg_unordered_push ((mail_msg_t *) m);
return id;
}
--- evolution-2.10.0/calendar/gui/alarm-notify/alarm-notify.h.kill-ethread 2007-01-03 10:34:50.000000000 -0500
+++ evolution-2.10.0/calendar/gui/alarm-notify/alarm-notify.h 2007-03-30 15:47:31.000000000 -0400
@@ -39,19 +39,6 @@
typedef struct _AlarmNotifyPrivate AlarmNotifyPrivate;
-typedef struct _AlarmMsg AlarmMsg;
-typedef struct _AlarmMsgPrivate AlarmMsgPrivate;
-
-struct _AlarmMsg {
- EMsg msg;
-
- void (*receive_msg)(EThread *e, struct _AlarmMsg *msg, void *data); /* message received */
- void *data;
-
- /* Private Usage */
- struct _AlarmMsgPrivate *priv;
-};
-
struct _AlarmNotify {
BonoboObject object;
--- evolution-2.10.0/calendar/gui/alarm-notify/alarm-notify.c.kill-ethread 2007-01-03 10:34:50.000000000 -0500
+++ evolution-2.10.0/calendar/gui/alarm-notify/alarm-notify.c 2007-03-30 15:47:31.000000000 -0400
@@ -45,10 +45,6 @@
GMutex *mutex;
};
-EThread *alarm_operation_thread; /* for operations that can (or should) be queued */
-EMsgPort *alarm_reply_port;
-static GIOChannel *alarm_reply_channel;
-
#define d(x) x
@@ -286,72 +282,12 @@
g_mutex_free (priv->mutex);
g_free (priv);
- e_thread_destroy(alarm_operation_thread);
- g_io_channel_unref(alarm_reply_channel);
- e_msgport_destroy(alarm_reply_port);
if (G_OBJECT_CLASS (parent_class)->finalize)
(* G_OBJECT_CLASS (parent_class)->finalize) (object);
}
-static guint
-alarm_channel_setup(EMsgPort **port, GIOChannel **channel, GIOFunc func)
-{
- GSource *source;
- guint id;
-
- d (printf("%s:%d (alarm_channel_setup) - Channel Setup\n ", __FILE__, __LINE__));
- *port = e_msgport_new();
-#ifndef G_OS_WIN32
- *channel = g_io_channel_unix_new(e_msgport_fd(*port));
-#else
- *channel = g_io_channel_win32_new_socket(e_msgport_fd(*port));
-#endif
- source = g_io_create_watch(*channel, G_IO_IN);
- g_source_set_callback(source, (GSourceFunc)func, *port, NULL);
- g_source_set_can_recurse(source, FALSE);
- id = g_source_attach(source, NULL);
- g_source_unref(source);
-
- return id;
-}
-
-static void
-alarm_msg_destroy(EThread *e, EMsg *msg, void *data)
-{
- AlarmMsg *m = (AlarmMsg *)msg;
-
- /* Free the private */
- g_free (m->data); /* Mostly it is a structure allocated as a carrier*/
- g_free (m);
-}
-
-static gboolean
-alarm_msgport_replied(GIOChannel *source, GIOCondition cond, void *d)
-{
- EMsgPort *port = (EMsgPort *)d;
- EMsg *m;
-
- while (( m = e_msgport_get(port))) {
- d (printf("%s:%d (alarm_msgport_replied) - %p: Replied to GUI thread\n", __FILE__, __LINE__, m));
- alarm_msg_destroy(NULL, m, NULL);
- }
-
- return TRUE;
-}
-
-static void
-alarm_msg_received(EThread *e, EMsg *msg, void *data)
-{
- AlarmMsg *m = (AlarmMsg *)msg;
-
- d(printf("%s:%d (alarm_msg_received) - %p: Received at thread %" G_GINT64_MODIFIER "x\n", __FILE__, __LINE__, m, e_util_pthread_id(pthread_self())));
- if (m->receive_msg) {
- m->receive_msg (e, m, data);
- }
-}
-
/**
* alarm_notify_new:
*
@@ -363,23 +299,10 @@
AlarmNotify *
alarm_notify_new (void)
{
- AlarmNotify *an;
-
- d (printf("%s:%d (alarm_notify_new) - Alarm Notify New \n ", __FILE__, __LINE__));
-
- /* Create a thread for alarm queue operation*/
- alarm_channel_setup(&alarm_reply_port, &alarm_reply_channel, alarm_msgport_replied);
-
- alarm_operation_thread = e_thread_new(E_THREAD_QUEUE);
- e_thread_set_msg_destroy(alarm_operation_thread, alarm_msg_destroy, 0);
- e_thread_set_msg_received(alarm_operation_thread, alarm_msg_received, 0);
- e_thread_set_reply_port(alarm_operation_thread, alarm_reply_port);
-
- an = g_object_new (TYPE_ALARM_NOTIFY,
- "poa", bonobo_poa_get_threaded (ORBIT_THREAD_HINT_PER_REQUEST, NULL),
- NULL);
-
- return an;
+ return g_object_new (TYPE_ALARM_NOTIFY,
+ "poa", bonobo_poa_get_threaded (
+ ORBIT_THREAD_HINT_PER_REQUEST, NULL),
+ NULL);
}
static void
--- evolution-2.10.0/calendar/gui/alarm-notify/alarm-queue.c.kill-ethread 2007-01-03 10:34:50.000000000 -0500
+++ evolution-2.10.0/calendar/gui/alarm-notify/alarm-queue.c 2007-03-30 15:47:31.000000000 -0400
@@ -115,9 +115,6 @@
static int tray_blink_state = FALSE;
static AlarmNotify *an;
-/* Main Tasks thread for dealing with the global structures */
-extern EThread *alarm_operation_thread;
-
/* Structure that stores a client we are monitoring */
typedef struct {
/* Monitored client */
@@ -199,6 +196,40 @@
static void load_alarms_for_today (ClientAlarms *ca);
static void midnight_refresh_cb (gpointer alarm_id, time_t trigger, gpointer data);
+/* Simple asynchronous message dispatcher */
+
+typedef struct _Message Message;
+typedef void (*MessageFunc) (Message *msg);
+
+struct _Message {
+ MessageFunc func;
+};
+
+static void
+message_proxy (Message *msg)
+{
+ g_return_if_fail (msg->func != NULL);
+
+ msg->func (msg);
+}
+
+static gpointer
+create_thread_pool (void)
+{
+ /* once created, run forever */
+ return g_thread_pool_new ((GFunc) message_proxy, NULL, 1, FALSE, NULL);
+}
+
+static void
+message_push (Message *msg)
+{
+ static GOnce once = G_ONCE_INIT;
+
+ g_once (&once, (GThreadFunc) create_thread_pool, NULL);
+
+ g_thread_pool_push ((GThreadPool *) once.retval, msg, NULL);
+}
+
/* Queues an alarm trigger for midnight so that we can load the next day's worth
* of alarms.
*/
@@ -237,47 +268,41 @@
}
struct _midnight_refresh_msg {
+ Message header;
gboolean remove;
};
/* Loads the alarms for the new day every midnight */
static void
-midnight_refresh_async (EThread *e, AlarmMsg *msg, void *data)
+midnight_refresh_async (struct _midnight_refresh_msg *msg)
{
- struct _midnight_refresh_msg *list = msg->data;
-
d(printf("%s:%d (midnight_refresh_async) \n",__FILE__, __LINE__));
/* Re-load the alarms for all clients */
g_hash_table_foreach (client_alarms_hash, add_client_alarms_cb, NULL);
/* Re-schedule the midnight update */
- if (list->remove && midnight_refresh_id != NULL) {
+ if (msg->remove && midnight_refresh_id != NULL) {
d(printf("%s:%d (midnight_refresh_async) - Reschedule the midnight update \n",__FILE__, __LINE__));
alarm_remove (midnight_refresh_id);
midnight_refresh_id = NULL;
}
queue_midnight_refresh ();
+
+ g_slice_free (struct _midnight_refresh_msg, msg);
}
static void
midnight_refresh_cb (gpointer alarm_id, time_t trigger, gpointer data)
{
- AlarmMsg *msg;
- struct _midnight_refresh_msg *list;
-
- /* These two structures will be freed by the msg destroy function*/
- msg = malloc (sizeof (AlarmMsg));
- msg->receive_msg = midnight_refresh_async;
-
- list = malloc (sizeof (struct _midnight_refresh_msg));
+ struct _midnight_refresh_msg *msg;
- list->remove = TRUE;
- msg->data = list;
+ msg = g_slice_new (struct _midnight_refresh_msg);
+ msg->header.func = (MessageFunc) midnight_refresh_async;
+ msg->remove = TRUE;
- d(printf("%s:%d (midnight_refresh_cb) - Invoking task for midnight refresh\n",__FILE__, __LINE__));
- e_thread_put(alarm_operation_thread, (EMsg *)msg);
+ message_push ((Message *) msg);
}
/* Looks up a client in the client alarms hash table */
@@ -636,6 +661,7 @@
* alarms.
*/
struct _query_msg {
+ Message header;
ECal *client;
GList *objects;
gpointer data;
@@ -669,7 +695,7 @@
}
static void
-query_objects_changed_async (EThread *e, AlarmMsg *msg, void *data)
+query_objects_changed_async (struct _query_msg *msg)
{
ClientAlarms *ca;
time_t from, day_end;
@@ -678,13 +704,12 @@
icaltimezone *zone;
CompQueuedAlarms *cqa;
GList *l;
- struct _query_msg *list = msg->data;
ECal *client;
GList *objects;
- client = list->client;
- ca = list->data;
- objects = list->objects;
+ client = msg->client;
+ ca = msg->data;
+ objects = msg->objects;
from = config_data_get_last_notification_time ();
if (from == -1)
@@ -773,43 +798,38 @@
comp = NULL;
}
g_list_free (objects);
+
+ g_slice_free (struct _query_msg, msg);
}
static void
query_objects_changed_cb (ECal *client, GList *objects, gpointer data)
{
- AlarmMsg *msg;
- struct _query_msg *list;
+ struct _query_msg *msg;
- /* These two structures will be freed by the msg destroy function*/
- msg = malloc (sizeof (AlarmMsg));
- msg->receive_msg = query_objects_changed_async;
- list = malloc (sizeof (struct _query_msg));
- list->client = client;
- list->objects = duplicate_ical (objects);
- list->data = data;
- msg->data = list;
-
- d(printf("%s:%d (query_objects_changed_cb) - Posting a task\n",__FILE__, __LINE__));
- e_thread_put(alarm_operation_thread, (EMsg *)msg);
+ msg = g_slice_new (struct _query_msg);
+ msg->header.func = (MessageFunc) query_objects_changed_async;
+ msg->client = client;
+ msg->objects = duplicate_ical (objects);
+ msg->data = data;
+ message_push ((Message *) msg);
}
/* Called when a calendar component is removed; we must delete its corresponding
* alarms.
*/
static void
-query_objects_removed_async (EThread *e, AlarmMsg *msg, void *data)
+query_objects_removed_async (struct _query_msg *msg)
{
ClientAlarms *ca;
GList *l;
- struct _query_msg *list = msg->data;
ECal *client;
GList *objects;
- client = list->client;
- ca = list->data;
- objects = list->objects;
+ client = msg->client;
+ ca = msg->data;
+ objects = msg->objects;
d(printf("%s:%d (query_objects_removed_async) - Removing %d objects\n",__FILE__, __LINE__, g_list_length(objects)));
@@ -822,27 +842,22 @@
}
g_list_free (objects);
+
+ g_slice_free (struct _query_msg, msg);
}
static void
query_objects_removed_cb (ECal *client, GList *objects, gpointer data)
{
- AlarmMsg *msg;
- struct _query_msg *list;
-
- /* These two structures will be freed by the msg destroy function*/
- msg = malloc (sizeof (AlarmMsg));
- msg->receive_msg = query_objects_removed_async;
-
- list = malloc (sizeof (struct _query_msg));
- list->client = client;
- list->objects = duplicate_ecal (objects);
- list->data = data;
- msg->data = list;
+ struct _query_msg *msg;
- d(printf("%s:%d (query_objects_removed_cb) - Posting a task\n",__FILE__, __LINE__));
- e_thread_put(alarm_operation_thread, (EMsg *)msg);
+ msg = g_slice_new (struct _query_msg);
+ msg->header.func = (MessageFunc) query_objects_removed_async;
+ msg->client = client;
+ msg->objects = duplicate_ecal (objects);
+ msg->data = data;
+ message_push ((Message *) msg);
}
@@ -989,20 +1004,19 @@
}
static void
-on_dialog_objs_removed_async (EThread *e, AlarmMsg *msg, void *data)
+on_dialog_objs_removed_async (struct _query_msg *msg)
{
const char *our_uid;
GList *l;
TrayIconData *tray_data;
- struct _query_msg *list = msg->data;
ECal *client;
GList *objects;
d(printf("%s:%d (on_dialog_objs_removed_async)\n",__FILE__, __LINE__));
- client = list->client;
- tray_data = list->data;
- objects = list->objects;
+ client = msg->client;
+ tray_data = msg->data;
+ objects = msg->objects;
e_cal_component_get_uid (tray_data->comp, &our_uid);
g_return_if_fail (our_uid && *our_uid);
@@ -1020,37 +1034,33 @@
tray_data = NULL;
}
}
+
+ g_slice_free (struct _query_msg, msg);
}
static void
on_dialog_objs_removed_cb (ECal *client, GList *objects, gpointer data)
{
- AlarmMsg *msg;
- struct _query_msg *list;
+ struct _query_msg *msg;
- /* These two structures will be freed by the msg destroy function*/
- msg = malloc (sizeof (AlarmMsg));
- msg->receive_msg = on_dialog_objs_removed_async;
-
- list = malloc (sizeof (struct _query_msg));
- list->client = client;
- list->objects = objects;
- list->data = data;
- msg->data = list;
+ msg = g_slice_new (struct _query_msg);
+ msg->header.func = (MessageFunc) on_dialog_objs_removed_async;
+ msg->client = client;
+ msg->objects = objects;
+ msg->data = data;
- d(printf("%s:%d (on_dialog_objs_removed_cb) - Posting a task \n",__FILE__, __LINE__));
- e_thread_put(alarm_operation_thread, (EMsg *)msg);
+ message_push ((Message *) msg);
}
struct _tray_cqa_msg {
+ Message header;
CompQueuedAlarms *cqa;
};
static void
-tray_list_remove_cqa_async(EThread *e, AlarmMsg *msg, void *data)
+tray_list_remove_cqa_async (struct _tray_cqa_msg *msg)
{
- struct _tray_cqa_msg *tmsg = msg->data;
- CompQueuedAlarms *cqa = tmsg->cqa;
+ CompQueuedAlarms *cqa = msg->cqa;
GList *list = tray_icons_list;
d(printf("%s:%d (tray_list_remove_cqa_async) - Removing CQA %p from tray list\n",__FILE__, __LINE__, cqa));
@@ -1087,28 +1097,25 @@
gtk_tree_selection_select_iter (sel, &iter);
}
}
+
+ g_slice_free (struct _tray_cqa_msg, msg);
}
static void
tray_list_remove_cqa (CompQueuedAlarms *cqa)
{
- AlarmMsg *msg;
- struct _tray_cqa_msg *list;
- /* These two structures will be freed by the msg destroy function*/
- msg = malloc (sizeof (AlarmMsg));
- msg->receive_msg = tray_list_remove_cqa_async;
-
- list = malloc (sizeof (struct _tray_cqa_msg));
- list->cqa = cqa;
- msg->data = list;
+ struct _tray_cqa_msg *msg;
+
+ msg = g_slice_new (struct _tray_cqa_msg);
+ msg->header.func = (MessageFunc) tray_list_remove_cqa_async;
+ msg->cqa = cqa;
- d(printf("%s:%d (tray_list_remove_cqa) - Posting a task\n",__FILE__, __LINE__));
- e_thread_put(alarm_operation_thread, (EMsg *)msg);
+ message_push ((Message *) msg);
}
/* Callback used from the alarm notify dialog */
static void
-tray_list_remove_async(EThread *e, AlarmMsg *msg, void *data)
+tray_list_remove_async (Message *msg)
{
GList *list = tray_icons_list;
@@ -1138,55 +1145,50 @@
} else
list = list->next;
}
+
+ g_slice_free (Message, msg);
}
static void
-tray_list_remove_icons ()
+tray_list_remove_icons (void)
{
- AlarmMsg *msg;
-
- /* These two structures will be freed by the msg destroy function*/
- msg = malloc (sizeof (AlarmMsg));
- msg->receive_msg = tray_list_remove_async;
+ Message *msg;
- msg->data = NULL;
+ msg = g_slice_new (Message);
+ msg->func = tray_list_remove_async;
- d(printf("%s:%d (tray_list_remove_icons) - Posting a task\n",__FILE__, __LINE__));
- e_thread_put(alarm_operation_thread, (EMsg *)msg);
+ message_push (msg);
}
struct _tray_msg {
+ Message header;
TrayIconData *data;
};
static void
-tray_list_remove_data_async(EThread *e, AlarmMsg *msg, void *data)
+tray_list_remove_data_async (struct _tray_msg *msg)
{
- struct _tray_msg *tmsg = msg->data;
- TrayIconData *tray_data = tmsg->data;
+ TrayIconData *tray_data = msg->data;
d(printf("%s:%d (tray_list_remove_data_async) - Removing %p from tray list\n",__FILE__, __LINE__, tray_data));
tray_icons_list = g_list_remove_all (tray_icons_list, tray_data);
free_tray_icon_data (tray_data);
tray_data = NULL;
+
+ g_slice_free (struct _tray_msg, msg);
}
static void
tray_list_remove_data (TrayIconData *data)
{
- AlarmMsg *msg;
- struct _tray_msg *list;
- /* These two structures will be freed by the msg destroy function*/
- msg = malloc (sizeof (AlarmMsg));
- msg->receive_msg = tray_list_remove_data_async;
-
- list = malloc (sizeof (struct _tray_msg));
- list->data = data;
- msg->data = list;
+ struct _tray_msg *msg;
+
+ msg = g_slice_new (struct _tray_msg);
+ msg->header.func = (MessageFunc) tray_list_remove_data_async;
+ msg->data = data;
- d(printf("%s:%d (tray_list_remove_data) - Posting a task\n",__FILE__, __LINE__));
- e_thread_put(alarm_operation_thread, (EMsg *)msg);
+ message_push ((Message *) msg);
}
static void
@@ -1394,29 +1396,24 @@
/* Add a new data to tray list */
static void
-tray_list_add_async (EThread *e, AlarmMsg *msg, void *data)
+tray_list_add_async (struct _tray_msg *msg)
{
- struct _tray_msg *list = msg->data;
- d(printf("%s:%d (tray_list_add_async) - Add %p\n",__FILE__, __LINE__, list->data));
- tray_icons_list = g_list_prepend (tray_icons_list, list->data);
+ d(printf("%s:%d (tray_list_add_async) - Add %p\n",__FILE__, __LINE__, msg->data));
+ tray_icons_list = g_list_prepend (tray_icons_list, msg->data);
+
+ g_slice_free (struct _tray_msg, msg);
}
static void
tray_list_add_new (TrayIconData *data)
{
- AlarmMsg *msg;
- struct _tray_msg *list;
+ struct _tray_msg *msg;
- /* These two structures will be freed by the msg destroy function*/
- msg = malloc (sizeof (AlarmMsg));
- msg->receive_msg = tray_list_add_async;
-
- list = malloc (sizeof (struct _tray_msg));
- list->data = data;
- msg->data = list;
-
- d(printf("%s:%d (tray_list_add_new) - Posting a task\n",__FILE__, __LINE__));
- e_thread_put(alarm_operation_thread, (EMsg *)msg);
+ msg = g_slice_new (struct _tray_msg);
+ msg->header.func = (MessageFunc) tray_list_add_async;
+ msg->data = data;
+
+ message_push ((Message *) msg);
}
/* Performs notification of a display alarm */
@@ -1840,21 +1837,13 @@
new_midnight = time_day_end_with_zone (time (NULL), zone);
if (new_midnight > midnight) {
- AlarmMsg *msg;
- struct _midnight_refresh_msg *list;
-
- /* These two structures will be freed by the msg destroy function*/
- msg = malloc (sizeof (AlarmMsg));
- msg->receive_msg = midnight_refresh_async;
-
- list = malloc (sizeof (struct _midnight_refresh_msg));
+ struct _midnight_refresh_msg *msg;
- list->remove = FALSE;
- /* We dont need it. So set it to NULL */
- msg->data = list;
+ msg = g_slice_new (struct _midnight_refresh_msg);
+ msg->header.func = (MessageFunc) midnight_refresh_async;
+ msg->remove = FALSE;
- d(printf("%s:%d (check_midnight_refresh) - Posting a task to refresh\n",__FILE__, __LINE__));
- e_thread_put(alarm_operation_thread, (EMsg *)msg);
+ message_push ((Message *) msg);
}
return TRUE;
@@ -1985,14 +1974,15 @@
}
struct _alarm_client_msg {
+ Message header;
ECal *client;
};
-static void alarm_queue_add_async (EThread *e, AlarmMsg *msg, void *data)
+static void
+alarm_queue_add_async (struct _alarm_client_msg *msg)
{
ClientAlarms *ca;
- struct _alarm_client_msg *list = msg->data;
- ECal *client = list->client;
+ ECal *client = msg->client;
g_return_if_fail (alarm_queue_inited);
g_return_if_fail (client != NULL);
@@ -2023,6 +2013,8 @@
G_CALLBACK (cal_opened_cb),
ca);
}
+
+ g_slice_free (struct _alarm_client_msg, msg);
}
/**
@@ -2042,20 +2034,13 @@
void
alarm_queue_add_client (ECal *client)
{
- AlarmMsg *msg;
- struct _alarm_client_msg *list;
+ struct _alarm_client_msg *msg;
- /* These two structures will be freed by the msg destroy function*/
- msg = malloc (sizeof (AlarmMsg));
- msg->receive_msg = alarm_queue_add_async;
-
- list = malloc (sizeof (struct _alarm_client_msg));
- list->client = client;
- g_object_ref (client);
- msg->data = list;
+ msg = g_slice_new (struct _alarm_client_msg);
+ msg->header.func = (MessageFunc) alarm_queue_add_async;
+ msg->client = g_object_ref (client);
- d(printf("%s:%d (alarm_queue_add_client) - Posting a task\n",__FILE__, __LINE__));
- e_thread_put(alarm_operation_thread, (EMsg *)msg);
+ message_push ((Message *) msg);
}
/* Removes a component an its alarms */
@@ -2107,11 +2092,10 @@
* Removes a calendar client from the alarm queueing system.
**/
static void
-alarm_queue_remove_async (EThread *e, AlarmMsg *msg, void *data)
+alarm_queue_remove_async (struct _alarm_client_msg *msg)
{
ClientAlarms *ca;
- struct _alarm_client_msg *list = msg->data;
- ECal *client = list->client;
+ ECal *client = msg->client;
g_return_if_fail (alarm_queue_inited);
g_return_if_fail (client != NULL);
@@ -2148,24 +2132,20 @@
g_free (ca);
g_hash_table_remove (client_alarms_hash, client);
+
+ g_slice_free (struct _alarm_client_msg, msg);
}
void
alarm_queue_remove_client (ECal *client)
{
- AlarmMsg *msg;
- struct _alarm_client_msg *list;
+ struct _alarm_client_msg *msg;
- /* These two structures will be freed by the msg destroy function*/
- msg = malloc (sizeof (AlarmMsg));
- msg->receive_msg = alarm_queue_remove_async;
-
- list = malloc (sizeof (struct _alarm_client_msg));
- list->client = client;
- msg->data = list;
+ msg = g_slice_new (struct _alarm_client_msg);
+ msg->header.func = (MessageFunc) alarm_queue_remove_async;
+ msg->client = client;
- d(printf("%s:%d (alarm_queue_remove_client) - Posting a task\n",__FILE__, __LINE__));
- e_thread_put(alarm_operation_thread, (EMsg *)msg);
+ message_push ((Message *) msg);
}
/* Update non-time related variables for various structures on modification of an existing component