1use crate::process::{Pid, Uid};
2use crate::{backend, io};
3
4/// `nice()`—Adjust the scheduling priority of the current process.
5///
6/// # References
7///  - [POSIX]
8///  - [Linux]
9///
10/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/nice.html
11/// [Linux]: https://man7.org/linux/man-pages/man2/nice.2.html
12#[inline]
13pub fn nice(inc: i32) -> io::Result<i32> {
14    backend::process::syscalls::nice(inc)
15}
16
17/// `getpriority(PRIO_USER, uid)`—Get the scheduling priority of the given
18/// user.
19///
20/// # References
21///  - [POSIX]
22///  - [Linux]
23///  - [Apple]
24///
25/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpriority.html
26/// [Linux]: https://man7.org/linux/man-pages/man2/getpriority.2.html
27/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html
28#[cfg(not(target_os = "redox"))]
29#[inline]
30#[doc(alias = "getpriority")]
31pub fn getpriority_user(uid: Uid) -> io::Result<i32> {
32    backend::process::syscalls::getpriority_user(uid)
33}
34
35/// `getpriority(PRIO_PGRP, gid)`—Get the scheduling priority of the given
36/// process group.
37///
38/// A `pgid` of `None` means the process group of the calling process.
39///
40/// # References
41///  - [POSIX]
42///  - [Linux]
43///  - [Apple]
44///
45/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpriority.html
46/// [Linux]: https://man7.org/linux/man-pages/man2/getpriority.2.html
47/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html
48#[cfg(not(target_os = "redox"))]
49#[inline]
50#[doc(alias = "getpriority")]
51pub fn getpriority_pgrp(pgid: Option<Pid>) -> io::Result<i32> {
52    backend::process::syscalls::getpriority_pgrp(pgid)
53}
54
55/// `getpriority(PRIO_PROCESS, pid)`—Get the scheduling priority of the given
56/// process.
57///
58/// A `pid` of `None` means the calling process.
59///
60/// # References
61///  - [POSIX]
62///  - [Linux]
63///  - [Apple]
64///
65/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpriority.html
66/// [Linux]: https://man7.org/linux/man-pages/man2/getpriority.2.html
67/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html
68#[cfg(not(target_os = "redox"))]
69#[inline]
70#[doc(alias = "getpriority")]
71pub fn getpriority_process(pid: Option<Pid>) -> io::Result<i32> {
72    backend::process::syscalls::getpriority_process(pid)
73}
74
75/// `setpriority(PRIO_USER, uid)`—Get the scheduling priority of the given
76/// user.
77///
78/// # References
79///  - [POSIX]
80///  - [Linux]
81///  - [Apple]
82///
83/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setpriority.html
84/// [Linux]: https://man7.org/linux/man-pages/man2/setpriority.2.html
85/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html
86#[cfg(not(target_os = "redox"))]
87#[inline]
88#[doc(alias = "setpriority")]
89pub fn setpriority_user(uid: Uid, priority: i32) -> io::Result<()> {
90    backend::process::syscalls::setpriority_user(uid, priority)
91}
92
93/// `setpriority(PRIO_PGRP, pgid)`—Get the scheduling priority of the given
94/// process group.
95///
96/// A `pgid` of `None` means the process group of the calling process.
97///
98/// # References
99///  - [POSIX]
100///  - [Linux]
101///  - [Apple]
102///
103/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setpriority.html
104/// [Linux]: https://man7.org/linux/man-pages/man2/setpriority.2.html
105/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html
106#[cfg(not(target_os = "redox"))]
107#[inline]
108#[doc(alias = "setpriority")]
109pub fn setpriority_pgrp(pgid: Option<Pid>, priority: i32) -> io::Result<()> {
110    backend::process::syscalls::setpriority_pgrp(pgid, priority)
111}
112
113/// `setpriority(PRIO_PROCESS, pid)`—Get the scheduling priority of the given
114/// process.
115///
116/// A `pid` of `None` means the calling process.
117///
118/// # References
119///  - [POSIX]
120///  - [Linux]
121///  - [Apple]
122///
123/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setpriority.html
124/// [Linux]: https://man7.org/linux/man-pages/man2/setpriority.2.html
125/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html
126#[cfg(not(target_os = "redox"))]
127#[inline]
128#[doc(alias = "setpriority")]
129pub fn setpriority_process(pid: Option<Pid>, priority: i32) -> io::Result<()> {
130    backend::process::syscalls::setpriority_process(pid, priority)
131}
132