[Spice-devel] [PATCH v6 3/7] Do not access ImageEncoders internal to lock/unlock glz encoding

Frediano Ziglio fziglio at redhat.com
Thu Jun 16 09:41:40 UTC 2016


Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/dcc-encoders.c    | 16 ++++++++++++++++
 server/dcc-encoders.h    |  2 ++
 server/display-channel.c | 15 ++++-----------
 3 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/server/dcc-encoders.c b/server/dcc-encoders.c
index 7a6a87d..156ce2f 100644
--- a/server/dcc-encoders.c
+++ b/server/dcc-encoders.c
@@ -552,6 +552,22 @@ static void red_glz_drawable_free(RedGlzDrawable *glz_drawable)
     }
 }
 
+gboolean image_encoders_glz_encode_lock(ImageEncoders *enc)
+{
+    if (enc->glz_dict) {
+        pthread_rwlock_wrlock(&enc->glz_dict->encode_lock);
+        return TRUE;
+    }
+    return FALSE;
+}
+
+void image_encoders_glz_encode_unlock(ImageEncoders *enc)
+{
+    if (enc->glz_dict) {
+        pthread_rwlock_unlock(&enc->glz_dict->encode_lock);
+    }
+}
+
 /*
  * Remove from the global lz dictionary some glz_drawables that have no reference to
  * Drawable (their qxl drawables are released too).
diff --git a/server/dcc-encoders.h b/server/dcc-encoders.h
index 284ed74..10119eb 100644
--- a/server/dcc-encoders.h
+++ b/server/dcc-encoders.h
@@ -48,6 +48,8 @@ void image_encoders_free_glz_drawables_to_free(ImageEncoders* enc);
 gboolean image_encoders_glz_create(ImageEncoders *enc, uint8_t id);
 void image_encoders_glz_get_restore_data(ImageEncoders *enc,
                                          uint8_t *out_id, GlzEncDictRestoreData *out_data);
+gboolean image_encoders_glz_encode_lock(ImageEncoders *enc);
+void image_encoders_glz_encode_unlock(ImageEncoders *enc);
 void drawable_free_glz_drawables(struct Drawable *drawable);
 void drawable_detach_glz_drawables(struct Drawable *drawable);
 
diff --git a/server/display-channel.c b/server/display-channel.c
index 4a0094b..2366a98 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -1206,12 +1206,9 @@ void display_channel_free_some(DisplayChannel *display)
     spice_debug("#draw=%d, #glz_draw=%d", display->drawable_count,
                 display->encoder_shared_data.glz_drawable_count);
     FOREACH_CLIENT(display, link, next, dcc) {
-        GlzSharedDictionary *glz_dict = dcc->encoders.glz_dict;
-
-        if (glz_dict) {
-            // encoding using the dictionary is prevented since the following operations might
-            // change the dictionary
-            pthread_rwlock_wrlock(&glz_dict->encode_lock);
+        // encoding using the dictionary is prevented since the following operations might
+        // change the dictionary
+        if (image_encoders_glz_encode_lock(&dcc->encoders)) {
             n = image_encoders_free_some_independent_glz_drawables(&dcc->encoders);
         }
     }
@@ -1221,11 +1218,7 @@ void display_channel_free_some(DisplayChannel *display)
     }
 
     FOREACH_CLIENT(display, link, next, dcc) {
-        GlzSharedDictionary *glz_dict = dcc->encoders.glz_dict;
-
-        if (glz_dict) {
-            pthread_rwlock_unlock(&glz_dict->encode_lock);
-        }
+        image_encoders_glz_encode_unlock(&dcc->encoders);
     }
 }
 
-- 
2.7.4



More information about the Spice-devel mailing list