-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread.h
63 lines (43 loc) · 1.12 KB
/
thread.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
//
// Created by naamagl on 3/31/19.
//
#ifndef OS_EX2_THREAD_H
#define OS_EX2_THREAD_H
#include <string>
#define STACK_SIZE 4096
using namespace std;
typedef unsigned long address_t;
class thread {
private:
// address_t _sp, _pc;
int _tid;
string _status = "ready"; // do we do or by signaling?
int _quantums = 0;
bool _sleeping = false;
bool _needs_resume = false;
char* _stack;
public:
// remember to implement default rule of 3
thread() = default;
thread(void (*f)(void), int tid){
_tid = tid;
_stack = new char[STACK_SIZE];
}
~thread()
{
delete[] _stack;
}
int get_tid(){return _tid;}
void set_status(string status){
_status = status;
}
string get_status(){return _status;}
int get_quantums(){return _quantums;}
void inc_quantums(){++_quantums;}
char* get_stack(){return _stack;}
bool is_sleeping(){return _sleeping;}
bool needs_resume(){return _needs_resume;}
void set_sleeping(bool mode){_sleeping = mode;}
void set_needs_resume(bool mode){_needs_resume = mode;}
};
#endif //OS_EX2_THREAD_H