babl: add babl_gc
authorØyvind Kolås <pippin@gimp.org>
Sat, 12 Nov 2022 22:36:09 +0000 (23:36 +0100)
committerØyvind Kolås <pippin@gimp.org>
Sat, 12 Nov 2022 23:18:47 +0000 (00:18 +0100)
The LUT garbage collection was running ad-hoc as a side effect of processing,
this is problematic since it could trigger during processing of other threads
that might be using or freeing the same fish leading to races. The new babl_gc
function is to be called from the main thread, at times when processing is not
occuring, calling babl_gc is not neccesary in short lived commandline tools
and similar.

babl/babl-fish-path.c
babl/babl.h
export-symbols

index d06129fddff93adb88e6df02b5cf5a8d408dfaab..2674c7ebd890764467bb6e2774b7a9c6530af6e6 100644 (file)
@@ -106,8 +106,20 @@ babl_gc_fishes (void)
      fprintf (stdout, "\e[H\e[2J");
   }
   babl_fish_class_for_each (gc_fishes, &context);
-  //malloc_trim (0); 
-  //  is responsibility of higher layers
+}
+
+static long babl_conv_counter = 0;
+
+void
+babl_gc (void)
+{
+  if (babl_conv_counter > 1000 * 1000 * 10) // run gc every 10 megapixels
+  {
+    babl_conv_counter = 0;
+    babl_gc_fishes ();
+    //malloc_trim (0); 
+    //  is responsibility of higher layers
+  }
 }
 
 #define BABL_LIKELY(x)      __builtin_expect(!!(x), 1)
@@ -1227,13 +1239,7 @@ babl_fish_path_process (const Babl *babl,
   }
   else
   {
-    static long conv_counter = 0;
-    conv_counter+=n;
-    if (conv_counter > 1000 * 1000 * 10) // run gc every 10 megapixels
-    {
-      conv_counter = 0;
-      babl_gc_fishes ();
-    }
+    babl_conv_counter+=n;
   }
   process_conversion_path (babl->fish_path.conversion_list,
                            source,
index 36681b83e47454f692f8ddfff501b040d777db3d..51be1ddaa6dd5e9ea3986f3430e28f1d820cc5f8 100644 (file)
@@ -724,6 +724,18 @@ typedef void (*BablFishProcess) (const Babl *babl, const char *src, char *dst, l
 BablFishProcess babl_fish_get_process (const Babl *babl);
 
 
+/**
+ * babl_gc: (skip)
+ *
+ * Do a babl fish garbage collection cycle, should only be called
+ * from the main thread with no concurrent babl processing in other
+ * threads in paralell.
+ *
+ * Since: babl-0.1.98
+ */
+void babl_gc (void);
+
+
 /* values below this are stored associated with this value, it should also be
  * used as a generic alpha zero epsilon in GEGL to keep the threshold effects
  * on one known value.
index 07b4e95d7cde95381f3c83939e2c246db9d30025..1e3860043d0ad6c6e70685456effdd8b224f3dad 100644 (file)
@@ -72,6 +72,7 @@ babl_db_exist_by_id
 babl_db_each
 babl_formats_count
 babl_format_class_for_each
+babl_gc
 babl_model_class_for_each
 babl_type_class_for_each
 babl_conversion_class_for_each