summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Moizik <kmoizik@redhat.com>2015-08-16 15:35:39 +0300
committerPavel Grunt <pgrunt@redhat.com>2015-10-09 13:31:28 +0200
commit2bbb32428832d7a56ecf40b2ed247c061ae9db94 (patch)
treecdaf0dd285693eb96a4d79f305ec7af20c38f3a4
parent3e13a7c6369587d65d49758245cdbff8366b81a0 (diff)
Usbredir channel: Introduce mutex for USB redirection
This commit introduces channel mutex to allow usage of channel objects in mutithreaded environments. This mutex will be used to protect non thread safe usbredir functions and data structures. Signed-off-by: Kirill Moizik <kmoizik@redhat.com> Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
-rw-r--r--src/channel-usbredir-priv.h4
-rw-r--r--src/channel-usbredir.c19
2 files changed, 23 insertions, 0 deletions
diff --git a/src/channel-usbredir-priv.h b/src/channel-usbredir-priv.h
index 2c4c6f7..c987474 100644
--- a/src/channel-usbredir-priv.h
+++ b/src/channel-usbredir-priv.h
@@ -51,6 +51,10 @@ void spice_usbredir_channel_disconnect_device(SpiceUsbredirChannel *channel);
libusb_device *spice_usbredir_channel_get_device(SpiceUsbredirChannel *channel);
+void spice_usbredir_channel_lock(SpiceUsbredirChannel *channel);
+
+void spice_usbredir_channel_unlock(SpiceUsbredirChannel *channel);
+
void spice_usbredir_channel_get_guest_filter(
SpiceUsbredirChannel *channel,
const struct usbredirfilter_rule **rules_ret,
diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
index 89f5c9d..86ce18f 100644
--- a/src/channel-usbredir.c
+++ b/src/channel-usbredir.c
@@ -79,6 +79,7 @@ struct _SpiceUsbredirChannelPrivate {
GSimpleAsyncResult *result;
SpiceUsbAclHelper *acl_helper;
#endif
+ GMutex *flows_mutex;
};
static void channel_set_handlers(SpiceChannelClass *klass);
@@ -107,6 +108,8 @@ static void spice_usbredir_channel_init(SpiceUsbredirChannel *channel)
{
#ifdef USE_USBREDIR
channel->priv = SPICE_USBREDIR_CHANNEL_GET_PRIVATE(channel);
+ channel->priv->flows_mutex = g_new0(GMutex, 1);
+ g_mutex_init(channel->priv->flows_mutex);
#endif
}
@@ -182,6 +185,10 @@ static void spice_usbredir_channel_finalize(GObject *obj)
if (channel->priv->host)
usbredirhost_close(channel->priv->host);
+#ifdef USE_USBREDIR
+ g_mutex_clear(channel->priv->flows_mutex);
+ g_free(channel->priv->flows_mutex);
+#endif
/* Chain up to the parent class */
if (G_OBJECT_CLASS(spice_usbredir_channel_parent_class)->finalize)
@@ -561,6 +568,18 @@ static void *usbredir_alloc_lock(void) {
#endif
}
+void spice_usbredir_channel_lock(SpiceUsbredirChannel *channel)
+{
+ g_return_if_fail(SPICE_IS_USBREDIR_CHANNEL(channel));
+ g_mutex_lock(channel->priv->flows_mutex);
+}
+
+void spice_usbredir_channel_unlock(SpiceUsbredirChannel *channel)
+{
+ g_return_if_fail(SPICE_IS_USBREDIR_CHANNEL(channel));
+ g_mutex_unlock(channel->priv->flows_mutex);
+}
+
static void usbredir_lock_lock(void *user_data) {
GMutex *mutex = user_data;