diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/bbdb/bbdb.c | 5 | ||||
-rw-r--r-- | plugins/bbdb/gaimbuddies.c | 5 | ||||
-rw-r--r-- | plugins/dbx-import/dbx-importer.c | 14 | ||||
-rw-r--r-- | plugins/external-editor/external-editor.c | 47 | ||||
-rw-r--r-- | plugins/mail-to-task/mail-to-task.c | 38 | ||||
-rw-r--r-- | plugins/pst-import/pst-importer.c | 14 | ||||
-rw-r--r-- | plugins/publish-calendar/publish-calendar.c | 16 |
7 files changed, 80 insertions, 59 deletions
diff --git a/plugins/bbdb/bbdb.c b/plugins/bbdb/bbdb.c index e0d3ca3e91..b06d168fed 100644 --- a/plugins/bbdb/bbdb.c +++ b/plugins/bbdb/bbdb.c @@ -192,12 +192,13 @@ bbdb_do_thread (const gchar *name, * care of that, thus just add it to the queue */ todo = g_slist_append (todo, td); } else { + GThread *thread; GError *error = NULL; EBookClient *client = bbdb_create_book_client (AUTOMATIC_CONTACTS_ADDRESSBOOK); /* list was empty, add item and create a thread */ todo = g_slist_append (todo, td); - g_thread_create (bbdb_do_in_thread, client, FALSE, &error); + thread = g_thread_try_new (NULL, bbdb_do_in_thread, client, &error); if (error) { g_warning ("%s: Creation of the thread failed with error: %s", G_STRFUNC, error->message); @@ -206,6 +207,8 @@ bbdb_do_thread (const gchar *name, G_UNLOCK (todo); bbdb_do_in_thread (client); G_LOCK (todo); + } else { + g_thread_unref (thread); } } G_UNLOCK (todo); diff --git a/plugins/bbdb/gaimbuddies.c b/plugins/bbdb/gaimbuddies.c index 99352787e9..b59e683c8e 100644 --- a/plugins/bbdb/gaimbuddies.c +++ b/plugins/bbdb/gaimbuddies.c @@ -307,6 +307,7 @@ void bbdb_sync_buddy_list (void) { GList *blist; + GThread *thread; GError *error = NULL; EBookClient *client = NULL; struct sync_thread_data *std; @@ -339,7 +340,7 @@ bbdb_sync_buddy_list (void) syncing = TRUE; - g_thread_create (bbdb_sync_buddy_list_in_thread, std, FALSE, &error); + thread = g_thread_try_new (NULL, bbdb_sync_buddy_list_in_thread, std, &error); if (error) { g_warning ( "%s: Creation of the thread failed with error: %s", @@ -349,6 +350,8 @@ bbdb_sync_buddy_list (void) G_UNLOCK (syncing); bbdb_sync_buddy_list_in_thread (std); G_LOCK (syncing); + } else { + g_thread_unref (thread); } G_UNLOCK (syncing); diff --git a/plugins/dbx-import/dbx-importer.c b/plugins/dbx-import/dbx-importer.c index 14799fb583..7f850ae631 100644 --- a/plugins/dbx-import/dbx-importer.c +++ b/plugins/dbx-import/dbx-importer.c @@ -105,7 +105,7 @@ typedef struct { EImport *import; EImportTarget *target; - GMutex *status_lock; + GMutex status_lock; gchar *status_what; gint status_pc; gint status_timeout_id; @@ -736,7 +736,7 @@ static void dbx_import_free (DbxImporter *m) { g_free (m->status_what); - g_mutex_free (m->status_lock); + g_mutex_clear (&m->status_lock); g_source_remove (m->status_timeout_id); m->status_timeout_id = 0; @@ -764,11 +764,11 @@ dbx_status_timeout (gpointer data) gchar *what; if (importer->status_what) { - g_mutex_lock (importer->status_lock); + g_mutex_lock (&importer->status_lock); what = importer->status_what; importer->status_what = NULL; pc = importer->status_pc; - g_mutex_unlock (importer->status_lock); + g_mutex_unlock (&importer->status_lock); e_import_status ( importer->target->import, @@ -786,11 +786,11 @@ dbx_status (CamelOperation *op, { DbxImporter *importer = data; - g_mutex_lock (importer->status_lock); + g_mutex_lock (&importer->status_lock); g_free (importer->status_what); importer->status_what = g_strdup (what); importer->status_pc = pc; - g_mutex_unlock (importer->status_lock); + g_mutex_unlock (&importer->status_lock); } /* Start the main import operation */ @@ -813,7 +813,7 @@ org_gnome_evolution_readdbx_import (EImport *ei, m->status_timeout_id = g_timeout_add (100, dbx_status_timeout, m); /*m->status_timeout_id = NULL;*/ - m->status_lock = g_mutex_new (); + g_mutex_init (&m->status_lock); m->cancellable = camel_operation_new (); g_signal_connect ( diff --git a/plugins/external-editor/external-editor.c b/plugins/external-editor/external-editor.c index cac0a63ed5..42cdb9f9ff 100644 --- a/plugins/external-editor/external-editor.c +++ b/plugins/external-editor/external-editor.c @@ -53,7 +53,6 @@ static void ee_editor_command_changed (GtkWidget *textbox); static void ee_editor_immediate_launch_changed (GtkWidget *checkbox); -static void async_external_editor (EMsgComposer *composer); static gboolean editor_running (void); static gboolean key_press_cb (GtkWidget *widget, GdkEventKey *event, @@ -249,9 +248,13 @@ numlines (const gchar *text, return lineno; } -void -async_external_editor (EMsgComposer *composer) +static gboolean external_editor_running = FALSE; +static GMutex external_editor_running_lock; + +static gpointer +external_editor_thread (gpointer user_data) { + EMsgComposer *composer = user_data; gchar *filename = NULL; gint status = 0; GSettings *settings; @@ -280,7 +283,8 @@ async_external_editor (EMsgComposer *composer) /* run_error_dialog also calls enable_composer */ g_idle_add ((GSourceFunc) run_error_dialog, data); - return; + + goto finished; } settings = g_settings_new ("org.gnome.evolution.plugin.external-editor"); @@ -339,7 +343,7 @@ async_external_editor (EMsgComposer *composer) g_free (filename); g_free (editor_cmd_line); g_free (editor_cmd); - return; + goto finished; } g_free (editor_cmd_line); g_free (editor_cmd); @@ -351,7 +355,7 @@ async_external_editor (EMsgComposer *composer) #endif d (printf ("\n\nsome problem here with external editor\n\n")); g_idle_add ((GSourceFunc) enable_composer, composer); - return; + goto finished; } else { gchar *buf; @@ -373,6 +377,13 @@ async_external_editor (EMsgComposer *composer) g_free (filename); } } + + finished: + g_mutex_lock (&external_editor_running_lock); + external_editor_running = FALSE; + g_mutex_unlock (&external_editor_running_lock); + + return NULL; } static void launch_editor (GtkAction *action, EMsgComposer *composer) @@ -386,8 +397,13 @@ static void launch_editor (GtkAction *action, EMsgComposer *composer) disable_composer (composer); - editor_thread = g_thread_create ( - (GThreadFunc) async_external_editor, composer, FALSE, NULL); + g_mutex_lock (&external_editor_running_lock); + external_editor_running = TRUE; + g_mutex_unlock (&external_editor_running_lock); + + editor_thread = g_thread_new ( + NULL, external_editor_thread, composer); + g_thread_unref (editor_thread); } static GtkActionEntry entries[] = { @@ -431,21 +447,14 @@ key_press_cb (GtkWidget *widget, return TRUE; } -static void -editor_running_thread_func (GThread *thread, - gpointer running) -{ - if (thread == editor_thread) - *(gboolean*)running = TRUE; -} - -/* Racy? */ static gboolean editor_running (void) { - gboolean running = FALSE; + gboolean running; - g_thread_foreach ((GFunc) editor_running_thread_func, &running); + g_mutex_lock (&external_editor_running_lock); + running = external_editor_running; + g_mutex_unlock (&external_editor_running_lock); return running; } diff --git a/plugins/mail-to-task/mail-to-task.c b/plugins/mail-to-task/mail-to-task.c index 2992fc961f..36801ccb99 100644 --- a/plugins/mail-to-task/mail-to-task.c +++ b/plugins/mail-to-task/mail-to-task.c @@ -559,8 +559,8 @@ struct _manage_comp ECalClient *client; ECalComponent *comp; icalcomponent *stored_comp; /* the one in client already */ - GCond *cond; - GMutex *mutex; + GCond cond; + GMutex mutex; gint mails_count; gint mails_done; gchar *editor_title; @@ -576,10 +576,8 @@ free_manage_comp_struct (struct _manage_comp *mc) g_object_unref (mc->client); if (mc->stored_comp) icalcomponent_free (mc->stored_comp); - if (mc->mutex) - g_mutex_free (mc->mutex); - if (mc->cond) - g_cond_free (mc->cond); + g_mutex_clear (&mc->mutex); + g_cond_clear (&mc->cond); if (mc->editor_title) g_free (mc->editor_title); @@ -681,7 +679,7 @@ comp_editor_closed (CompEditor *editor, /* Signal the do_mail_to_event thread that editor was closed and editor * for next event can be displayed (if any) */ - g_cond_signal (mc->cond); + g_cond_signal (&mc->cond); } /* @@ -807,12 +805,12 @@ do_manage_comp_idle (struct _manage_comp *mc) g_object_unref (edit_comp); } else { g_warning ("Failed to create event editor: %s", error ? error->message : "Unknown error"); - g_cond_signal (mc->cond); + g_cond_signal (&mc->cond); } } else { /* User canceled editing already existing event, so treat it as if he just closed the editor window */ comp_editor_closed (NULL, FALSE, mc); - g_cond_signal (mc->cond); + g_cond_signal (&mc->cond); } if (error) { @@ -979,8 +977,8 @@ do_mail_to_event (AsyncData *data) mc = g_new0 (struct _manage_comp, 1); mc->client = g_object_ref (client); mc->comp = g_object_ref (comp); - mc->mutex = g_mutex_new (); - mc->cond = g_cond_new (); + g_mutex_init (&mc->mutex); + g_cond_init (&mc->cond); mc->mails_count = uids->len; mc->mails_done = i + 1; /* Current task */ mc->editor_title = NULL; @@ -990,9 +988,9 @@ do_mail_to_event (AsyncData *data) /* Wait for user to quit the editor created in previous iteration * before displaying next one */ gboolean can_continue; - g_mutex_lock (oldmc->mutex); - g_cond_wait (oldmc->cond, oldmc->mutex); - g_mutex_unlock (oldmc->mutex); + g_mutex_lock (&oldmc->mutex); + g_cond_wait (&oldmc->cond, &oldmc->mutex); + g_mutex_unlock (&oldmc->mutex); can_continue = oldmc->can_continue; free_manage_comp_struct (oldmc); oldmc = NULL; @@ -1015,9 +1013,9 @@ do_mail_to_event (AsyncData *data) /* Wait for the last editor and then clean up */ if (oldmc) { - g_mutex_lock (oldmc->mutex); - g_cond_wait (oldmc->cond, oldmc->mutex); - g_mutex_unlock (oldmc->mutex); + g_mutex_lock (&oldmc->mutex); + g_cond_wait (&oldmc->cond, &oldmc->mutex); + g_mutex_unlock (&oldmc->mutex); free_manage_comp_struct (oldmc); } } @@ -1220,10 +1218,12 @@ mail_to_event (ECalClientSourceType source_type, else data->selected_text = NULL; - thread = g_thread_create ((GThreadFunc) do_mail_to_event, data, FALSE, &error); + thread = g_thread_try_new (NULL, (GThreadFunc) do_mail_to_event, data, &error); if (!thread) { - g_warning (G_STRLOC ": %s", error->message); + g_warning (G_STRLOC ": %s", error ? error->message : "Unknown error"); g_error_free (error); + } else { + g_thread_unref (thread); } } diff --git a/plugins/pst-import/pst-importer.c b/plugins/pst-import/pst-importer.c index 205bfff333..958b374ebc 100644 --- a/plugins/pst-import/pst-importer.c +++ b/plugins/pst-import/pst-importer.c @@ -109,7 +109,7 @@ struct _PstImporter { EImportTarget *target; gint waiting_open; - GMutex *status_lock; + GMutex status_lock; gchar *status_what; gint status_pc; gint status_timeout_id; @@ -2098,7 +2098,7 @@ pst_import_free (PstImporter *m) g_object_unref (m->cancellable); g_free (m->status_what); - g_mutex_free (m->status_lock); + g_mutex_clear (&m->status_lock); g_source_remove (m->status_timeout_id); m->status_timeout_id = 0; @@ -2125,11 +2125,11 @@ pst_status_timeout (gpointer data) gchar *what; if (importer->status_what) { - g_mutex_lock (importer->status_lock); + g_mutex_lock (&importer->status_lock); what = importer->status_what; importer->status_what = NULL; pc = importer->status_pc; - g_mutex_unlock (importer->status_lock); + g_mutex_unlock (&importer->status_lock); e_import_status (importer->target->import, (EImportTarget *) importer->target, what, pc); } @@ -2145,11 +2145,11 @@ pst_status (CamelOperation *op, { PstImporter *importer = data; - g_mutex_lock (importer->status_lock); + g_mutex_lock (&importer->status_lock); g_free (importer->status_what); importer->status_what = g_strdup (what); importer->status_pc = pc; - g_mutex_unlock (importer->status_lock); + g_mutex_unlock (&importer->status_lock); } static void @@ -2175,7 +2175,7 @@ pst_import (EImport *ei, m->status_timeout_id = g_timeout_add (100, pst_status_timeout, m); /*m->status_timeout_id = NULL;*/ - m->status_lock = g_mutex_new (); + g_mutex_init (&m->status_lock); m->cancellable = camel_operation_new (); g_signal_connect ( diff --git a/plugins/publish-calendar/publish-calendar.c b/plugins/publish-calendar/publish-calendar.c index 4193ae50d4..ab3e36dd6d 100644 --- a/plugins/publish-calendar/publish-calendar.c +++ b/plugins/publish-calendar/publish-calendar.c @@ -182,10 +182,12 @@ publish_uri_async (EPublishUri *uri) GThread *thread = NULL; GError *error = NULL; - thread = g_thread_create ((GThreadFunc) publish_no_succ_info, uri, FALSE, &error); + thread = g_thread_try_new (NULL, (GThreadFunc) publish_no_succ_info, uri, &error); if (!thread) { - g_warning (G_STRLOC ": %s", error->message); + g_warning (G_STRLOC ": %s", error ? error->message : "Unknown error"); g_error_free (error); + } else { + g_thread_unref (thread); } } @@ -993,10 +995,12 @@ e_plugin_lib_enable (EPlugin *ep, uris = g_settings_get_strv (settings, PC_SETTINGS_URIS); g_object_unref (settings); - thread = g_thread_create ((GThreadFunc) publish_uris_set_timeout, uris, FALSE, &error); + thread = g_thread_try_new (NULL, (GThreadFunc) publish_uris_set_timeout, uris, &error); if (!thread) { - g_warning ("Could create thread to set timeout for publishing uris : %s", error->message); + g_warning ("Could create thread to set timeout for publishing uris : %s", error ? error->message : "Unknown error"); g_error_free (error); + } else { + g_thread_unref (thread); } } @@ -1096,12 +1100,14 @@ action_calendar_publish_cb (GtkAction *action, GThread *thread = NULL; GError *error = NULL; - thread = g_thread_create ((GThreadFunc) publish_urls, NULL, FALSE, &error); + thread = g_thread_try_new (NULL, (GThreadFunc) publish_urls, NULL, &error); if (!thread) { /* To Translators: This is shown to a user when creation of a new thread, * where the publishing should be done, fails. Basically, this shouldn't * ever happen, and if so, then something is really wrong. */ error_queue_add (g_strdup (_("Could not create publish thread.")), error); + } else { + g_thread_unref (thread); } } |