@@ -12,6 +12,8 @@ use libc::SCHED_NORMAL as SCHED_OTHER;
12
12
use libc:: SCHED_OTHER ;
13
13
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
14
14
use libc:: { SCHED_BATCH , SCHED_IDLE } ;
15
+ #[ cfg( target_os = "vxworks" ) ]
16
+ use libc:: SCHED_SPORADIC ;
15
17
use libc:: { SCHED_FIFO , SCHED_RR } ;
16
18
17
19
use crate :: { Error , ThreadPriority , ThreadPriorityValue } ;
@@ -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,9 @@ pub enum RealtimeThreadSchedulePolicy {
171
177
Fifo ,
172
178
/// A round-robin policy
173
179
RoundRobin ,
180
+ // Policy similar to Fifo
181
+ #[ cfg( target_os = "vxworks" ) ]
182
+ Sporadic ,
174
183
/// A deadline policy. Note, due to Linux expecting a pid_t and not a pthread_t, the given
175
184
/// [ThreadId](struct.ThreadId) will be interpreted as a pid_t. This policy is NOT
176
185
/// POSIX-compatible, so we only include it for linux targets.
@@ -186,6 +195,8 @@ impl RealtimeThreadSchedulePolicy {
186
195
match self {
187
196
RealtimeThreadSchedulePolicy :: Fifo => SCHED_FIFO ,
188
197
RealtimeThreadSchedulePolicy :: RoundRobin => SCHED_RR ,
198
+ #[ cfg( target_os = "vxworks" ) ]
199
+ RealtimeThreadSchedulePolicy :: Sporadic => SCHED_SPORADIC ,
189
200
#[ cfg( all(
190
201
any( target_os = "linux" , target_os = "android" ) ,
191
202
not( target_arch = "wasm32" )
@@ -284,6 +295,10 @@ impl ThreadSchedulePolicy {
284
295
SCHED_RR => Ok ( ThreadSchedulePolicy :: Realtime (
285
296
RealtimeThreadSchedulePolicy :: RoundRobin ,
286
297
) ) ,
298
+ #[ cfg( target_os = "vxworks" ) ]
299
+ SCHED_SPORADIC => Ok ( ThreadSchedulePolicy :: Realtime (
300
+ RealtimeThreadSchedulePolicy :: Sporadic ,
301
+ ) ) ,
287
302
#[ cfg( all(
288
303
any( target_os = "linux" , target_os = "android" ) ,
289
304
not( target_arch = "wasm32" )
@@ -346,8 +361,8 @@ impl ThreadPriority {
346
361
PriorityPolicyEdgeValueType :: Maximum => NICENESS_MAX as libc:: c_int,
347
362
} )
348
363
}
349
- } else if #[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ] {
350
- // macOS/iOS allows specifying the priority using sched params.
364
+ } else if #[ cfg( any( target_os = "macos" , target_os = "ios" , target_os = "vxworks" ) ) ] {
365
+ // macOS/iOS and VxWorks allow specifying the priority using sched params.
351
366
get_edge_priority( policy)
352
367
} else {
353
368
Err ( Error :: Priority (
@@ -426,7 +441,7 @@ impl ThreadPriority {
426
441
// for the SCHED_OTHER policy.
427
442
// <https://www.usenix.org/legacy/publications/library/proceedings/bsdcon02/full_papers/gerbarg/gerbarg_html/index.html>
428
443
#[ cfg( all(
429
- any( target_os = "macos" , target_os = "ios" ) ,
444
+ any( target_os = "macos" , target_os = "ios" , target_os = "vxworks" ) ,
430
445
not( target_arch = "wasm32" )
431
446
) ) ]
432
447
ThreadSchedulePolicy :: Normal ( _) => {
@@ -571,10 +586,10 @@ pub fn set_thread_priority_and_policy(
571
586
}
572
587
_ => {
573
588
let fixed_priority = priority. to_posix ( policy) ?;
574
- // On macOS and iOS it is possible to set the priority
589
+ // On VxWorks, macOS and iOS it is possible to set the priority
575
590
// this way.
576
591
if matches ! ( policy, ThreadSchedulePolicy :: Realtime ( _) )
577
- || cfg ! ( any( target_os = "macos" , target_os = "ios" ) )
592
+ || cfg ! ( any( target_os = "macos" , target_os = "ios" , target_os = "vxworks" ) )
578
593
{
579
594
// If the policy is a realtime one, the priority is set via
580
595
// pthread_setschedparam.
@@ -613,6 +628,9 @@ pub fn set_thread_priority_and_policy(
613
628
614
629
// Normal priority threads adjust relative priority through niceness.
615
630
set_errno ( 0 ) ;
631
+ // VxWorks does not have setpriority function call. Control never
632
+ // reaches this statement because of the cfg condition in if
633
+ #[ cfg( not( target_os = "vxworks" ) ) ]
616
634
let ret = unsafe { libc:: setpriority ( libc:: PRIO_PROCESS , 0 , fixed_priority) } ;
617
635
if ret != 0 {
618
636
return Err ( Error :: OS ( errno ( ) ) ) ;
0 commit comments