hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

nice.ha (730B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use errors;
      5 use rt;
      6 
      7 // Adds the argument to the niceness of the current process. The input should be
      8 // between -20 and 19 (inclusive); lower numbers represent a higher priority.
      9 // Generally, you must have elevated permissions to reduce your niceness, but
     10 // not to increase it.
     11 export fn nice(inc: int) (void | errors::error) = {
     12 	let prio = inc;
     13 	if (inc > -40 && inc <= 40) {
     14 		prio += rt::getpriority(rt::PRIO_PROCESS, 0) as int;
     15 	};
     16 	if (prio > 19) {
     17 		prio = 19;
     18 	};
     19 	if (prio < -20) {
     20 		prio = -20;
     21 	};
     22 	match (rt::setpriority(rt::PRIO_PROCESS, 0, prio)) {
     23 	case void => void;
     24 	case let err: rt::errno =>
     25 		return errors::errno(err);
     26 	};
     27 };