Commit 0c92fd587b for ffmpeg

commit 0c92fd587b1530f8c476ed58e307f06585819176
Author: Ramiro Polla <ramiro.polla@gmail.com>
Date:   Wed Dec 2 12:49:54 2026 +0100

    swscale/tests/sws_ops_aarch64: use threading to speed up entries generation

    9.4s -> 1.9s on 8 threads.

    Similar to 2f0848c9bb, but for sws_ops_aarch64.

    Signed-off-by: Ramiro Polla <ramiro.polla@gmail.com>

diff --git a/libswscale/tests/sws_ops_aarch64.c b/libswscale/tests/sws_ops_aarch64.c
index 303dc6d6cf..54b3b0dffe 100644
--- a/libswscale/tests/sws_ops_aarch64.c
+++ b/libswscale/tests/sws_ops_aarch64.c
@@ -23,6 +23,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/bprint.h"
 #include "libavutil/mem.h"
+#include "libavutil/thread.h"
 #include "libavutil/tree.h"
 #include "libswscale/graph.h"
 #include "libswscale/ops.h"
@@ -170,8 +171,13 @@ static int aarch64_op_impl_cmp(const void *a, const void *b)
 }

 /*********************************************************************/
+struct EnumPriv {
+    struct AVTreeNode *root;
+    AVMutex lock;
+};
+
 /* Insert the SwsAArch64OpImplParams structure into the AVTreeNode. */
-static int aarch64_collect_op(const SwsAArch64OpImplParams *params, struct AVTreeNode **root)
+static int aarch64_collect_op(const SwsAArch64OpImplParams *params, struct EnumPriv *s)
 {
     int ret = 0;

@@ -181,7 +187,9 @@ static int aarch64_collect_op(const SwsAArch64OpImplParams *params, struct AVTre
         ret = AVERROR(ENOMEM);
         goto error;
     }
-    av_tree_insert(root, copy, aarch64_op_impl_cmp, &node);
+    ff_mutex_lock(&s->lock);
+    av_tree_insert(&s->root, copy, aarch64_op_impl_cmp, &node);
+    ff_mutex_unlock(&s->lock);
     if (!node)
         copy = NULL;

@@ -194,7 +202,7 @@ error:
 static int collect_ops_compile(SwsContext *ctx, const SwsOpList *ops,
                                SwsCompiledOp *out)
 {
-    struct AVTreeNode **root = (struct AVTreeNode **) ctx->opaque;
+    struct EnumPriv *s = ctx->opaque;
     int ret;

     SwsUOpList *uops = ff_sws_uop_list_alloc();
@@ -218,7 +226,7 @@ static int collect_ops_compile(SwsContext *ctx, const SwsOpList *ops,
     for (int i = 0; i < uops->num_ops; i++) {
         SwsAArch64OpImplParams params = { 0 };
         convert_to_aarch64_impl(&uops->ops[i], block_size, &params);
-        ret = aarch64_collect_op(&params, root);
+        ret = aarch64_collect_op(&params, s);
         if (ret < 0)
             goto end;
         if (params.uop == SWS_UOP_LINEAR_FMA && params.type == SWS_PIXEL_F32) {
@@ -227,7 +235,7 @@ static int collect_ops_compile(SwsContext *ctx, const SwsOpList *ops,
              * and do not use fmla (selected by SWS_BITEXACT).
              */
             params.uop = SWS_UOP_LINEAR;
-            ret = aarch64_collect_op(&params, root);
+            ret = aarch64_collect_op(&params, s);
             if (ret < 0)
                 goto end;
         }
@@ -456,13 +464,16 @@ static int print_op(void *opaque, void *elem)
 /*********************************************************************/
 int main(int argc, char *argv[])
 {
-    struct AVTreeNode *root = NULL;
+    struct EnumPriv s = { 0 };
     int ret = 1;

 #ifdef _WIN32
     _setmode(_fileno(stdout), _O_BINARY);
 #endif

+    if (ff_mutex_init(&s.lock, NULL))
+        return 1;
+
     SwsContext *ctx = sws_alloc_context();
     if (!ctx)
         goto fail;
@@ -472,7 +483,8 @@ int main(int argc, char *argv[])
         goto fail;

     graph->ctx = ctx;
-    ctx->opaque = &root;
+    ctx->opaque = &s;
+    ctx->threads = 0; /* use slice threading to speed up tree building */

     static const SwsFlags flags_list[] = {
         0,
@@ -497,12 +509,13 @@ int main(int argc, char *argv[])
     printf(" * To regenerate, run: make fate-sws-ops-entries-aarch64 GEN=1\n");
     printf(" */\n");
     printf("\n");
-    av_tree_enumerate(root, stdout, NULL, print_op);
+    av_tree_enumerate(s.root, stdout, NULL, print_op);

     ff_sws_graph_free(&graph);

 fail:
-    av_tree_destroy(root);
+    av_tree_destroy(s.root);
     sws_free_context(&ctx);
+    ff_mutex_destroy(&s.lock);
     return ret;
 }