ramdisk Makefile: CLEANFILES fix
[minix.git] / kernel / system / do_schedctl.c
blob498d0d04f74502e1349bd845c99fe65b848b561e
1 #include "kernel/system.h"
2 #include <minix/endpoint.h>
4 /*===========================================================================*
5 * do_schedctl *
6 *===========================================================================*/
7 int do_schedctl(struct proc * caller, message * m_ptr)
9 struct proc *p;
10 unsigned flags;
11 int priority, quantum, cpu;
12 int proc_nr;
13 int r;
15 /* check parameter validity */
16 flags = (unsigned) m_ptr->SCHEDCTL_FLAGS;
17 if (flags & ~SCHEDCTL_FLAG_KERNEL) {
18 printf("do_schedctl: flags 0x%x invalid, caller=%d\n",
19 flags, caller - proc);
20 return EINVAL;
23 if (!isokendpt(m_ptr->SCHEDCTL_ENDPOINT, &proc_nr))
24 return EINVAL;
26 p = proc_addr(proc_nr);
28 if ((flags & SCHEDCTL_FLAG_KERNEL) == SCHEDCTL_FLAG_KERNEL) {
29 /* the kernel becomes the scheduler and starts
30 * scheduling the process.
32 priority = (int) m_ptr->SCHEDCTL_PRIORITY;
33 quantum = (int) m_ptr->SCHEDCTL_QUANTUM;
34 cpu = (int) m_ptr->SCHEDCTL_CPU;
36 /* Try to schedule the process. */
37 if((r = sched_proc(p, priority, quantum, cpu) != OK))
38 return r;
39 p->p_scheduler = NULL;
40 } else {
41 /* the caller becomes the scheduler */
42 p->p_scheduler = caller;
45 return(OK);