Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- server/image-encoders.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/server/image-encoders.c b/server/image-encoders.c index b23cdf0..a5ee622 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,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_dict_item_check(GlzDictItem *glz_item) +{ + 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); + } +} +#else +static inline void glz_dict_item_check(GlzDictItem *glz_item) +{ +} +#endif static SPICE_GNUC_NORETURN SPICE_GNUC_PRINTF(2, 3) void quic_usr_error(QuicUsrContext *usr, const char *fmt, ...) @@ -370,6 +388,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 +404,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 +507,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 +549,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 +568,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 +589,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 +605,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 +1120,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 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel