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 DF2F346E53 for ; Fri, 14 Jul 2023 22:38:42 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C2AF468C629; Sat, 15 Jul 2023 01:38:39 +0300 (EEST) Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6DDA768C209 for ; Sat, 15 Jul 2023 01:38:33 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 9F19420002 for ; Fri, 14 Jul 2023 22:38:32 +0000 (UTC) Date: Sat, 15 Jul 2023 00:38:31 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20230714223831.GQ1093384@pb2> References: <20230707140540.10279-1-nuomi2021@gmail.com> MIME-Version: 1.0 In-Reply-To: X-GND-Sasl: michael@niedermayer.cc Subject: Re: [FFmpeg-devel] [PATCH v2 01/14] vvcdec: add thread executor 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 Content-Type: multipart/mixed; boundary="===============3200884891809843236==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============3200884891809843236== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="d5xRKMqY7hkGAt+u" Content-Disposition: inline --d5xRKMqY7hkGAt+u Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jul 07, 2023 at 10:05:27PM +0800, Nuo Mi wrote: > The executor design pattern was inroduced by java > > it also adapted by python > > Compared to handcrafted thread pool management, it greatly simplifies the= thread code. > --- > libavcodec/Makefile | 1 + > libavcodec/executor.c | 182 ++++++++++++++++++++++++++++++++++++++++ > libavcodec/executor.h | 67 +++++++++++++++ > libavcodec/vvc/Makefile | 4 + > 4 files changed, 254 insertions(+) > create mode 100644 libavcodec/executor.c > create mode 100644 libavcodec/executor.h > create mode 100644 libavcodec/vvc/Makefile [...] > +++ b/libavcodec/executor.h > @@ -0,0 +1,67 @@ > +/* > + * Copyright (C) 2022 Nuo Mi > + * > + * This file is part of FFmpeg. > + * > + * FFmpeg is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * FFmpeg is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with FFmpeg; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1= 301 USA > + */ > + > +#ifndef AVCODEC_EXECUTOR_H > +#define AVCODEC_EXECUTOR_H > + > +typedef struct Executor Executor; > +typedef struct Tasklet Tasklet; > + > +struct Tasklet { > + Tasklet *next; > +}; > + > +typedef struct TaskletCallbacks { > + void *user_data; > + > + int local_context_size; > + > + // return 1 if a's priority > b's priority > + int (*priority_higher)(const Tasklet *a, const Tasklet *b); > + > + // task is ready for run > + int (*ready)(const Tasklet *t, void *user_data); > + > + // run the task > + int (*run)(Tasklet *t, void *local_context, void *user_data); > +} TaskletCallbacks; > + > +/** > + * Alloc executor > + * @param callbacks callback strucutre for executor > + * @param thread_count worker thread number > + * @return return the executor > + */ > +Executor* ff_executor_alloc(const TaskletCallbacks *callbacks, int threa= d_count); > + > +/** > + * Free executor > + * @param e pointer to executor > + */ > +void ff_executor_free(Executor **e); > + > +/** > + * Add task to executor > + * @param e pointer to executor > + * @param t pointer to task. If NULL, it will wakeup one work thread > + */ > +void ff_executor_execute(Executor *e, Tasklet *t); > + > +#endif //AVCODEC_EXECUTOR_H This would be quite useful outside libavcodec In fact id like to use it in libavradio to do the first stage of FFTs (which are the overwhelming bulk of computations ATM) and maybe eventually later stages too Maybe this could be made available to the outside of libavcodec as avpriv_ or av_ ? maybe from libavutil ? thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Take away the freedom of one citizen and you will be jailed, take away the freedom of all citizens and you will be congratulated by your peers in Parliament. --d5xRKMqY7hkGAt+u Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCZLHOYwAKCRBhHseHBAsP qycTAJ9S/loV5bkhQiGuS/mEpojzLMzR4wCfZGv5+ihogjKbttUmJBt2yi/gZYM= =YHkY -----END PGP SIGNATURE----- --d5xRKMqY7hkGAt+u-- --===============3200884891809843236== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============3200884891809843236==--