* src/misc/threads.c: made vlc_set_thread_priority usable on non-Darwin

OSes, and added an rt-offset configuration variable to tune the priority
  of VLC against other programs without recompiling everything.
This commit is contained in:
Christophe Massiot 2004-02-20 17:20:01 +00:00
parent decac965b3
commit c73cac4ec8
2 changed files with 22 additions and 8 deletions

View File

@ -2,7 +2,7 @@
* libvlc.h: main libvlc header
*****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: libvlc.h,v 1.133 2004/02/11 19:17:13 fenrir Exp $
* $Id: libvlc.h,v 1.134 2004/02/20 17:20:01 massiot Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
@ -523,6 +523,12 @@ static char *ppsz_align_descriptions[] = { N_("Center"),
"slow. You should only activate this if you know what you're " \
"doing.")
#define RT_OFFSET_TEXT N_("Adjust VLC priority")
#define RT_OFFSET_LONGTEXT N_( \
"This options adds an offset (positive or negative) to VLC default " \
"priorities. You can use it to tune VLC priority against other " \
"programs, or against other VLC instances.")
#define MINIMIZE_THREADS_TXT N_("Minimize number of threads")
#define MINIMIZE_THREADS_LONGTXT N_( \
"This option minimizes the number of threads needed to run VLC")
@ -850,6 +856,10 @@ vlc_module_begin();
add_bool( "rt-priority", 0, NULL, RT_PRIORITY_TEXT, RT_PRIORITY_LONGTEXT, VLC_TRUE );
#endif
#if !defined(SYS_BEOS) && defined(PTHREAD_COND_T_IN_PTHREAD_H)
add_integer( "rt-offset", 0, NULL, RT_OFFSET_TEXT, RT_OFFSET_LONGTEXT, VLC_TRUE );
#endif
#if defined(WIN32)
add_bool( "one-instance", 0, NULL, ONEINSTANCE_TEXT, ONEINSTANCE_LONGTEXT, VLC_TRUE );
add_bool( "high-priority", 1, NULL, HPRIORITY_TEXT, HPRIORITY_LONGTEXT, VLC_TRUE );

View File

@ -2,7 +2,7 @@
* threads.c : threads implementation for the VideoLAN client
*****************************************************************************
* Copyright (C) 1999-2004 VideoLAN
* $Id: threads.c,v 1.45 2004/01/06 12:02:06 zorglub Exp $
* $Id: threads.c,v 1.46 2004/02/20 17:20:01 massiot Exp $
*
* Authors: Jean-Marc Dressler <polux@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
@ -568,7 +568,9 @@ int __vlc_thread_create( vlc_object_t *p_this, char * psz_file, int i_line,
{
int i_error, i_policy;
struct sched_param param;
memset( &param, 0, sizeof(struct sched_param) );
i_priority += config_GetInt( p_this, "rt-offset" );
if ( i_priority < 0 )
{
param.sched_priority = (-1) * i_priority;
@ -645,13 +647,17 @@ int __vlc_thread_set_priority( vlc_object_t *p_this, char * psz_file,
}
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
#ifdef SYS_DARWIN
if ( i_priority )
if ( i_priority
#ifndef SYS_DARWIN
&& config_GetInt( p_this, "rt-priority" )
#endif
)
{
int i_error, i_policy;
struct sched_param param;
memset( &param, 0, sizeof(struct sched_param) );
i_priority += config_GetInt( p_this, "rt-offset" );
if ( i_priority < 0 )
{
param.sched_priority = (-1) * i_priority;
@ -662,7 +668,7 @@ int __vlc_thread_set_priority( vlc_object_t *p_this, char * psz_file,
param.sched_priority = i_priority;
i_policy = SCHED_RR;
}
if ( (i_error = pthread_setschedparam( pthread_self(),
if ( (i_error = pthread_setschedparam( p_this->thread_id,
i_policy, &param )) )
{
msg_Warn( p_this, "couldn't set thread priority (%s:%d): %s",
@ -670,8 +676,6 @@ int __vlc_thread_set_priority( vlc_object_t *p_this, char * psz_file,
i_priority = 0;
}
}
#endif
#endif
return 0;