-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread.c
47 lines (37 loc) · 819 Bytes
/
thread.c
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
#include <cpufunc.h>
#include <thread.h>
int nthreads;
unsigned char thread_stack[MAXTHREADS][STACKSIZE];
struct thread threads[MAXTHREADS];
struct thread *
thread_create(int(*func)(void *))
{
int current = nthreads;
if (nthreads >= MAXTHREADS) {
kprintf("Maximum number of threads reached\n");
return NULL;
}
threads[current].tid = current;
threads[current].stack = thread_stack[current] + STACKSIZE - 1;
threads[current].func = func;
nthreads++;
kprintf("[svc] Created thread %d\n", current);
return &threads[current];
}
void
thread_destroy(struct thread *t)
{
}
void
run_threads(void)
{
int current;
if (nthreads == 0)
return;
for (;;) {
for (current = 0; current < nthreads; current++) {
/* Run thread function */
_gouser(threads[current].func, threads[current].stack);
}
}
}