arm: protect state after signal handler
[minix.git] / lib / libsys / sched_start.c
blobce012267038664f9fe89aa7838a88a4cc99a682e
1 #include "syslib.h"
2 #include <assert.h>
3 #include <machine/archtypes.h>
4 #include <timers.h>
6 #include "kernel/config.h"
7 #include "kernel/const.h"
8 #include "kernel/type.h"
9 #include "kernel/proc.h"
11 /*===========================================================================*
12 * sched_inherit *
13 *===========================================================================*/
14 int sched_inherit(endpoint_t scheduler_e,
15 endpoint_t schedulee_e, endpoint_t parent_e, unsigned maxprio,
16 endpoint_t *newscheduler_e)
18 int rv;
19 message m;
21 assert(_ENDPOINT_P(scheduler_e) >= 0);
22 assert(_ENDPOINT_P(schedulee_e) >= 0);
23 assert(_ENDPOINT_P(parent_e) >= 0);
24 assert(maxprio < NR_SCHED_QUEUES);
25 assert(newscheduler_e);
27 m.SCHEDULING_ENDPOINT = schedulee_e;
28 m.SCHEDULING_PARENT = parent_e;
29 m.SCHEDULING_MAXPRIO = (int) maxprio;
31 /* Send the request to the scheduler */
32 if ((rv = _taskcall(scheduler_e, SCHEDULING_INHERIT, &m))) {
33 return rv;
36 /* Store the process' scheduler. Note that this might not be the
37 * scheduler we sent the SCHEDULING_INHERIT message to. That scheduler
38 * might have forwarded the scheduling message on to another scheduler
39 * before returning the message.
41 *newscheduler_e = m.SCHEDULING_SCHEDULER;
42 return (OK);
45 /*===========================================================================*
46 * sched_start *
47 *===========================================================================*/
48 int sched_start(endpoint_t scheduler_e,
49 endpoint_t schedulee_e,
50 endpoint_t parent_e,
51 int maxprio,
52 int quantum,
53 int cpu,
54 endpoint_t *newscheduler_e)
56 int rv;
57 message m;
59 /* No scheduler given? We are done. */
60 if(scheduler_e == NONE) {
61 return OK;
64 assert(_ENDPOINT_P(schedulee_e) >= 0);
65 assert(_ENDPOINT_P(parent_e) >= 0);
66 assert(maxprio >= 0);
67 assert(maxprio < NR_SCHED_QUEUES);
68 assert(quantum > 0);
69 assert(newscheduler_e);
71 /* The KERNEL must schedule this process. */
72 if(scheduler_e == KERNEL) {
73 if ((rv = sys_schedctl(SCHEDCTL_FLAG_KERNEL,
74 schedulee_e, maxprio, quantum, cpu)) != OK) {
75 return rv;
77 *newscheduler_e = scheduler_e;
78 return OK;
81 /* A user-space scheduler must schedule this process. */
82 m.SCHEDULING_ENDPOINT = schedulee_e;
83 m.SCHEDULING_PARENT = parent_e;
84 m.SCHEDULING_MAXPRIO = (int) maxprio;
85 m.SCHEDULING_QUANTUM = (int) quantum;
87 /* Send the request to the scheduler */
88 if ((rv = _taskcall(scheduler_e, SCHEDULING_START, &m))) {
89 return rv;
92 /* Store the process' scheduler. Note that this might not be the
93 * scheduler we sent the SCHEDULING_START message to. That scheduler
94 * might have forwarded the scheduling message on to another scheduler
95 * before returning the message.
97 *newscheduler_e = m.SCHEDULING_SCHEDULER;
98 return (OK);