make vfs & filesystems use failable copying
[minix3.git] / lib / libsys / sched_start.c
blob7017047b34dfe9a4bee4dda974566638aca19279
1 #include "syslib.h"
2 #include <assert.h>
3 #include <machine/archtypes.h>
4 #include <minix/timers.h>
5 #include <string.h>
7 #include "kernel/config.h"
8 #include "kernel/const.h"
9 #include "kernel/type.h"
10 #include "kernel/proc.h"
12 /*===========================================================================*
13 * sched_inherit *
14 *===========================================================================*/
15 int sched_inherit(endpoint_t scheduler_e,
16 endpoint_t schedulee_e, endpoint_t parent_e, unsigned maxprio,
17 endpoint_t *newscheduler_e)
19 int rv;
20 message m;
22 assert(_ENDPOINT_P(scheduler_e) >= 0);
23 assert(_ENDPOINT_P(schedulee_e) >= 0);
24 assert(_ENDPOINT_P(parent_e) >= 0);
25 assert(maxprio < NR_SCHED_QUEUES);
26 assert(newscheduler_e);
28 memset(&m, 0, sizeof(m));
29 m.SCHEDULING_ENDPOINT = schedulee_e;
30 m.SCHEDULING_PARENT = parent_e;
31 m.SCHEDULING_MAXPRIO = (int) maxprio;
33 /* Send the request to the scheduler */
34 if ((rv = _taskcall(scheduler_e, SCHEDULING_INHERIT, &m))) {
35 return rv;
38 /* Store the process' scheduler. Note that this might not be the
39 * scheduler we sent the SCHEDULING_INHERIT message to. That scheduler
40 * might have forwarded the scheduling message on to another scheduler
41 * before returning the message.
43 *newscheduler_e = m.SCHEDULING_SCHEDULER;
44 return (OK);
47 /*===========================================================================*
48 * sched_start *
49 *===========================================================================*/
50 int sched_start(endpoint_t scheduler_e,
51 endpoint_t schedulee_e,
52 endpoint_t parent_e,
53 int maxprio,
54 int quantum,
55 int cpu,
56 endpoint_t *newscheduler_e)
58 int rv;
59 message m;
61 /* No scheduler given? We are done. */
62 if(scheduler_e == NONE) {
63 return OK;
66 assert(_ENDPOINT_P(schedulee_e) >= 0);
67 assert(_ENDPOINT_P(parent_e) >= 0);
68 assert(maxprio >= 0);
69 assert(maxprio < NR_SCHED_QUEUES);
70 assert(quantum > 0);
71 assert(newscheduler_e);
73 /* The KERNEL must schedule this process. */
74 if(scheduler_e == KERNEL) {
75 if ((rv = sys_schedctl(SCHEDCTL_FLAG_KERNEL,
76 schedulee_e, maxprio, quantum, cpu)) != OK) {
77 return rv;
79 *newscheduler_e = scheduler_e;
80 return OK;
83 /* A user-space scheduler must schedule this process. */
84 memset(&m, 0, sizeof(m));
85 m.SCHEDULING_ENDPOINT = schedulee_e;
86 m.SCHEDULING_PARENT = parent_e;
87 m.SCHEDULING_MAXPRIO = (int) maxprio;
88 m.SCHEDULING_QUANTUM = (int) quantum;
90 /* Send the request to the scheduler */
91 if ((rv = _taskcall(scheduler_e, SCHEDULING_START, &m))) {
92 return rv;
95 /* Store the process' scheduler. Note that this might not be the
96 * scheduler we sent the SCHEDULING_START message to. That scheduler
97 * might have forwarded the scheduling message on to another scheduler
98 * before returning the message.
100 *newscheduler_e = m.SCHEDULING_SCHEDULER;
101 return (OK);