-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thread.cpp
64 lines (54 loc) · 1.13 KB
/
Thread.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
/*
* Thread.cpp
*
* Created on: Jun 1, 2021
* Author: OS1
*/
#include "Thread.h"
#include "PCB.h"
#include "Kernel.h"
#include <iostream.h>
Thread::Thread(StackSize stackSize, Time timeSlice){
lock
myPCB = new PCB(this, stackSize, timeSlice);
unlock
}
void Thread::start(){
myPCB->start();
}
void Thread::waitToComplete(){
myPCB->waitToComplete();
}
Thread::~Thread(){
waitToComplete();
lock
delete myPCB; //izbaciti iz globalnog niza svih pcb ?
unlock
}
ID Thread::getId(){
return myPCB->getID();
}
ID Thread::getRunningId(){
return ((PCB*)Kernel::runningPCB)->getID();
}
Thread * Thread::getThreadById(ID id){
lock
for(Kernel::allPCBs.toHead(); Kernel::allPCBs.hasCurr(); Kernel::allPCBs.toNext()){
PCB * p = Kernel::allPCBs.getPointer();
if(p->id == id){
unlock
return p->myThread;
}
}
unlock
return 0;
}
void dispatch(){
#ifndef BCC_BLOCK_IGNORE
asm cli;
//cout << "U dispatchu " << endl;
Kernel::requestedContextChange = 1; //oznacimo da jesmo trazili promenu i udjemo u timer prekidnu rutinu
timer();
asm sti;
#endif
}