Commit Graph

5 Commits

Author SHA1 Message Date
Zhao Zhili
906b883e7b avutil/executor: Fix stack overflow due to recursive call
av_executor_execute run the task directly when thread is disabled.
The task can schedule a new task by call av_executor_execute. This
forms an implicit recursive call. This patch removed the recursive
call.
2024-07-11 20:26:23 +08:00
Zhao Zhili
54f9469fa1 avutil/executor: Fix missing check before using mutex 2024-07-11 20:24:11 +08:00
Zhao Zhili
baf3123c1c avutil/executor: Allowing thread_count be zero
Before the patch, disable threads support at configure/build time
was the only method to force zero thread in executor. However,
it's common practice for libavcodec to run on caller's thread when
user specify thread number to one. And for WASM environment, whether
threads are supported needs to be detected at runtime. So executor
should support zero thread at runtime.

A single thread executor can be useful, e.g., to handle network
protocol. So we can't take thread_count one as zero thread, which
disabled a valid usercase.

Other libraries take -threads 0 to mean auto. Executor as a low
level utils doesn't do cpu detect. So take thread_count zero as
zero thread, literally.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-06-27 20:54:42 +08:00
Andreas Rheinhardt
790f793844 avutil/common: Don't auto-include mem.h
There are lots of files that don't need it: The number of object
files that actually need it went down from 2011 to 884 here.

Keep it for external users in order to not cause breakages.

Also improve the other headers a bit while just at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-31 00:08:43 +01:00
Nuo Mi
25ecc94d58
avutil: add thread executor
The executor design pattern was introduced by java
<https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/util/concurrent/Executor.html>
it also adapted by python
<https://docs.python.org/3/library/concurrent.futures.html>
Compared to handcrafted thread pool management, it greatly simplifies the thread code.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2023-09-02 02:49:06 +02:00