[PATCH 5/5] Add some debugging for GlzContext structure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 server/image-encoders.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/server/image-encoders.c b/server/image-encoders.c
index 23c3326..17fdc0f 100644
--- a/server/image-encoders.c
+++ b/server/image-encoders.c
@@ -20,12 +20,15 @@
 #endif
 
 #include <glib.h>
+#include <common/log.h>
 
 #include "image-encoders.h"
 #include "spice-bitmap-utils.h"
 #include "red-worker.h" // red_drawable_unref
 #include "pixmap-cache.h" // MAX_CACHE_CLIENTS
 
+#define GLZ_DEBUG 0
+
 #define ZLIB_DEFAULT_COMPRESSION_LEVEL 3
 
 #define ENCODER_MESSAGE_SIZE 512
@@ -66,6 +69,23 @@ static void encoder_data_init(EncoderData *data);
 static void encoder_data_reset(EncoderData *data);
 static void image_encoders_release_glz(ImageEncoders *enc);
 
+#if GLZ_DEBUG
+static void glz_context_check(GlzContext *glz_context)
+{
+    spice_assert(glz_context);
+    spice_assert(ring_item_is_linked(&glz_context->glz_context_link));
+    spice_assert(ring_item_is_linked(&glz_context->retention_link));
+    spice_assert(glz_context->enc);
+    spice_assert(glz_context->red_drawable);
+    if (ring_item_is_linked(&glz_context->free_link)) {
+        spice_assert(glz_context->context == NULL);
+    }
+}
+#else
+static inline void glz_context_check(GlzContext *glz_context)
+{
+}
+#endif
 
 static SPICE_GNUC_NORETURN SPICE_GNUC_PRINTF(2, 3) void
 quic_usr_error(QuicUsrContext *usr, const char *fmt, ...)
@@ -371,6 +391,7 @@ static void glz_usr_free_image(GlzEncoderUsrContext *usr, GlzUsrImageContext *im
     GlzContext *glz_context = (GlzContext *)image;
     ImageEncoders *drawable_enc = glz_context->enc;
     ImageEncoders *this_enc = SPICE_CONTAINEROF(lz_data, ImageEncoders, glz_data);
+    glz_context_check(glz_context);
     glz_context->context = NULL;
     if (this_enc == drawable_enc) {
         glz_context_free(glz_context);
@@ -386,6 +407,7 @@ static void glz_usr_free_image(GlzEncoderUsrContext *usr, GlzUsrImageContext *im
         ring_add_before(&glz_context->free_link,
                         &drawable_enc->glz_drawables_inst_to_free);
         pthread_mutex_unlock(&drawable_enc->glz_drawables_inst_to_free_lock);
+        glz_context_check(glz_context);
     }
 }
 
@@ -488,7 +510,7 @@ static gboolean glz_context_free(GlzContext *glz_context)
 {
     gboolean ret;
 
-    spice_assert(glz_context);
+    glz_context_check(glz_context);
 
     ring_remove(&glz_context->glz_context_link);
     ring_remove(&glz_context->retention_link);
@@ -529,6 +551,7 @@ int image_encoders_free_some_independent_glz_drawables(ImageEncoders *enc, int l
     while (left_to_free > 0
            && (ring_link = ring_get_head(&enc->glz_orphans)) != NULL) {
         GlzContext *glz_context = SPICE_CONTAINEROF(ring_link, GlzContext, retention_link);
+        glz_context_check(glz_context);
         if (!glz_context_free(glz_context)) {
             --left_to_free;
         }
@@ -547,6 +570,7 @@ void image_encoders_free_glz_drawables_to_free(ImageEncoders* enc)
     pthread_mutex_lock(&enc->glz_drawables_inst_to_free_lock);
     while ((ring_link = ring_get_head(&enc->glz_drawables_inst_to_free))) {
         GlzContext * glz_context = SPICE_CONTAINEROF(ring_link, GlzContext, free_link);
+        glz_context_check(glz_context);
         glz_context_free(glz_context);
     }
     pthread_mutex_unlock(&enc->glz_drawables_inst_to_free_lock);
@@ -567,6 +591,7 @@ void image_encoders_free_glz_drawables(ImageEncoders *enc)
     pthread_rwlock_wrlock(&glz_dict->encode_lock);
     while ((ring_link = ring_get_head(&enc->glz_drawables))) {
         GlzContext *glz_context = SPICE_CONTAINEROF(ring_link, GlzContext, glz_context_link);
+        glz_context_check(glz_context);
         // 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_context);
@@ -582,6 +607,7 @@ void glz_retention_free(GlzImageRetention *ret)
     while ((head = ring_get_head(&ret->ring)) != NULL) {
         GlzContext *glz_context = SPICE_CONTAINEROF(head, GlzContext, retention_link);
 
+        glz_context_check(glz_context);
         ring_remove(head);
         ring_add_before(head, &glz_context->enc->glz_orphans);
     }
@@ -1094,6 +1120,7 @@ static GlzContext *get_glz_context(ImageEncoders *enc, RedDrawable *red_drawable
 
     ring_add_before(&ret->glz_context_link, &enc->glz_drawables);
     ring_add(&glz_retention->ring, &ret->retention_link);
+    glz_context_check(ret);
     return ret;
 }
 
-- 
2.7.4

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]