]> git.sesse.net Git - x264/commitdiff
Change priority handling on some OSs
authorSteven Walters <kemuri9@gmail.com>
Wed, 2 Sep 2009 19:33:50 +0000 (12:33 -0700)
committerFiona Glaser <fiona@x264.com>
Wed, 2 Sep 2009 22:33:18 +0000 (15:33 -0700)
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.

common/osdep.h
encoder/lookahead.c

index 9d6a1e635bc2942b0d6bc687e954dc900b8a8ebf..cb61b14b7f353f8f9ac7a5247e72bd1845e63207 100644 (file)
@@ -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 <unistd.h>
 #define x264_lower_thread_priority(p) { UNUSED int nice_ret = nice(p); }
+#endif /* USE_REAL_PTHREAD */
 #else
 #define x264_lower_thread_priority(p)
 #endif
index 9df0ce35e6ff5efb0acbadbf4368d9d19abe1f42..35ed729d739dbf7a4aa3daf97decfdd424f7f0e9 100644 (file)
@@ -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: