forked from vladandrew/dafny_sched_unikraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glue.cpp
88 lines (68 loc) · 1.87 KB
/
glue.cpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "sched.h"
_module::SchedCoop sched_coop;
#ifdef __cplusplus
extern "C" {
#endif
#include <uk/sched.h>
#include <uk/plat/lcpu.h>
#include <uk/schedcoop.h>
#include <uk/plat/memory.h>
#include <uk/plat/time.h>
void schedcoop_thread_woken(struct uk_sched *s, struct uk_thread *t)
{
}
void schedcoop_schedule(struct uk_sched *s)
{
struct uk_thread *prev, *next, *thread, *tmp;
_module::Thread *t = sched_coop.schedule().get();
next = (uk_thread *)t->uk_thread;
prev = uk_thread_current();
if (prev != next)
uk_sched_thread_switch(s, prev, next);
}
int schedcoop_thread_add(struct uk_sched *s, struct uk_thread *t,
const uk_thread_attr_t *attr __unused)
{
unsigned long flags;
flags = ukplat_lcpu_save_irqf();
_module::Thread *thread = new _module::Thread();
thread->uk_sched = (uint64)s;
thread->uk_thread = (uint64)t;
std::shared_ptr<_module::Thread> my_ptr(thread);
sched_coop.thread__add(my_ptr);
ukplat_lcpu_restore_irqf(flags);
return 0;
}
void schedcoop_thread_remove(struct uk_sched *s, struct uk_thread *t)
{
if (t == uk_thread_current()) {
schedcoop_schedule(s);
uk_pr_warn("schedule() returned! Trying again\n");
}
}
void schedcoop_yield(struct uk_sched *s)
{
schedcoop_schedule(s);
}
void idle_thread_fn(void *unused __unused)
{
struct uk_thread *current = uk_thread_current();
struct uk_sched *s = current->sched;
s->threads_started = true;
ukplat_lcpu_enable_irq();
while (1) {
uk_thread_block(current);
schedcoop_schedule(s);
}
}
void schedcoop_thread_blocked(struct uk_sched *s, struct uk_thread *t)
{
UK_ASSERT(ukplat_lcpu_irqs_disabled());
}
void init_sched_ctor()
{
sched_coop.__ctor();
}
#ifdef __cplusplus
}
#endif