[Spice-devel] [PATCH spice-gtk 06/10] usbredir: Add locking callbacks for libusbredirhost
Hans de Goede
hdegoede at redhat.com
Mon Dec 19 03:24:39 PST 2011
This is a preparation patch for handling usb packet completion in a
separate thread.
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
More information about the Spice-devel
mailing list