summaryrefslogtreecommitdiff
path: root/minix/lib/libc/sys/priority.c
blob: 74c4be52bd6a386beca8c318964787c529a796fa (plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
priority.c
*/

#include <sys/cdefs.h>
#include "namespace.h"
#include <errno.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <lib.h>
#include <unistd.h>
#include <string.h>
#include <stddef.h>


int getpriority(int which, id_t who)
{
	int v;
	message m;

	memset(&m, 0, sizeof(m));
	m.m_lc_pm_priority.which = which;
	m.m_lc_pm_priority.who = who;

	/* GETPRIORITY returns negative for error.
	 * Otherwise, it returns the priority plus the minimum
	 * priority, to distiginuish from error. We have to
	 * correct for this. (The user program has to check errno
	 * to see if something really went wrong.)
	 */

	if((v = _syscall(PM_PROC_NR, PM_GETPRIORITY, &m)) < 0) {
		return v;
	}

	return v + PRIO_MIN;
}

int setpriority(int which, id_t who, int prio)
{
	message m;

	memset(&m, 0, sizeof(m));
	m.m_lc_pm_priority.which = which;
	m.m_lc_pm_priority.who = who;
	m.m_lc_pm_priority.prio = prio;

	return _syscall(PM_PROC_NR, PM_SETPRIORITY, &m);
}