-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.h
80 lines (60 loc) · 1.75 KB
/
types.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
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef _TYPES_H
#define _TYPES_H
#include <map>
#include <memory>
#include <queue>
#include <ucontext.h>
#include "thread.h"
enum ThreadState {
INITIALIZED,
RUNNING,
FINISHED,
BLOCKED,
READY,
};
class Tcb {
public:
// EFFECTS: creates an empty TCB. it contains no context or stack, and
// its initial state is INITIALIZED.
Tcb();
// EFFECTS: creates a valid TCB with an allocated context and stack
// whose state is initialized to the given state, and whose program
// counter is set to the given function with the given argument
Tcb(ThreadState, thread_startfunc_t, void *);
// use default move constructors
Tcb(Tcb&&) = default;
Tcb& operator=(Tcb&&) = default;
// disable copy constructors
Tcb(const Tcb&) = delete;
Tcb& operator=(const Tcb&) = delete;
// REQUIRES: this tcb manages a stack (as well as a context, implicitly)
// EFFECTS: frees the stack managed by this tcb
void freeStack();
// MEMBER VARIABLES //
ucontext_t ctx;
char *stackPtr;
std::shared_ptr<ThreadState> state;
std::shared_ptr<std::queue<std::unique_ptr<Tcb>>> joinQueue;
};
class RaiiLock {
public:
RaiiLock();
~RaiiLock();
};
using TcbPtr = std::unique_ptr<Tcb>;
using ThreadStatePtr = std::shared_ptr<ThreadState>;
using JoinQueuePtr = std::shared_ptr<std::queue<TcbPtr>>;
extern std::queue<TcbPtr> readyQueue;
extern std::vector<TcbPtr> finishedList;
extern std::map<cpu *, TcbPtr> runningList;
extern ucontext_t *dummyCtx;
extern ucontext_t *suspendCtx;
void os_wrapper(thread_startfunc_t, void *);
void switch_to_next_or_suspend(ucontext_t *);
void cleanup_finished_list();
void yield_helper();
void handle_timer();
void send_ipi();
void handle_ipi();
void suspend_thread();
#endif