On 2011-12-20 17:25:42 -0800, Ronald S. Bultje wrote:
> Hi,
> 
> On Tue, Dec 20, 2011 at 5:02 PM, Janne Grunau <[email protected]>wrote:
> 
> > Uses the non-standard value _SC_NPROCESSORS_ONLN for sysconf() to
> > determine the number of CPUs.
> > ---
> >  configure            |    2 ++
> >  libavcodec/pthread.c |   12 ++++++++++++
> >  2 files changed, 14 insertions(+), 0 deletions(-)
> >
> > diff --git a/configure b/configure
> > index 180578d..3871a5b 100755
> > --- a/configure
> > +++ b/configure
> > @@ -1136,6 +1136,7 @@ HAVE_LIST="
> >     symver
> >     symver_asm_label
> >     symver_gnu_asm
> > +    sysconf
> >     sys_mman_h
> >     sys_resource_h
> >     sys_select_h
> > @@ -2855,6 +2856,7 @@ check_func  setrlimit
> >  check_func  strerror_r
> >  check_func  strptime
> >  check_func  strtok_r
> > +check_func  sysconf
> >  check_func_headers io.h setmode
> >  check_func_headers lzo/lzo1x.h lzo1x_999_compress
> >  check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi
> > diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
> > index 7e03c64..ebc0514 100644
> > --- a/libavcodec/pthread.c
> > +++ b/libavcodec/pthread.c
> > @@ -30,6 +30,11 @@
> >  */
> >
> >  #include "config.h"
> > +
> > +#if HAVE_SYSCONF
> > +#include <unistd.h> /* for sysconf and _SC_NPROCESSORS_ONLN */
> > +#endif
> > +
> >  #include "avcodec.h"
> >  #include "internal.h"
> >  #include "thread.h"
> > @@ -919,6 +924,13 @@ int ff_thread_init(AVCodecContext *avctx)
> >     w32thread_init();
> >  #endif
> >
> > +    if (!avctx->thread_count) {
> > +#if HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
> > +        avctx->thread_count = sysconf(_SC_NPROCESSORS_ONLN);
> > +#endif
> > +        av_log(avctx, AV_LOG_DEBUG, "using %d threads\n",
> > avctx->thread_count);
> > +    }
> >
> 
> Missing #else fallback? (Can simply default to 1.)

I had that first but it will break passing 0 to x264, although it may
be a safe assumption that if our autodetection fails, x264 will also
default to 1 thread.

Janne
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to