From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 12AC14968E for ; Mon, 17 Jun 2024 05:19:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EB72568D677; Mon, 17 Jun 2024 08:19:50 +0300 (EEST) Received: from out203-205-251-60.mail.qq.com (out203-205-251-60.mail.qq.com [203.205.251.60]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2879C68D586 for ; Mon, 17 Jun 2024 08:19:42 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1718601572; bh=GpEjmRMiCdJzX6XknulKmGDpg8rFk1cTTvXrt8bXujc=; h=From:To:Cc:Subject:Date; b=Ki1Ok2mk7dMFMxOe6EdEMjdTI8onyObj0sd/wU7dIXDauq8jshZ2j9Uzj9esvs6rL em3VrJfEoTk4DFK5PBxoHwDFa7fodDbfdmGITFKBgCw/1reJ9BCsiYmhRcNvNMKneJ U3ov26DNfiNnZ/zfrojOF6WeeZDhFZaxCKG2Z98Q= Received: from localhost.localdomain ([113.108.77.64]) by newxmesmtplogicsvrsza29-0.qq.com (NewEsmtp) with SMTP id 4DEABC98; Mon, 17 Jun 2024 13:19:30 +0800 X-QQ-mid: xmsmtpt1718601570tvw02wvxh Message-ID: X-QQ-XMAILINFO: MmCmH9jyqHC2QUDJLzJBUl46icGRIA/RJ3KmYYeS1z3JjmOc1Zv5wjhbweT/jD DZmP/kvt9n5htDuA/GAfaGT3tnY4UmAZPlNAWk8Q1Ay8GBANo0q+LLQz+XaIGsYlKgV2l8g9HQon Vm1C/DuFiZ1C/dBkcvvgh8ptHzIZiIuz0c8p6U4wQe+ejIlDs4ky7Tfcy/eupVNWB+imvYnDpp8O ++fzD8vB2HA6ADuntlqVQ8q1Xj/XOhtbQFuIMvAMRmQaflLOrCGH24pSnVIKVcih/EAUVWEeCTlG U1ri12HLjshv53QHJMIGqyUETHwwLEGuG2mRWt+dza1bv8sqblTlqQh6koCy3bX5pLTY9jj38WDf yjlcmVChUEdybI636EFGMA/JBN8IdyP7tfR3RpWNTYstjwhVFvTi7Q+OgbytBHNXIPYvsOToveei 56ZaTMOVx6n6eD5lVakNGKbksc5crPppesyMLAc/QQIvjHp2vde7yFDP4oNjPB26OP6htnZNY+hl WHOwOgy3zHJA3vi8STyUsOnWztYpi0Bgfql3/6GwdmVhbO/cDXuoSVHwZt6FIvXtkF+hTsQWDg96 jaAzLRcIAtm+y1LrHG5SdJUZXlCzNYwpkC16C2TnjDxR63MX1rkWPYsRuZG/r9tkP+fHtCNyqX70 yGs53sGkJY7dsuy+7+f/sW+KW97ffdWuWWUEjbHSdnHG/AKDb4QxNh+h4Cv1D1HbW63J72UcmY2i RBBZzXgjKjUZMTAPV3p0btNBkE7e3eE5F4k9lnXTAkvsvHkbHSkhQ0PhkLCBgXGb8IxD4jvbctVL fi873kLxqo3PdeihfcA1XEsmrKjbYWaRF5YxSrit4DR7JjoSNtzzihkYTLcQr1asaqcY1oI3o5H/ oLufDrnWickK+TPmieNnvTmj1UJnPEBj9qX8eLGzgaEG5E85m4jrrvVVgclkXNz4beiFKyYysdXu TWZLhPFaZN3SlSt2mGALCruaof5NIROHuRQOjOorA= X-QQ-XMRINFO: MSVp+SPm3vtS1Vd6Y4Mggwc= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Jun 2024 13:19:26 +0800 X-OQ-MSGID: <20240617051927.249039-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avutil/executor: Allowing thread_count be zero X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Zhao Zhili Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Zhao Zhili When thread_count be zero, it will be run on current thread like !HAVE_THREADS. --- libavutil/executor.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/libavutil/executor.c b/libavutil/executor.c index 26691fe157..fb20104b58 100644 --- a/libavutil/executor.c +++ b/libavutil/executor.c @@ -82,9 +82,11 @@ static int run_one_task(AVExecutor *e, void *lc) /* nothing */; if (*prev) { AVTask *t = remove_task(prev, *prev); - ff_mutex_unlock(&e->lock); + if (e->thread_count > 0) + ff_mutex_unlock(&e->lock); cb->run(t, lc, cb->user_data); - ff_mutex_lock(&e->lock); + if (e->thread_count > 0) + ff_mutex_lock(&e->lock); return 1; } return 0; @@ -146,14 +148,17 @@ AVExecutor* av_executor_alloc(const AVTaskCallbacks *cb, int thread_count) return NULL; e->cb = *cb; - e->local_contexts = av_calloc(thread_count, e->cb.local_context_size); + e->local_contexts = av_calloc(FFMAX(thread_count, 1), e->cb.local_context_size); if (!e->local_contexts) goto free_executor; - e->threads = av_calloc(thread_count, sizeof(*e->threads)); + e->threads = av_calloc(FFMAX(thread_count, 1), sizeof(*e->threads)); if (!e->threads) goto free_executor; + if (!thread_count) + return e; + has_lock = !ff_mutex_init(&e->lock, NULL); has_cond = !ff_cond_init(&e->cond, NULL); @@ -175,9 +180,12 @@ free_executor: void av_executor_free(AVExecutor **executor) { + int thread_count; + if (!executor || !*executor) return; - executor_free(*executor, 1, 1); + thread_count = (*executor)->thread_count; + executor_free(*executor, thread_count, thread_count); *executor = NULL; } @@ -195,9 +203,9 @@ void av_executor_execute(AVExecutor *e, AVTask *t) ff_cond_signal(&e->cond); ff_mutex_unlock(&e->lock); -#if !HAVE_THREADS - // We are running in a single-threaded environment, so we must handle all tasks ourselves - while (run_one_task(e, e->local_contexts)) - /* nothing */; -#endif + if (!e->thread_count || !HAVE_THREADS) { + // We are running in a single-threaded environment, so we must handle all tasks ourselves + while (run_one_task(e, e->local_contexts)) + /* nothing */; + } } -- 2.25.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".