From baccc1c5417f990ebfc1b6780e2dab255a72ee3c Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Sat, 19 Nov 2022 05:44:44 +0100 Subject: swscale/utils: Avoid calling ff_thread_once() unnecessarily Signed-off-by: Andreas Rheinhardt --- libswscale/utils.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libswscale/utils.c b/libswscale/utils.c index 053c6bb76b..fb788fc330 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -1340,13 +1340,10 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter, int ret = 0; enum AVPixelFormat tmpFmt; static const float float_mult = 1.0f / 255.0f; - static AVOnce rgb2rgb_once = AV_ONCE_INIT; cpu_flags = av_get_cpu_flags(); flags = c->flags; emms_c(); - if (ff_thread_once(&rgb2rgb_once, ff_sws_rgb2rgb_init) != 0) - return AVERROR_UNKNOWN; unscaled = (srcW == dstW && srcH == dstH); @@ -2043,6 +2040,7 @@ fail: // FIXME replace things by appropriate error codes av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) { + static AVOnce rgb2rgb_once = AV_ONCE_INIT; int ret; c->frame_src = av_frame_alloc(); @@ -2050,6 +2048,9 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter, if (!c->frame_src || !c->frame_dst) return AVERROR(ENOMEM); + if (ff_thread_once(&rgb2rgb_once, ff_sws_rgb2rgb_init) != 0) + return AVERROR_UNKNOWN; + if (c->nb_threads != 1) { ret = context_init_threaded(c, srcFilter, dstFilter); if (ret < 0 || c->nb_threads > 1) -- cgit v1.2.3