Re: [spice-gtk 2/3] usbredir: Use atomic for UsbDeviceManager::event_thread_run

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

 



Hi

----- Original Message -----
> This variable is accessed from 2 different threads (main thread and USB
> event thread), so some care must be taken to read/write it.
> ---

event_thread_run is a bool, you should make it a gint, probably even volatile.


>  src/usb-device-manager.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
> index 1fc8fc1..1912b62 100644
> --- a/src/usb-device-manager.c
> +++ b/src/usb-device-manager.c
> @@ -1280,7 +1280,7 @@ static gpointer
> spice_usb_device_manager_usb_ev_thread(gpointer user_data)
>      SpiceUsbDeviceManagerPrivate *priv = self->priv;
>      int rc;
>  
> -    while (priv->event_thread_run) {
> +    while (g_atomic_int_get(&priv->event_thread_run)) {
>          rc = libusb_handle_events(priv->context);
>          if (rc && rc != LIBUSB_ERROR_INTERRUPTED) {
>              const char *desc = spice_usbutil_libusb_strerror(rc);
> @@ -1310,7 +1310,7 @@ gboolean
> spice_usb_device_manager_start_event_listening(
>           g_thread_join(priv->event_thread);
>           priv->event_thread = NULL;
>      }
> -    priv->event_thread_run = TRUE;
> +    g_atomic_int_set(&priv->event_thread_run, TRUE);
>      priv->event_thread = g_thread_new("usb_ev_thread",
>                                        spice_usb_device_manager_usb_ev_thread,
>                                        self);
> @@ -1326,7 +1326,7 @@ void spice_usb_device_manager_stop_event_listening(
>  
>      priv->event_listeners--;
>      if (priv->event_listeners == 0)
> -        priv->event_thread_run = FALSE;
> +        g_atomic_int_set(&priv->event_thread_run, FALSE);
>  }
>  
>  static void spice_usb_device_manager_check_redir_on_connect(

Why not use atomic_int_get in dispose() too?

> --
> 2.7.4
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@xxxxxxxxxxxxxxxxxxxxx
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
> 
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]