Changeset 2efddef08d002f95619b37232c52c74baeb696f2

Show
Ignore:
Timestamp:
06/06/08 16:29:46 (3 months ago)
Author:
Rémi Denis-Courmont <rdenis@simphalempin.com>
git-committer:
Rémi Denis-Courmont <rdenis@simphalempin.com> 1212762586 +0300
git-parent:

[6145aa227a84a32b65beb8f27758e63f0b23b6b3]

git-author:
Rémi Denis-Courmont <rdenis@simphalempin.com> 1212762586 +0300
Message:

Set the thread priority before its creation

This should avoid priority inversion.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/misc/threads.c

    r4268368 r2efddef  
    491491 
    492492#if defined( LIBVLC_USE_PTHREAD ) 
     493    pthread_attr_t attr; 
     494    pthread_attr_init (&attr); 
     495 
    493496    sigset_t set, oldset; 
    494  
    495497    /* We really don't want signals to (literaly) interrupt our blocking I/O 
    496498     * system calls. SIGPIPE is especially bad, as it can be caused by remote 
     
    508510    pthread_sigmask (SIG_BLOCK, &set, &oldset); 
    509511 
    510     i_ret = pthread_create( &p_priv->thread_id, NULL, thread_entry, boot ); 
    511     pthread_sigmask (SIG_SETMASK, &oldset, NULL); 
    512  
    513512#ifndef __APPLE__ 
    514513    if( config_GetInt( p_this, "rt-priority" ) > 0 ) 
    515514#endif 
    516515    { 
    517         int i_error, i_policy; 
    518         struct sched_param param; 
    519  
    520         memset( &param, 0, sizeof(struct sched_param) ); 
     516        /* Hack to avoid error msg */ 
    521517        if( config_GetType( p_this, "rt-offset" ) ) 
    522518            i_priority += config_GetInt( p_this, "rt-offset" ); 
    523519        if( i_priority <= 0 ) 
    524520        { 
    525             param.sched_priority = (-1) * i_priority; 
    526             i_policy = SCHED_OTHER; 
     521            struct sched_param param = { .sched_priority = -i_priority, }; 
     522            pthread_attr_setschedpolicy (&attr, SCHED_OTHER); 
     523            pthread_attr_setschedparam (&attr, &param); 
    527524        } 
    528525        else 
    529526        { 
    530             param.sched_priority = i_priority; 
    531             i_policy = SCHED_RR; 
     527            struct sched_param param = { .sched_priority = +i_priority, }; 
     528            pthread_attr_setschedpolicy (&attr, SCHED_OTHER); 
     529            pthread_attr_setschedparam (&attr, &param); 
    532530        } 
    533         if( (i_error = pthread_setschedparam( p_priv->thread_id, 
    534                                                i_policy, &param )) ) 
    535         { 
    536             errno = i_error; 
    537             msg_Warn( p_this, "couldn't set thread priority (%s:%d): %m", 
    538                       psz_file, i_line ); 
    539             i_priority = 0; 
    540         } 
    541     } 
    542 #ifndef __APPLE__ 
    543     else 
    544         i_priority = 0; 
    545 #endif 
     531    } 
     532 
     533    i_ret = pthread_create( &p_priv->thread_id, &attr, thread_entry, boot ); 
     534    pthread_sigmask (SIG_SETMASK, &oldset, NULL); 
     535    pthread_attr_destroy (&attr); 
    546536 
    547537#elif defined( WIN32 ) || defined( UNDER_CE )