forked from NxxxxxxW/Control-thread
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathass.h
101 lines (90 loc) · 2.37 KB
/
ass.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef ASS_H
#define ASS_H
#include <vector>
#include <string>
#include <map>
#include <iostream>
#include <pthread.h>
using namespace std;
const int kMaxMaterialsCount = 10;
const int kLimitMaterialCount = 4;
const char kToolType[] = {'x', 'y', 'z'};
const int kMaterialsType[] = {1, 2, 3};
const char kProductType[] = {'A', 'B', 'C'};
const int kToolTypeCount = 3;
const int kMaterialsTypeCount = 3;
const int kProductTypeCount = 3;
const int kGeneratosCount = 3;
const int kDefaultOperatorCount = 3;
const int generator_sleep_time = 1000 * 500;
const int operator_sleep_time = 1000 * 1000;
enum MATERIAL_TYPE{
FIRST_M = 1,
SECOND_M,
THIRD_M
};
class Generator;
class Operator;
class Ass{
public:
vector<int> materials_buff;
map<int, int> current_m_count;
map<int, int> total_m_count;
map<char,bool> tools;
vector<char> product_buff;
map<char, int> product_in_making;
map<char, int> product_in_buff;
bool status;
vector<Generator*> generators;
vector<Operator*> operators;
public:
pthread_mutex_t materials_mtx;
pthread_cond_t materials_cond;
pthread_cond_t materials_create_cond;
pthread_mutex_t tools_mtx;
pthread_cond_t tools_cond;
pthread_mutex_t products_mtx;
pthread_cond_t products_cond;
pthread_mutex_t status_mtx;
pthread_cond_t status_cond;
public:
Ass();
~Ass();
void create_generators();
void create_operators(int operators_count = 3);
bool check_material_full(int type);
bool check_material_empty(int type);
bool get_material(int type);
bool generate_material(int type);
char get_producing_type();
bool producing_product(char ptype);
bool producing_product_A();
bool producing_product_B();
bool producing_product_C();
bool check_tool_need(char ptype);
bool check_material_need(char ptype);
void thread_pause();
void thread_resume();
void show_info();
void set_pause_resume_switch();
};
class Generator{
private:
pthread_t tid;
int material_type;
public:
Generator(int m_type);
bool start(Ass *pAss);
static void* generate_first_material(void* param);
static void* generate_second_material(void* param);
static void* generate_third_material(void* param);
};
class Operator{
private:
pthread_t tid;
public:
Operator();
bool start(Ass *pAss);
static void* producing_product(void* param);
};
#endif