Skip to content

Commit c13302d

Browse files
committed
Add rtprio (realtime priority) API for FreeBSD and DragonFly
1 parent 2aeb382 commit c13302d

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

libc-test/build.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ fn main() {
288288
cfg.header("sys/msg.h");
289289
cfg.header("sys/shm.h");
290290
cfg.header("sys/procdesc.h");
291+
cfg.header("sys/rtprio.h");
291292
}
292293

293294
if netbsd {
@@ -311,6 +312,7 @@ fn main() {
311312
cfg.header("ufs/ufs/quota.h");
312313
cfg.header("pthread_np.h");
313314
cfg.header("sys/ioctl_compat.h");
315+
cfg.header("sys/rtprio.h");
314316
}
315317

316318
if solaris {
@@ -381,9 +383,9 @@ fn main() {
381383
}
382384
}
383385
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
384-
"type_" if linux &&
386+
"type_" if (linux || freebsd || dragonfly) &&
385387
(struct_ == "input_event" || struct_ == "input_mask" ||
386-
struct_ == "ff_effect") => "type".to_string(),
388+
struct_ == "ff_effect" || struct_ == "rtprio") => "type".to_string(),
387389
s => s.to_string(),
388390
}
389391
});

src/unix/bsd/freebsdlike/dragonfly/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub type clock_t = u64;
22
pub type ino_t = u64;
3+
pub type lwpid_t = i32;
34
pub type nlink_t = u32;
45
pub type blksize_t = i64;
56
pub type clockid_t = ::c_ulong;
@@ -737,6 +738,12 @@ pub const _SC_THREAD_ROBUST_PRIO_PROTECT: ::c_int = 127;
737738
pub const WCONTINUED: ::c_int = 4;
738739
pub const WSTOPPED: ::c_int = 0o177;
739740

741+
// Values for struct rtprio (type_ field)
742+
pub const RTP_PRIO_REALTIME: ::c_ushort = 0;
743+
pub const RTP_PRIO_NORMAL: ::c_ushort = 1;
744+
pub const RTP_PRIO_IDLE: ::c_ushort = 2;
745+
pub const RTP_PRIO_THREAD: ::c_ushort = 3;
746+
740747
extern {
741748
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
742749
-> ::c_int;
@@ -750,4 +757,7 @@ extern {
750757
timeout: *mut ::timespec) -> ::c_int;
751758

752759
pub fn freelocale(loc: ::locale_t);
760+
761+
pub fn lwp_rtprio(function: ::c_int, pid: ::pid_t, lwpid: lwpid_t,
762+
rtp: *mut super::rtprio) -> ::c_int;
753763
}

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,11 @@ pub const PD_DAEMON: ::c_int = 0x00000001;
846846
pub const PD_CLOEXEC: ::c_int = 0x00000002;
847847
pub const PD_ALLOWED_AT_FORK: ::c_int = PD_DAEMON | PD_CLOEXEC;
848848

849+
// Values for struct rtprio (type_ field)
850+
pub const RTP_PRIO_REALTIME: ::c_ushort = 2;
851+
pub const RTP_PRIO_NORMAL: ::c_ushort = 3;
852+
pub const RTP_PRIO_IDLE: ::c_ushort = 4;
853+
849854
extern {
850855
pub fn __error() -> *mut ::c_int;
851856

@@ -905,6 +910,9 @@ extern {
905910
pub fn pdfork(fdp: *mut ::c_int, flags: ::c_int) -> ::pid_t;
906911
pub fn pdgetpid(fd: ::c_int, pidp: *mut ::pid_t) -> ::c_int;
907912
pub fn pdkill(fd: ::c_int, signum: ::c_int) -> ::c_int;
913+
914+
pub fn rtprio_thread(function: ::c_int, lwpid: ::lwpid_t,
915+
rtp: *mut super::rtprio) -> ::c_int;
908916
}
909917

910918
cfg_if! {

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ s! {
170170
pub cmcred_ngroups: ::c_short,
171171
pub cmcred_groups: [::gid_t; CMGROUP_MAX],
172172
}
173+
174+
pub struct rtprio {
175+
pub type_: ::c_ushort,
176+
pub prio: ::c_ushort,
177+
}
173178
}
174179

175180
pub const AIO_LISTIO_MAX: ::c_int = 16;
@@ -960,6 +965,12 @@ pub const CMGROUP_MAX: usize = 16;
960965
// sizeof(long)
961966
pub const BPF_ALIGNMENT: ::c_int = 8;
962967

968+
// Values for rtprio struct (prio field) and syscall (function argument)
969+
pub const RTP_PRIO_MIN: ::c_ushort = 0;
970+
pub const RTP_PRIO_MAX: ::c_ushort = 31;
971+
pub const RTP_LOOKUP: ::c_int = 0;
972+
pub const RTP_SET: ::c_int = 1;
973+
963974
f! {
964975
pub fn WIFCONTINUED(status: ::c_int) -> bool {
965976
status == 0x13
@@ -1135,6 +1146,7 @@ extern {
11351146
val: ::c_int) -> ::c_int;
11361147
pub fn getpriority(which: ::c_int, who: ::c_int) -> ::c_int;
11371148
pub fn setpriority(which: ::c_int, who: ::c_int, prio: ::c_int) -> ::c_int;
1149+
pub fn rtprio(function: ::c_int, pid: ::pid_t, rtp: *mut rtprio) -> ::c_int;
11381150

11391151
pub fn fdopendir(fd: ::c_int) -> *mut ::DIR;
11401152

0 commit comments

Comments
 (0)