summaryrefslogtreecommitdiff
path: root/libavcodec/pthread.c
diff options
context:
space:
mode:
authorJanne Grunau <janne-libav@jannau.net>2012-01-01 17:35:16 +0100
committerJanne Grunau <janne-libav@jannau.net>2012-01-01 21:11:43 +0100
commitb12d21733975f9001eecb480fc28e5e4473b1327 (patch)
tree273f7243cff7a1c150c4542a919422631d028212 /libavcodec/pthread.c
parentda7c65f0ce2a9c5609cdecbca4336821a92a7aa8 (diff)
threads: limit the number of automatic threads to MAX_AUTO_THREADS
The extra thread added in {frame_}*thread_init was not taken into account. Explicitly sets thread_count to 1 if only one CPU core was detected. Also fixes two typos in comments.
Diffstat (limited to 'libavcodec/pthread.c')
-rw-r--r--libavcodec/pthread.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index 54a0eb3ab7..58c5fcd638 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -186,7 +186,7 @@ static int get_logical_cpus(AVCodecContext *avctx)
nb_cpus = sysconf(_SC_NPROCESSORS_ONLN);
#endif
av_log(avctx, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus);
- return FFMIN(nb_cpus, MAX_AUTO_THREADS);
+ return nb_cpus;
}
@@ -296,9 +296,11 @@ static int thread_init(AVCodecContext *avctx)
if (!thread_count) {
int nb_cpus = get_logical_cpus(avctx);
- // use number of cores + 1 as thread count if there is motre than one
+ // use number of cores + 1 as thread count if there is more than one
if (nb_cpus > 1)
- thread_count = avctx->thread_count = nb_cpus + 1;
+ thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);
+ else
+ thread_count = avctx->thread_count = 1;
}
if (thread_count <= 1) {
@@ -767,9 +769,11 @@ static int frame_thread_init(AVCodecContext *avctx)
if (!thread_count) {
int nb_cpus = get_logical_cpus(avctx);
- // use number of cores + 1 as thread count if there is motre than one
+ // use number of cores + 1 as thread count if there is more than one
if (nb_cpus > 1)
- thread_count = avctx->thread_count = nb_cpus + 1;
+ thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);
+ else
+ thread_count = avctx->thread_count = 1;
}
if (thread_count <= 1) {