Skip to content

Commit

Permalink
threads: limit the number of automatic threads to MAX_AUTO_THREADS
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Janne Grunau committed Jan 1, 2012
1 parent da7c65f commit b12d217
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions libavcodec/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b12d217

Please sign in to comment.