@@ -50,7 +50,7 @@ impl ThreadId {
5050 any( target_os = "linux" , target_os = "android" ) ,
5151 not( target_arch = "wasm32" )
5252 ) ) ]
53- let system = Some ( get_thread_system_id ( ) ) ;
53+ let system = Some ( get_thread_system_id ( ) as libc :: id_t ) ;
5454 #[ cfg( not( all(
5555 any( target_os = "linux" , target_os = "android" ) ,
5656 not( target_arch = "wasm32" )
@@ -342,12 +342,17 @@ impl NormalThreadSchedulePolicy {
342342 /// Returns true if the schedule policy allows to control the thread
343343 /// priority only via the dynamic priority value, - niceness.
344344 pub fn is_niceness_based ( & self ) -> bool {
345- match self {
346- #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
347- NormalThreadSchedulePolicy :: Idle => true ,
348- #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
349- NormalThreadSchedulePolicy :: Batch => true ,
350- NormalThreadSchedulePolicy :: Other => false ,
345+ cfg_if:: cfg_if! {
346+ if #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ] {
347+ // On Linux all normal thread scheduling policies can't
348+ // have any other value than `0` and should be controlled
349+ // via niceness.
350+ return true ;
351+ } else {
352+ // On other platforms, there is only SCHED_OTHER which
353+ // can be controlled via pthread's priority.
354+ return false ;
355+ }
351356 }
352357 }
353358}
@@ -575,7 +580,9 @@ fn set_thread_priority_and_policy_deadline(
575580 ) )
576581 }
577582 } ;
578- let tid = native as libc:: pid_t ;
583+ let tid = native
584+ . system
585+ . ok_or ( Error :: Priority ( "Can't obtain the system thread id." ) ) ?;
579586 let sched_attr = SchedAttr {
580587 size : std:: mem:: size_of :: < SchedAttr > ( ) as u32 ,
581588 sched_policy : RealtimeThreadSchedulePolicy :: Deadline . to_posix ( ) as u32 ,
@@ -633,7 +640,7 @@ pub fn set_thread_priority_and_policy(
633640 // SCHED_DEADLINE policy requires its own syscall
634641 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
635642 ThreadSchedulePolicy :: Realtime ( RealtimeThreadSchedulePolicy :: Deadline ) => {
636- set_thread_priority_and_policy_deadline ( thread_id. pthread , priority)
643+ set_thread_priority_and_policy_deadline ( thread_id, priority)
637644 }
638645 _ => {
639646 let fixed_priority = priority. to_posix ( policy) ?;
@@ -848,9 +855,9 @@ pub trait ThreadExt {
848855 cfg_if:: cfg_if! {
849856 if #[ cfg( all( any( target_os = "linux" , target_os = "android" ) , not( target_arch = "wasm32" ) ) ) ] {
850857 if policy == ThreadSchedulePolicy :: Realtime ( RealtimeThreadSchedulePolicy :: Deadline ) {
851- set_thread_priority_and_policy( get_thread_pthread_id ( ) , ThreadPriority :: Crossplatform ( ThreadPriorityValue ( 0 ) ) , policy)
858+ set_thread_priority_and_policy( ThreadId :: get_for_current ( ) , ThreadPriority :: Crossplatform ( ThreadPriorityValue ( 0 ) ) , policy)
852859 } else {
853- set_thread_priority_and_policy( get_thread_pthread_id ( ) , priority, policy)
860+ set_thread_priority_and_policy( ThreadId :: get_for_current ( ) , priority, policy)
854861 }
855862 } else {
856863 set_thread_priority_and_policy( ThreadId :: get_for_current( ) , priority, policy)
@@ -919,7 +926,7 @@ mod tests {
919926 use std:: time:: Duration ;
920927
921928 assert ! ( set_thread_priority_and_policy(
922- 0 , // current thread
929+ ThreadId :: get_for_current ( ) ,
923930 ThreadPriority :: Deadline {
924931 runtime: Duration :: from_millis( 1 ) ,
925932 deadline: Duration :: from_millis( 10 ) ,
0 commit comments