[Spice-devel] [PATCH v2 27/30] Do not access ImageEncoders internal to lock/unlock glz encoding

Frediano Ziglio fziglio at redhat.com
Thu Jun 9 12:31:47 UTC 2016


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

diff --git a/server/dcc-encoders.c b/server/dcc-encoders.c
index d269b7d..1fccd94 100644
--- a/server/dcc-encoders.c
+++ b/server/dcc-encoders.c
@@ -546,6 +546,20 @@ static void image_encoders_free_glz_drawable(ImageEncoders *enc, RedGlzDrawable
     }
 }
 
+void image_encoders_glz_encode_lock(ImageEncoders *enc)
+{
+    if (enc->glz_dict) {
+        pthread_rwlock_wrlock(&enc->glz_dict->encode_lock);
+    }
+}
+
+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 715a961..d4c241c 100644
--- a/server/dcc-encoders.h
+++ b/server/dcc-encoders.h
@@ -45,6 +45,8 @@ void image_encoders_glz_free_from_drawable_ring(Ring *drawable_ring);
 void image_encoders_glz_detach_from_drawable_ring(Ring *drawable_ring);
 void image_encoders_glz_get_restore_data(ImageEncoders *enc,
                                          uint8_t *out_id, GlzEncDictRestoreData *out_data);
+void image_encoders_glz_encode_lock(ImageEncoders *enc);
+void image_encoders_glz_encode_unlock(ImageEncoders *enc);
 
 #define RED_COMPRESS_BUF_SIZE (1024 * 64)
 struct RedCompressBuf {
diff --git a/server/display-channel.c b/server/display-channel.c
index 5d69b33..2df3081 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -1256,14 +1256,10 @@ void display_channel_free_some(DisplayChannel *display)
 
     spice_debug("#draw=%d", display->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);
-            n = image_encoders_free_some_independent_glz_drawables(&dcc->encoders);
-        }
+        // encoding using the dictionary is prevented since the following operations might
+        // change the dictionary
+        image_encoders_glz_encode_lock(&dcc->encoders);
+        n = image_encoders_free_some_independent_glz_drawables(&dcc->encoders);
     }
 
     while (!ring_is_empty(&display->current_list) && n++ < RED_RELEASE_BUNCH_SIZE) {
@@ -1271,11 +1267,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