forked from AntonKozlov/os226-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsched.h
33 lines (25 loc) · 1.18 KB
/
sched.h
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
#pragma once
enum policy {
// first-in, first-out; run tasks in order of their arrival
POLICY_FIFO,
// highest priority task (highest priority value) should be executed
// first. Use round-robin for processes with same priority
// (task from 1st process, from 2nd, ... Nth, 1st, 2nd, ...)
POLICY_PRIO,
// consider deadline, execute process with Earliest Deadline First.
// Fallback to priority policy if deadlines are equal
POLICY_DEADLINE,
};
// Add new task
extern void sched_new(void (*entrypoint)(void *ctx), // entrypoint function
void *ctx, // context of the process
int priority, // priority, [0 - 10], bigger for more priority
int deadline); // absolute time till the task should be completed, <=0 for no deadline
// Continue process from function after some amount of time
extern void sched_cont(void (*entrypoint)(void *aspace), // entrypoint function
void *aspace,// addresses the process can access
int timeout); // when the continuation became runnable
// Notify scheduler that some amount of time passed
extern void sched_time_elapsed(unsigned amount);
// Scheduler loop, start executing tasks until all of them finish
extern void sched_run(enum policy policy);