From: Øyvind Kolås Date: Sat, 12 Nov 2022 22:36:09 +0000 (+0100) Subject: babl: add babl_gc X-Git-Tag: archive/raspbian/1%0.1.106-3+rpi1^2~15^2~1^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=5728b438dc5da0e7b1d25b2320cd111f9003cfcc;p=babl.git babl: add babl_gc 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. --- diff --git a/babl/babl-fish-path.c b/babl/babl-fish-path.c index d06129f..2674c7e 100644 --- a/babl/babl-fish-path.c +++ b/babl/babl-fish-path.c @@ -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, diff --git a/babl/babl.h b/babl/babl.h index 36681b8..51be1dd 100644 --- a/babl/babl.h +++ b/babl/babl.h @@ -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. diff --git a/export-symbols b/export-symbols index 07b4e95..1e38600 100644 --- a/export-symbols +++ b/export-symbols @@ -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