@@ -10,6 +10,8 @@ use std::convert::TryFrom;
10
10
use libc:: SCHED_NORMAL as SCHED_OTHER ;
11
11
#[ cfg( not( target_os = "android" ) ) ]
12
12
use libc:: SCHED_OTHER ;
13
+ #[ cfg( target_os = "vxworks" ) ]
14
+ use libc:: SCHED_SPORADIC ;
13
15
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
14
16
use libc:: { SCHED_BATCH , SCHED_IDLE } ;
15
17
use libc:: { SCHED_FIFO , SCHED_RR } ;
@@ -51,6 +53,8 @@ fn errno() -> libc::c_int {
51
53
* libc:: __errno_location( )
52
54
} else if #[ cfg( any( target_os = "macos" , target_os = "ios" , target_os = "freebsd" ) ) ] {
53
55
* libc:: __error( )
56
+ } else if #[ cfg( target_os = "vxworks" ) ] {
57
+ libc:: errnoGet( )
54
58
} else {
55
59
compile_error!( "Your OS is probably not supported." )
56
60
}
@@ -67,6 +71,8 @@ fn set_errno(number: libc::c_int) {
67
71
* libc:: __errno_location( ) = number;
68
72
} else if #[ cfg( any( target_os = "macos" , target_os = "ios" , target_os = "freebsd" ) ) ] {
69
73
* libc:: __error( ) = number;
74
+ } else if #[ cfg( target_os = "vxworks" ) ] {
75
+ let _ = libc:: errnoSet( number) ;
70
76
} else {
71
77
compile_error!( "Your OS is probably not supported." )
72
78
}
@@ -171,6 +177,10 @@ pub enum RealtimeThreadSchedulePolicy {
171
177
Fifo ,
172
178
/// A round-robin policy
173
179
RoundRobin ,
180
+ // Policy similar to Fifo
181
+ /// A sporadic scheduling policy specific to VxWorks.
182
+ #[ cfg( target_os = "vxworks" ) ]
183
+ Sporadic ,
174
184
/// A deadline policy. Note, due to Linux expecting a pid_t and not a pthread_t, the given
175
185
/// [ThreadId](struct.ThreadId) will be interpreted as a pid_t. This policy is NOT
176
186
/// POSIX-compatible, so we only include it for linux targets.
@@ -186,6 +196,8 @@ impl RealtimeThreadSchedulePolicy {
186
196
match self {
187
197
RealtimeThreadSchedulePolicy :: Fifo => SCHED_FIFO ,
188
198
RealtimeThreadSchedulePolicy :: RoundRobin => SCHED_RR ,
199
+ #[ cfg( target_os = "vxworks" ) ]
200
+ RealtimeThreadSchedulePolicy :: Sporadic => SCHED_SPORADIC ,
189
201
#[ cfg( all(
190
202
any( target_os = "linux" , target_os = "android" ) ,
191
203
not( target_arch = "wasm32" )
@@ -284,6 +296,10 @@ impl ThreadSchedulePolicy {
284
296
SCHED_RR => Ok ( ThreadSchedulePolicy :: Realtime (
285
297
RealtimeThreadSchedulePolicy :: RoundRobin ,
286
298
) ) ,
299
+ #[ cfg( target_os = "vxworks" ) ]
300
+ SCHED_SPORADIC => Ok ( ThreadSchedulePolicy :: Realtime (
301
+ RealtimeThreadSchedulePolicy :: Sporadic ,
302
+ ) ) ,
287
303
#[ cfg( all(
288
304
any( target_os = "linux" , target_os = "android" ) ,
289
305
not( target_arch = "wasm32" )
@@ -346,8 +362,8 @@ impl ThreadPriority {
346
362
PriorityPolicyEdgeValueType :: Maximum => NICENESS_MAX as libc:: c_int,
347
363
} )
348
364
}
349
- } else if #[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ] {
350
- // macOS/iOS allows specifying the priority using sched params.
365
+ } else if #[ cfg( any( target_os = "macos" , target_os = "ios" , target_os = "vxworks" ) ) ] {
366
+ // macOS/iOS and VxWorks allow specifying the priority using sched params.
351
367
get_edge_priority( policy)
352
368
} else {
353
369
Err ( Error :: Priority (
@@ -426,14 +442,14 @@ impl ThreadPriority {
426
442
// for the SCHED_OTHER policy.
427
443
// <https://www.usenix.org/legacy/publications/library/proceedings/bsdcon02/full_papers/gerbarg/gerbarg_html/index.html>
428
444
#[ cfg( all(
429
- any( target_os = "macos" , target_os = "ios" ) ,
445
+ any( target_os = "macos" , target_os = "ios" , target_os = "vxworks" ) ,
430
446
not( target_arch = "wasm32" )
431
447
) ) ]
432
448
ThreadSchedulePolicy :: Normal ( _) => {
433
449
Self :: to_allowed_value_for_policy ( p as i32 , policy) . map ( |v| v as u32 )
434
450
}
435
451
#[ cfg( not( all(
436
- any( target_os = "macos" , target_os = "ios" ) ,
452
+ any( target_os = "macos" , target_os = "ios" , target_os = "vxworks" ) ,
437
453
not( target_arch = "wasm32" )
438
454
) ) ) ]
439
455
ThreadSchedulePolicy :: Normal ( _) => {
@@ -571,10 +587,14 @@ pub fn set_thread_priority_and_policy(
571
587
}
572
588
_ => {
573
589
let fixed_priority = priority. to_posix ( policy) ?;
574
- // On macOS and iOS it is possible to set the priority
590
+ // On VxWorks, macOS and iOS it is possible to set the priority
575
591
// this way.
576
592
if matches ! ( policy, ThreadSchedulePolicy :: Realtime ( _) )
577
- || cfg ! ( any( target_os = "macos" , target_os = "ios" ) )
593
+ || cfg ! ( any(
594
+ target_os = "macos" ,
595
+ target_os = "ios" ,
596
+ target_os = "vxworks"
597
+ ) )
578
598
{
579
599
// If the policy is a realtime one, the priority is set via
580
600
// pthread_setschedparam.
@@ -596,6 +616,20 @@ pub fn set_thread_priority_and_policy(
596
616
e => Err ( Error :: OS ( e) ) ,
597
617
}
598
618
} else {
619
+ //VxWorks does not have set priority function
620
+ #[ cfg( target_os = "vxworks" ) ]
621
+ unsafe fn setpriority (
622
+ _which : u32 ,
623
+ _who : u32 ,
624
+ _priority : libc:: c_int ,
625
+ ) -> libc:: c_int {
626
+ set_errno ( libc:: ENOSYS ) ;
627
+ -1
628
+ }
629
+
630
+ #[ cfg( not( target_os = "vxworks" ) ) ]
631
+ use libc:: setpriority;
632
+
599
633
// Normal priority threads must be set with static priority 0.
600
634
let params = ScheduleParams { sched_priority : 0 } . into_posix ( ) ;
601
635
@@ -613,7 +647,7 @@ pub fn set_thread_priority_and_policy(
613
647
614
648
// Normal priority threads adjust relative priority through niceness.
615
649
set_errno ( 0 ) ;
616
- let ret = unsafe { libc :: setpriority ( libc:: PRIO_PROCESS , 0 , fixed_priority) } ;
650
+ let ret = unsafe { setpriority ( libc:: PRIO_PROCESS , 0 , fixed_priority) } ;
617
651
if ret != 0 {
618
652
return Err ( Error :: OS ( errno ( ) ) ) ;
619
653
}
0 commit comments