-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.cpp
72 lines (55 loc) · 1.97 KB
/
worker.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
65
66
67
68
69
70
71
72
#include "worker.h"
Worker::Worker(double lambda, bool isPriority) :lambda(lambda),priorityWorker(isPriority),working(false),currentPacket(Priority::LOW,0),rd(),gen(rd()),dist(lambda),index(-1)
{
}
Worker::Worker(const Worker& otherWorker) :lambda(otherWorker.lambda),priorityWorker(otherWorker.priorityWorker),working(otherWorker.working),currentPacket(otherWorker.currentPacket),rd(),gen(otherWorker.gen),dist(otherWorker.dist),index(-1) {
}
Worker::Worker(Worker&& otherWorker) : lambda(otherWorker.lambda),priorityWorker(otherWorker.priorityWorker),working(otherWorker.working),currentPacket(otherWorker.currentPacket),rd(),gen(otherWorker.gen),dist(otherWorker.dist),index(-1) {
}
//Worker& Worker::operator= (Worker otherWorker) {
// priorityWorker = otherWorker.priorityWorker;
// working = otherWorker.working;
// currentPacket = otherWorker.currentPacket;
// gen = otherWorker.gen;
// dist = otherWorker.dist;
// index = otherWorker.index;
// return *this;
//}
//Worker& Worker::operator= (Worker&& otherWorker) {
// priorityWorker = otherWorker.priorityWorker;
// working = otherWorker.working;
// currentPacket = otherWorker.currentPacket;
// gen = otherWorker.gen;
// dist = otherWorker.dist;
// index = otherWorker.index;
// return *this;
//}
bool Worker::isWorking() {
return working;
}
Packet Worker::abortPacket(double currentTime) {
working = false;
currentPacket.abort(currentTime);
return currentPacket;
}
Packet Worker::finish(double currentTime) {
working = false;
currentPacket.finish(currentTime);
return currentPacket;
}
int Worker::getCurrentPriority() {
return currentPacket.getPriority();
}
bool Worker::isPriorityWorker() {
return priorityWorker;
}
Event Worker::workOn(Packet packet, double currentTime) {
packet.work(currentTime);
currentPacket = packet;
working = true;
Event event(EventType::PACKET_FINISHED,packet.getBeginOfState()+dist(gen),index);
return event;
}
void Worker::setIndex(size_t index) {
this->index = index;
}