+/*****************************************************************************
+ * vlc_thread_set_priority: set the priority of the current thread when we
+ * couldn't set it in vlc_thread_create (for instance for the main thread)
+ *****************************************************************************/
+int __vlc_thread_set_priority( vlc_object_t *p_this, char * psz_file,
+ int i_line, int i_priority )
+{
+#if defined( PTH_INIT_IN_PTH_H ) || defined( ST_INIT_IN_ST_H )
+#elif defined( WIN32 ) || defined( UNDER_CE )
+ if( !SetThreadPriority(GetCurrentThread(), i_priority) )
+ {
+ msg_Warn( p_this, "couldn't set a faster priority" );
+ return 1;
+ }
+
+#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
+#ifndef __APPLE__
+ if( config_GetInt( p_this, "rt-priority" ) )
+#endif
+ {
+ int i_error, i_policy;
+ struct sched_param param;
+
+ memset( ¶m, 0, sizeof(struct sched_param) );
+ if( config_GetType( p_this, "rt-offset" ) )
+ {
+ i_priority += config_GetInt( p_this, "rt-offset" );
+ }
+ if( i_priority <= 0 )
+ {
+ param.sched_priority = (-1) * i_priority;
+ i_policy = SCHED_OTHER;
+ }
+ else
+ {
+ param.sched_priority = i_priority;
+ i_policy = SCHED_RR;
+ }
+ if( !p_this->thread_id )
+ p_this->thread_id = pthread_self();
+ if( (i_error = pthread_setschedparam( p_this->thread_id,
+ i_policy, ¶m )) )
+ {
+ msg_Warn( p_this, "couldn't set thread priority (%s:%d): %s",
+ psz_file, i_line, strerror(i_error) );
+ i_priority = 0;
+ }
+ }
+#endif
+
+ return 0;
+}
+