From patchwork Sun Jun 30 10:45:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 50221 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:cc64:0:b0:482:c625:d099 with SMTP id k4csp1204298vqv; Sun, 30 Jun 2024 03:45:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVI0iG6o3hfIeLIeFqXV/3j0vqdK/9hHJgQkDyhjjIU3xJFvaDcIKtfkUkFtYOaMgbNgsjA9T9OWM13r5ZIuvolzeCeeuHciE0MjA== X-Google-Smtp-Source: AGHT+IGNtO7Yt0DErFu8bFlg/jATRk6D+O4tARh5S27JIk3BNukfPX11uuJ0EfB9S5Equ4bK4NBN X-Received: by 2002:a05:6512:1384:b0:52d:9ad6:f43f with SMTP id 2adb3069b0e04-52e82643b8cmr2222800e87.5.1719744325895; Sun, 30 Jun 2024 03:45:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719744325; cv=none; d=google.com; s=arc-20160816; b=fdZN+92s/Ohkra88gO9eUyK3Xer9OKmgIFsT6hUfXLXhvNL3IbOFXzJoJmfCxnqOnk E+qnDW5PxRPYsDDfnV2E3Atba/ErliZbTRRVtw6MZf22mi/YYSTeoF7E6/QsmGNDCfU0 PcnSA+BAndAew/v3Rh5N+kIEu9y0zGx5Y/UR4rrFcCPYFD/qS0HzpQcqbzJet9CUzpH6 TW+H6jBdIHK/WzYuyjusRP5mC5fXKH9ZSxQ4g5P6zBJ9ii00FD/lZkDXle7UVz5VIrwV JSD8OGD/KafTPd2hxPtI+x3f77ebIBYkg2kP7a0vM7olgh3azmNTSfO45CEbVKAhSetM VoKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:date:to:from:message-id :dkim-signature:delivered-to; bh=NmrU4+sseNZ2/dZGSoguYfLPQbd7ZLyC0IJyrmzdL78=; fh=HnHYuZ9XgUo86ZRXTLWWmQxhslYEI9B9taZ5X1DLFfc=; b=HNul2xxifIc0S+CJ9gShfX8Bb2Q1qGXLsxwceyvIwl/XvUwkDPTela6qO3ytpiLZgt bqa1U2GOjVz8r1EHf98a8Yb3fdLUNd159Oo/Z5hDhMHgMWB5v6ctZFaXJ1KA+6l1OYXr ekgMnKFCTcPuEUfvc2ZorPjAJiApri4a3jrkl27K9zGSHeu/NTDxZe8BMPpNMQPddWf1 Dj+ckJTFp/NpmgRKX4u6vtUz4Aj+a3yLLNJtueCuW6U0O8ZorFuy5JF17kXq4pv4LJR7 HjxzxbEJXkbyWCAYIB0mQcSdgNOaGif/sv4m22kW/tKwcYOrkr3s06QfwJZFKCDTYjuT A9DQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=YdjPoOPG; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 2adb3069b0e04-52e7ab25b05si1623601e87.214.2024.06.30.03.45.25; Sun, 30 Jun 2024 03:45:25 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=YdjPoOPG; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7C14768C07E; Sun, 30 Jun 2024 13:45:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out203-205-251-84.mail.qq.com (unknown [203.205.251.84]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6763068C07E for ; Sun, 30 Jun 2024 13:45:13 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1719744302; bh=XLvBvaMzkdGikRNZFxDx9O0blZSNxs4MSNKIo+AlHSk=; h=From:To:Cc:Subject:Date; b=YdjPoOPGmhq8y32YQVqYkZQHneYt+uRqez5mKlrJsb2yKQUNPNacM9DduahXkao1o 3CpqsBLodxxGlYH5uvC7gztdXeFFRaiEsgBdkBaW7Q9Yy5vlvplslAi+vQ9Irq64wL awzPJzy2dLF/0/Fvs5H1YQRhYVgqdZ1XQU4RinjY= Received: from ZHILIZHAO-MB1.tencent.com ([121.34.202.77]) by newxmesmtplogicsvrszb16-1.qq.com (NewEsmtp) with SMTP id B411BE28; Sun, 30 Jun 2024 18:45:01 +0800 X-QQ-mid: xmsmtpt1719744301tswmruh0w Message-ID: X-QQ-XMAILINFO: MAiknbc9razuBGUAnycJnCYtV9xA496AV7SqeQxGMHX7g/h88e14e38NaAqnmH VZ6TtEeJasZTAAGkheyOX8NVOMVbtpIswohOWGnnOY7uGf93MpgY+IFi9K9T5znlcLzrnrxyYi5P UnAICc1m+jZlR08EiSaknmdhAQwL8tKPhMoHPV4F37ucd7wbbGvMoY3r04x3VBGjPcX9ssdbzdix 2NiJL66FzGV/039IdUWyVFy3vsNbhSkr+hStsgZD3/p0C/zBpOGoCLFVrYWi1DfoDP+ugoYHkGDz dhrjN7dIm2XNlQ9sTI2sMpcJEGk/VWv72DDwkR57OvSGStKm2IuWR3R+YqNbVgPiGxASzbvKKMtq fWAMzRxGug3noiZnOt1CNXj0Gb3q4dLEmJWtqUAl/DUk1XsRB2Tq020lzDatciWUh7m6zYWt16vx N6Q/NjpICuq8PYrpOYg4TeFRrmgSeF55QLQ++vfCU68tNPbOExGIlwfFXRnawDpJQH1hr9k8xq9I 50k6Oq6IzD5B5NyRZUhtrCc6MYqsduuT4emm1G0Jt0BfL9rz8gj4dgYcHxLSQJNyx9ccLDtBHVOf pYID5IEGNZ3lCnGcIlvDUh5bAkSitJQrdmpKb84NPY9HLlfce+mnYvxyWzX0k24jCR3Ix/K8Dd3h 50lAcbv9gOOmWgVVyqvkyWPzCp3BUh27FtO+55XsFIr0HYJ1C0vfBuYl1jaNHCrHoTk+4OFUVQJe sTU2RzxVL+G2XUPDYJWSgeO4Su8QcbO1gRklaqR6psxkwFK9g8nbSEJOqB+6KH1/pQrxeF2BD4Kp UEoiHU0De0LP3zADkhhUibA2FSrxMMXskjvzIY6RBHAnUCe2c7HEbOeghwS+cC58c6RyHq+Hebp4 4B7BGhLBs/lwKt1yNw0Ovbt/MPfGSxtN7DeZkB3+wNVgKGGVWrotTSLzTocOi+qqUjM5b2km4/z1 +GcJyjacg98gxOb6YJ6FezWgN2ZoSQP3okRbmbj9uy6n4uWaHwdA== X-QQ-XMRINFO: OWPUhxQsoeAVDbp3OJHYyFg= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Sun, 30 Jun 2024 18:45:00 +0800 X-OQ-MSGID: <20240630104500.17749-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avutil/executor: Fix missing check before using mutex 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: HpWpzZ98aVT9 From: Zhao Zhili --- The code can be simplified by always creating mutex/cond. I'm not sure it worth the overhead. Please note !HAVE_THREADS don't have the same problem since it has mock implementation of ff_mutex_lock/unlock. libavutil/executor.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libavutil/executor.c b/libavutil/executor.c index fb20104b58..89058fab2f 100644 --- a/libavutil/executor.c +++ b/libavutil/executor.c @@ -194,14 +194,17 @@ void av_executor_execute(AVExecutor *e, AVTask *t) AVTaskCallbacks *cb = &e->cb; AVTask **prev; - ff_mutex_lock(&e->lock); + if (e->thread_count) + ff_mutex_lock(&e->lock); if (t) { for (prev = &e->tasks; *prev && cb->priority_higher(*prev, t); prev = &(*prev)->next) /* nothing */; add_task(prev, t); } - ff_cond_signal(&e->cond); - ff_mutex_unlock(&e->lock); + if (e->thread_count) { + ff_cond_signal(&e->cond); + ff_mutex_unlock(&e->lock); + } if (!e->thread_count || !HAVE_THREADS) { // We are running in a single-threaded environment, so we must handle all tasks ourselves