diff options
author | Ignacio Casal Quinteiro <icq@gnome.org> | 2014-12-23 10:35:44 +0100 |
---|---|---|
committer | Ignacio Casal Quinteiro <icq@gnome.org> | 2014-12-23 10:38:57 +0100 |
commit | 67c4e73b482555a594865b69fb2a3403e385dd26 (patch) | |
tree | 0798227e2cac3795ec76432f119bc95f88e1eae3 /gusb/gusb-context.c | |
parent | d628256576d783762d1adb02b75ec06367a5794e (diff) | |
download | gusb-67c4e73b482555a594865b69fb2a3403e385dd26.tar.gz |
context: use an atomic int to handle the event thread loop
Diffstat (limited to 'gusb/gusb-context.c')
-rw-r--r-- | gusb/gusb-context.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/gusb/gusb-context.c b/gusb/gusb-context.c index 460f59b..99400ed 100644 --- a/gusb/gusb-context.c +++ b/gusb/gusb-context.c @@ -59,7 +59,7 @@ struct _GUsbContextPrivate GPtrArray *devices; GThread *thread_event; gboolean done_enumerate; - gboolean thread_event_run; + volatile gint thread_event_run; guint hotplug_poll_id; int debug_level; libusb_context *ctx; @@ -463,8 +463,10 @@ g_usb_context_event_thread_cb (gpointer data) { GUsbContext *context = G_USB_CONTEXT (data); GUsbContextPrivate *priv = context->priv; - while (priv->thread_event_run) + + while (g_atomic_int_get (&priv->thread_event_run) > 0) libusb_handle_events (priv->ctx); + return NULL; } @@ -503,7 +505,7 @@ g_usb_context_initable_init (GInitable *initable, } priv->ctx = ctx; - priv->thread_event_run = TRUE; + priv->thread_event_run = 1; priv->thread_event = g_thread_new ("GUsbEventThread", g_usb_context_event_thread_cb, context); @@ -545,7 +547,7 @@ g_usb_context_finalize (GObject *object) GUsbContextPrivate *priv = context->priv; /* this is safe to call even when priv->hotplug_id is unset */ - priv->thread_event_run = FALSE; + g_atomic_int_dec_and_test (&priv->thread_event_run); libusb_hotplug_deregister_callback (priv->ctx, priv->hotplug_id); g_thread_join (priv->thread_event); |