[Spice-devel] [PATCH 27/30] Do not access EncodersData internal to lock/unlock glz encoding
Frediano Ziglio
fziglio at redhat.com
Tue Jun 7 10:18:05 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 01138a2..b91ddc8 100644
--- a/server/dcc-encoders.c
+++ b/server/dcc-encoders.c
@@ -546,6 +546,20 @@ static void dcc_free_glz_drawable(EncodersData *enc, RedGlzDrawable *drawable)
}
}
+void dcc_glz_encode_lock(EncodersData *enc)
+{
+ if (enc->glz_dict) {
+ pthread_rwlock_wrlock(&enc->glz_dict->encode_lock);
+ }
+}
+
+void dcc_glz_encode_unlock(EncodersData *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 09a86a0..0ee68e9 100644
--- a/server/dcc-encoders.h
+++ b/server/dcc-encoders.h
@@ -45,6 +45,8 @@ void dcc_glz_free_from_drawable_ring(Ring *drawable_ring);
void dcc_glz_detach_from_drawable_ring(Ring *drawable_ring);
void dcc_glz_get_restore_data(EncodersData *enc,
uint8_t *out_id, GlzEncDictRestoreData *out_data);
+void dcc_glz_encode_lock(EncodersData *enc);
+void dcc_glz_encode_unlock(EncodersData *enc);
#define RED_COMPRESS_BUF_SIZE (1024 * 64)
struct RedCompressBuf {
diff --git a/server/display-channel.c b/server/display-channel.c
index bcc2480..d8ed021 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 = dcc_free_some_independent_glz_drawables(&dcc->encoders, n);
- }
+ // encoding using the dictionary is prevented since the following operations might
+ // change the dictionary
+ dcc_glz_encode_lock(&dcc->encoders);
+ n = dcc_free_some_independent_glz_drawables(&dcc->encoders, n);
}
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);
- }
+ dcc_glz_encode_unlock(&dcc->encoders);
}
}
--
2.7.4
More information about the Spice-devel
mailing list