File: nice.ha

package info (click to toggle)
hare 0.24.2-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,756 kB
  • sloc: asm: 1,180; sh: 119; makefile: 116; lisp: 99
file content (27 lines) | stat: -rw-r--r-- 730 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// SPDX-License-Identifier: MPL-2.0
// (c) Hare authors <https://harelang.org>

use errors;
use rt;

// Adds the argument to the niceness of the current process. The input should be
// between -20 and 19 (inclusive); lower numbers represent a higher priority.
// Generally, you must have elevated permissions to reduce your niceness, but
// not to increase it.
export fn nice(inc: int) (void | errors::error) = {
	let prio = inc;
	if (inc > -40 && inc <= 40) {
		prio += rt::getpriority(rt::PRIO_PROCESS, 0) as int;
	};
	if (prio > 19) {
		prio = 19;
	};
	if (prio < -20) {
		prio = -20;
	};
	match (rt::setpriority(rt::PRIO_PROCESS, 0, prio)) {
	case void => void;
	case let err: rt::errno =>
		return errors::errno(err);
	};
};