-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCPU.h
59 lines (50 loc) · 1.17 KB
/
CPU.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
/*
* CPU.h
*
* Created on: Aug 27, 2016
* Author: iryna
*/
#ifndef CPU_H_
#define CPU_H_
#include <queue>
#include <map>
#include <string>
#include <list>
#include <regex>
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/regex.hpp>
#include "Program.h"
enum Statement {VARIABLE, PRINT, LOCK, UNLOCK, END, UNDEFINED};
class CPU {
public:
static CPU *GetInstance() {
if(!instance)
instance = new CPU();
return instance;
}
~CPU();
void InitializePrograms( std::queue<std::string>,
unsigned variableTU,
unsigned printTU,
unsigned lockTU,
unsigned unlockTU,
unsigned endTU,
unsigned _quantum);
void Run();
private:
static CPU *instance;
CPU();
int exec(Program* program, unsigned time);
unsigned GetRequiredTime(std::string);
void executeStatement(std::string);
bool checkValueIsLess100(int);
bool LockUnlockCheck(std::queue<std::string> instructions);
std::map<Statement, unsigned> timeUnitsMap;
std::queue<Program*> readyQueue;
std::queue<Program*> blockedQueue;
std::map<char, int> variables;
unsigned quantum;
bool hasLock;
};
#endif /* CPU_H_ */