From: Steven Walters Date: Wed, 2 Sep 2009 19:33:50 +0000 (-0700) Subject: Change priority handling on some OSs X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bc120190edf7db86f44ed44ffad31271ad1294c7;p=libx264 Change priority handling on some OSs Instead of setting the lookahead thread to max priority, lower all the other threads' priorities instead. This is particularly useful when the "max priority" is "realtime", as in Windows, which can cause some problems. --- diff --git a/common/osdep.h b/common/osdep.h index 9d6a1e63..cb61b14b 100644 --- a/common/osdep.h +++ b/common/osdep.h @@ -222,9 +222,21 @@ static int ALWAYS_INLINE x264_clz( uint32_t x ) } #endif -#if defined(SYS_LINUX) && defined(HAVE_PTHREAD) +#ifdef USE_REAL_PTHREAD +#ifdef SYS_MINGW +#define x264_lower_thread_priority(p)\ +{\ + x264_pthread_t handle = pthread_self();\ + struct sched_param sp;\ + int policy = SCHED_OTHER;\ + pthread_getschedparam( handle, &policy, &sp );\ + sp.sched_priority -= p;\ + pthread_setschedparam( handle, policy, &sp );\ +} +#else #include #define x264_lower_thread_priority(p) { UNUSED int nice_ret = nice(p); } +#endif /* USE_REAL_PTHREAD */ #else #define x264_lower_thread_priority(p) #endif diff --git a/encoder/lookahead.c b/encoder/lookahead.c index 9df0ce35..35ed729d 100644 --- a/encoder/lookahead.c +++ b/encoder/lookahead.c @@ -153,22 +153,8 @@ int x264_lookahead_init( x264_t *h, int i_slicetype_length ) if( x264_macroblock_cache_init( look_h ) ) goto fail; - UNUSED x264_pthread_attr_t attr; - if( x264_pthread_attr_init( &attr ) ) + if( x264_pthread_create( &look_h->thread_handle, NULL, (void *)x264_lookahead_thread, look_h ) ) goto fail; -#if defined(USE_REAL_PTHREAD) && !defined(SYS_LINUX) - int offset = sched_get_priority_max( SCHED_OTHER ); - x264_log( h, X264_LOG_DEBUG, "setting priority of lookahead thread to %d\n", offset ); - struct sched_param sp; - pthread_attr_getschedparam( &attr, &sp ); - sp.sched_priority = offset; - pthread_attr_setschedparam( &attr, &sp ); -#endif - - if( x264_pthread_create( &look_h->thread_handle, &attr, (void *)x264_lookahead_thread, look_h ) ) - goto fail; - - x264_pthread_attr_destroy( &attr ); return 0; fail: