-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
77 lines (58 loc) · 1.66 KB
/
main.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
73
74
75
76
77
#include <iostream>
#include <thread>
#include <atomic>
#include <afxres.h>
#include "cacheStore.h"
#define ADD 1
#define GET 2
using namespace std;
using namespace CacheStore;
int main() {
CacheRow cacheRow;
cacheRow.init(5);
CacheRow Queue;
Queue.init(5);
while (1) {
cout << ">";
string input = "";
cin >> input;
if (input == "exit") {
break;
} else if (input == "add") {
int ref;
cin >> ref;
cin >> input;
Block block;
block.value = input;
block.ref = ref;
block.attempt = 0;
/*Queue->addBlock(block);
if (!QueueCleanThread.joinable()) {
QueueCleanThread.detach();
}
QueueCleanThread.join();*/
if (Queue.hasHadata(ref) == -1) {
//Queue.addBlock(block);
thread threadAddBlock(Queue.addBlock, Queue, block);
threadAddBlock.join();
} else {
thread threadAddBlock(cacheRow.addBlock, cacheRow, block);
thread threadRemoveBlock(Queue.removeBlock, Queue, ref);
threadAddBlock.join();
threadRemoveBlock.join();
Queue.removeBlock(ref);
}
} else if (input == "remove") {
int ref;
cin >> ref;
cacheRow.removeBlock(ref);
cacheRow.viewAll();
} else if (input == "all") {
cout << "Queue" << endl;
Queue.viewAll();
cout << "Cache" << endl;
cacheRow.viewAll();
}
}
return 0;
}