[Spice-devel] [PATCH GTK 3/4] call vcard_emul_init from a thread
Christophe Fergeau
cfergeau at redhat.com
Tue Jul 5 01:37:53 PDT 2011
It can blocked for up to 5 seconds when trying to spawn
the pcsc-lite daemon, so better to run it from a thread to avoid
blocking the mainloop. The cold plug insertion events will be
caught from the mainloop thread, so this shouldn't cause issues.
---
gtk/smartcard-manager.c | 31 ++++++++++++++++++++++++-------
1 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/gtk/smartcard-manager.c b/gtk/smartcard-manager.c
index 6d73e15..9565840 100644
--- a/gtk/smartcard-manager.c
+++ b/gtk/smartcard-manager.c
@@ -389,6 +389,29 @@ gboolean spice_smartcard_reader_is_software(SpiceSmartCardReader *reader)
return (strcmp(vreader_get_name((VReader*)reader), SPICE_SOFTWARE_READER_NAME) == 0);
}
+static gpointer spice_vcard_emul_init_thread(gpointer data)
+{
+ VCardEmulError error;
+
+ error = vcard_emul_init(data);
+
+ if (error != VCARD_EMUL_OK) {
+ g_critical("vcard_emul_init() failed: %d", error);
+ }
+
+ return NULL;
+}
+
+static void spice_vcard_emul_init_async(VCardEmulOptions *options)
+{
+ GThread *thread;
+
+ thread = g_thread_create(spice_vcard_emul_init_thread, options, FALSE, NULL);
+ if (thread == NULL) {
+ g_critical("g_thread_new() failed");
+ }
+}
+
G_GNUC_INTERNAL
void spice_smartcard_manager_init_libcacard(SpiceSession *session)
{
@@ -396,7 +419,6 @@ void spice_smartcard_manager_init_libcacard(SpiceSession *session)
VCardEmulOptions *options = NULL;
gchar *dbname = NULL;
GStrv certificates;
- VCardEmulError error;
g_return_if_fail(session != NULL);
g_object_get(G_OBJECT(session),
@@ -430,12 +452,7 @@ void spice_smartcard_manager_init_libcacard(SpiceSession *session)
}
init:
- /* FIXME: sometime this hangs a long time..., cant we make it async? */
- error = vcard_emul_init(options);
-
- if (error != VCARD_EMUL_OK) {
- g_critical("vcard_emul_init() failed: %d", error);
- }
+ spice_vcard_emul_init_async(options);
}
gboolean spice_smartcard_manager_insert_card(SpiceSmartCardManager *manager)
--
1.7.5.4
More information about the Spice-devel
mailing list