[Spice-devel] [PATCH spice-server v4 2/2] Add some debugging for GlzDictItem structure

Frediano Ziglio fziglio at redhat.com
Wed Dec 14 21:27:52 UTC 2016


Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/image-encoders.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Changes since v3:
- do not use inline for empty function.

diff --git a/server/image-encoders.c b/server/image-encoders.c
index b23cdf0..698a737 100644
--- a/server/image-encoders.c
+++ b/server/image-encoders.c
@@ -20,6 +20,7 @@
 #endif
 
 #include <glib.h>
+#include <common/log.h>
 
 #include "image-encoders.h"
 #include "spice-bitmap-utils.h"
@@ -65,6 +66,19 @@ static void encoder_data_init(EncoderData *data);
 static void encoder_data_reset(EncoderData *data);
 static void image_encoders_release_glz(ImageEncoders *enc);
 
+static void glz_dict_item_check(G_GNUC_UNUSED GlzDictItem *glz_item)
+{
+#if GLZ_DEBUG
+    spice_assert(glz_item != NULL);
+    spice_assert(ring_item_is_linked(&glz_item->glz_context_link));
+    spice_assert(ring_item_is_linked(&glz_item->retention_link));
+    spice_assert(glz_item->enc != NULL);
+    spice_assert(glz_item->red_drawable != NULL);
+    if (ring_item_is_linked(&glz_item->free_link)) {
+        spice_assert(glz_item->dict_image_context == NULL);
+    }
+#endif
+}
 
 static SPICE_GNUC_NORETURN SPICE_GNUC_PRINTF(2, 3) void
 quic_usr_error(QuicUsrContext *usr, const char *fmt, ...)
@@ -370,6 +384,7 @@ static void glz_usr_free_image(GlzEncoderUsrContext *usr, GlzUsrImageContext *im
     GlzDictItem *glz_item = (GlzDictItem *)image;
     ImageEncoders *drawable_enc = glz_item->enc;
     ImageEncoders *this_enc = SPICE_CONTAINEROF(lz_data, ImageEncoders, glz_data);
+    glz_dict_item_check(glz_item);
     glz_item->dict_image_context = NULL;
     if (this_enc == drawable_enc) {
         glz_context_free(glz_item);
@@ -385,6 +400,7 @@ static void glz_usr_free_image(GlzEncoderUsrContext *usr, GlzUsrImageContext *im
         ring_add_before(&glz_item->free_link,
                         &drawable_enc->glz_dict_items_to_free);
         pthread_mutex_unlock(&drawable_enc->glz_dict_items_to_free_lock);
+        glz_dict_item_check(glz_item);
     }
 }
 
@@ -487,6 +503,7 @@ static gboolean glz_context_free(GlzDictItem *glz_item)
     gboolean ret;
 
     spice_assert(glz_item);
+    glz_dict_item_check(glz_item);
 
     ring_remove(&glz_item->glz_context_link);
     ring_remove(&glz_item->retention_link);
@@ -528,6 +545,7 @@ int image_encoders_free_some_independent_glz_drawables(ImageEncoders *enc, int m
     while (max_to_free > n
            && (ring_link = ring_get_head(&enc->glz_orphans)) != NULL) {
         GlzDictItem *glz_item = SPICE_CONTAINEROF(ring_link, GlzDictItem, retention_link);
+        glz_dict_item_check(glz_item);
         if (glz_context_free(glz_item)) {
             ++n;
         }
@@ -546,6 +564,7 @@ void image_encoders_free_glz_drawables_to_free(ImageEncoders* enc)
     pthread_mutex_lock(&enc->glz_dict_items_to_free_lock);
     while ((ring_link = ring_get_head(&enc->glz_dict_items_to_free))) {
         GlzDictItem * glz_item = SPICE_CONTAINEROF(ring_link, GlzDictItem, free_link);
+        glz_dict_item_check(glz_item);
         glz_context_free(glz_item);
     }
     pthread_mutex_unlock(&enc->glz_dict_items_to_free_lock);
@@ -566,6 +585,7 @@ void image_encoders_free_glz_drawables(ImageEncoders *enc)
     pthread_rwlock_wrlock(&glz_dict->encode_lock);
     while ((ring_link = ring_get_head(&enc->glz_dict_items))) {
         GlzDictItem *glz_item = SPICE_CONTAINEROF(ring_link, GlzDictItem, glz_context_link);
+        glz_dict_item_check(glz_item);
         // no need to lock the to_free list, since we assured no other thread is encoding and
         // thus not other thread access the to_free list of the channel
         glz_context_free(glz_item);
@@ -581,6 +601,7 @@ void glz_retention_destroy(GlzImageRetention *retention)
     while ((head = ring_get_head(&retention->ring)) != NULL) {
         GlzDictItem *glz_item = SPICE_CONTAINEROF(head, GlzDictItem, retention_link);
 
+        glz_dict_item_check(glz_item);
         ring_remove(head);
         ring_add_before(head, &glz_item->enc->glz_orphans);
     }
@@ -1095,6 +1116,7 @@ static GlzDictItem *get_glz_context(ImageEncoders *enc, RedDrawable *red_drawabl
 
     ring_add_before(&ret->glz_context_link, &enc->glz_dict_items);
     ring_add(&glz_retention->ring, &ret->retention_link);
+    glz_dict_item_check(ret);
     return ret;
 }
 
-- 
2.9.3



More information about the Spice-devel mailing list