-
Notifications
You must be signed in to change notification settings - Fork 0
/
threadq.h
67 lines (57 loc) · 1.37 KB
/
threadq.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
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
#ifndef JOS_INC_THREADQ_H
#define JOS_INC_THREADQ_H
#include "thread.h"
//#include "setjmp.h"
#include <setjmp.h>
#define THREAD_NUM_ONHALT 4
enum { name_size = 32 };
enum { stack_size = 4096 };
struct thread_context;
struct thread_queue
{
struct thread_context *tq_first;
struct thread_context *tq_last;
};
struct thread_context {
thread_id_t tc_tid;
void *tc_stack_bottom;
char tc_name[name_size];
void (*tc_entry)(uint32_t);
uint32_t tc_arg;
// struct jos_jmp_buf tc_jb;
jmp_buf tc_jb; //add
volatile uint32_t *tc_wait_addr;
volatile char tc_wakeup;
void (*tc_onhalt[THREAD_NUM_ONHALT])(thread_id_t);
int tc_nonhalt;
struct thread_context *tc_queue_link;
};
static inline void
threadq_init(struct thread_queue *tq)
{
tq->tq_first = 0;
tq->tq_last = 0;
}
static inline void
threadq_push(struct thread_queue *tq, struct thread_context *tc)
{
tc->tc_queue_link = 0;
if (!tq->tq_first) {
tq->tq_first = tc;
tq->tq_last = tc;
} else {
tq->tq_last->tc_queue_link = tc;
tq->tq_last = tc;
}
}
static inline struct thread_context *
threadq_pop(struct thread_queue *tq)
{
if (!tq->tq_first)
return 0;
struct thread_context *tc = tq->tq_first;
tq->tq_first = tc->tc_queue_link;
tc->tc_queue_link = 0;
return tc;
}
#endif