[Spice-devel] [PATCH spice-gtk 06/10] usbredir: Add locking callbacks for libusbredirhost

Christophe Fergeau cfergeau at redhat.com
Fri Dec 23 09:51:35 PST 2011


On Mon, Dec 19, 2011 at 12:24:39PM +0100, Hans de Goede wrote:
> This is a preparation patch for handling usb packet completion in a
> separate thread.

Looks good, except that g_mutex_new/g_mutex_free are being deprecated in
glib 2.31. The old symbols are still here so we should be fine for now, to
avoid them we'll need to do something like
GMutex *mutex;
mutex = g_slice_new (GMutex);
g_mutex_init (&mutex);
return mutex;

Obviously, g_mutex_init isn't in older glib otherwise things would be too
easy so it will need to be conditional on glib version.
No need to do it as part of this patch, we can add this later when glib
2.32 is released.
ACK patch

Christophe

> 
> Signed-off-by: Hans de Goede <hdegoede at redhat.com>
> ---
>  gtk/channel-usbredir.c |   36 ++++++++++++++++++++++++++++++++----
>  1 files changed, 32 insertions(+), 4 deletions(-)
> 
> diff --git a/gtk/channel-usbredir.c b/gtk/channel-usbredir.c
> index 26821c6..dfd1655 100644
> --- a/gtk/channel-usbredir.c
> +++ b/gtk/channel-usbredir.c
> @@ -90,6 +90,12 @@ static void usbredir_log(void *user_data, int level, const char *msg);
>  static int usbredir_read_callback(void *user_data, uint8_t *data, int count);
>  static int usbredir_write_callback(void *user_data, uint8_t *data, int count);
>  static void usbredir_write_flush_callback(void *user_data);
> +
> +static void *usbredir_alloc_lock(void);
> +static void usbredir_lock_lock(void *user_data);
> +static void usbredir_unlock_lock(void *user_data);
> +static void usbredir_free_lock(void *user_data);
> +
>  #endif
>  
>  G_DEFINE_TYPE(SpiceUsbredirChannel, spice_usbredir_channel, SPICE_TYPE_CHANNEL)
> @@ -185,10 +191,10 @@ static gboolean spice_usbredir_channel_open_device(
>                                     usbredir_read_callback,
>                                     usbredir_write_callback,
>                                     usbredir_write_flush_callback,
> -                                   NULL,
> -                                   NULL,
> -                                   NULL,
> -                                   NULL,
> +                                   usbredir_alloc_lock,
> +                                   usbredir_lock_lock,
> +                                   usbredir_unlock_lock,
> +                                   usbredir_free_lock,
>                                     channel, PACKAGE_STRING,
>                                     spice_util_get_debug() ? usbredirparser_debug : usbredirparser_warning,
>                                     usbredirhost_fl_write_cb_owns_buffer);
> @@ -447,6 +453,28 @@ static int usbredir_write_callback(void *user_data, uint8_t *data, int count)
>      return count;
>  }
>  
> +static void *usbredir_alloc_lock(void) {
> +    return g_mutex_new();
> +}
> +
> +static void usbredir_lock_lock(void *user_data) {
> +    GMutex *mutex = user_data;
> +
> +    g_mutex_lock(mutex);
> +}
> +
> +static void usbredir_unlock_lock(void *user_data) {
> +    GMutex *mutex = user_data;
> +
> +    g_mutex_unlock(mutex);
> +}
> +
> +static void usbredir_free_lock(void *user_data) {
> +    GMutex *mutex = user_data;
> +
> +    g_mutex_free(mutex);
> +}
> +
>  /* --------------------------------------------------------------------- */
>  /* coroutine context                                                     */
>  static void spice_usbredir_handle_msg(SpiceChannel *c, SpiceMsgIn *msg)
> -- 
> 1.7.7.4
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20111223/1ee9cead/attachment.pgp>


More information about the Spice-devel mailing list