[Spice-devel] [PATCH v4 15/19] Do not access ImageEncoders internal to lock/unlock glz encoding

Frediano Ziglio fziglio at redhat.com
Tue Jun 14 09:33:07 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 a83794e..7b129e4 100644
--- a/server/dcc-encoders.c
+++ b/server/dcc-encoders.c
@@ -550,6 +550,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 ac61a70..4587a0b 100644
--- a/server/dcc-encoders.h
+++ b/server/dcc-encoders.h
@@ -50,6 +50,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 bddedd9..15d69c4 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -1198,14 +1198,10 @@ void display_channel_free_some(DisplayChannel *display)
     spice_debug("#draw=%d, #glz_draw=%d", display->drawable_count,
                 display->encoder_globals.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);
-            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) {
@@ -1213,11 +1209,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