aboutsummaryrefslogtreecommitdiffstats
path: root/sdk/proc/priority.c
blob: 88185673944f3eb7d3de0b05c1af51ed1097eae3 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Specify process for soft realtime scheduling treatment.
 * $Id$
 * Copyright (c) 1997 by Tycho Softworks.
 * For conditions of distribution and reuse see product license.
 */
 
#include <proc/process.h>
#include <std/time.h>

#ifndef	SYS_RESOURCE_H_MISSING
#include <sys/resource.h>
#endif

#ifndef	SETPRIORITY_F_MISSING

int	priority(int pri)
{
#ifdef	_POSIX_PRIORITY_SCHEDULING
	#define	_P	__P

	#include <sched.h>

	struct	sched_param p;
#endif
	int newpri = getpriority(PRIO_PROCESS, 0) - pri - 1;

	if(setpriority(PRIO_PROCESS, 0, newpri))
		return -1;

#ifdef	_POSIX_MEMLOCK
	#include <linux/mman.h>

	if(mlockall(MCL_CURRENT | MCL_FUTURE))
		return -1;
#endif

#ifdef	_POSIX_PRIORITY_SCHEDULING
	if(pri > 0)
	{
		p.sched_priority = sched_get_priority_min(SCHED_RR) + pri - 1;
		if(sched_setscheduler(0, SCHED_RR, &p))
			return -1;
	} 
#endif
	
	return 0;
}

#else

int	priority(int priority)
{
	return nice(- priority - 1);
}
#endif

#ifdef	_POSIX_PRIORITY_SCHEDULING
#include <sched.h>

void	yield(void)
{
	sched_yield();
}
#else

void	yield(void)
{
	sleep(0);
}
#endif