Changeset 2efddef08d002f95619b37232c52c74baeb696f2
- 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
| r4268368 |
r2efddef |
|
| 491 | 491 | |
|---|
| 492 | 492 | #if defined( LIBVLC_USE_PTHREAD ) |
|---|
| | 493 | pthread_attr_t attr; |
|---|
| | 494 | pthread_attr_init (&attr); |
|---|
| | 495 | |
|---|
| 493 | 496 | sigset_t set, oldset; |
|---|
| 494 | | |
|---|
| 495 | 497 | /* We really don't want signals to (literaly) interrupt our blocking I/O |
|---|
| 496 | 498 | * system calls. SIGPIPE is especially bad, as it can be caused by remote |
|---|
| … | … | |
| 508 | 510 | pthread_sigmask (SIG_BLOCK, &set, &oldset); |
|---|
| 509 | 511 | |
|---|
| 510 | | i_ret = pthread_create( &p_priv->thread_id, NULL, thread_entry, boot ); |
|---|
| 511 | | pthread_sigmask (SIG_SETMASK, &oldset, NULL); |
|---|
| 512 | | |
|---|
| 513 | 512 | #ifndef __APPLE__ |
|---|
| 514 | 513 | if( config_GetInt( p_this, "rt-priority" ) > 0 ) |
|---|
| 515 | 514 | #endif |
|---|
| 516 | 515 | { |
|---|
| 517 | | int i_error, i_policy; |
|---|
| 518 | | struct sched_param param; |
|---|
| 519 | | |
|---|
| 520 | | memset( ¶m, 0, sizeof(struct sched_param) ); |
|---|
| | 516 | /* Hack to avoid error msg */ |
|---|
| 521 | 517 | if( config_GetType( p_this, "rt-offset" ) ) |
|---|
| 522 | 518 | i_priority += config_GetInt( p_this, "rt-offset" ); |
|---|
| 523 | 519 | if( i_priority <= 0 ) |
|---|
| 524 | 520 | { |
|---|
| 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, ¶m); |
|---|
| 527 | 524 | } |
|---|
| 528 | 525 | else |
|---|
| 529 | 526 | { |
|---|
| 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, ¶m); |
|---|
| 532 | 530 | } |
|---|
| 533 | | if( (i_error = pthread_setschedparam( p_priv->thread_id, |
|---|
| 534 | | i_policy, ¶m )) ) |
|---|
| 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); |
|---|
| 546 | 536 | |
|---|
| 547 | 537 | #elif defined( WIN32 ) || defined( UNDER_CE ) |
|---|