#include #include #include #include #include #include #include #include #include #include #include #include using namespace std;void service();void invoke_disk();const int MAX_DEVICE = 12;const int MAX_CONTROLLER = 6;const int MAX_CHANNEL = 3;struct DCT { string device_type; int device_id; int device_status; int COCT_id; };struct SDT { int device_id; string device_type; struct DCT DCT; }SDT[MAX_DEVICE];struct COCT { int controller_id; int controller_status; int CHCT_id; }COCT[MAX_CONTROLLER];struct CHCT { int channel_id; int channel_status; int COCT_id[MAX_CONTROLLER]; }CHCT[MAX_CHANNEL];struct PCB { string process_name; int origin_id; int device_id;};vector allocated_device;vector block_device;vector block_controller;vector block_channel;void init_device() { int tmp = 10000; for (int i = 0; i < MAX_DEVICE; i++) { SDT[i].device_id = tmp++ ; SDT[i].device_type = i % 2 == 0 ? “INPUT“ : “OUTPUT“; SDT[i].DCT.device_id = SDT[i].device_id; SDT[i].DCT.device_type = SDT[i].device_type; SDT[i].DCT.device_status = 0; SDT[i].DCT.COCT_id = i / 2; } }void init_controller() { int tmp = 1000; for (int i = 0; i < MAX_CONTROLLER; i++) { COCT[i].controller_id = tmp++; COCT[i].controller_status = 0; COCT[i].CHCT_id = i / 2; }}void init_channel() { int tmp = 100; for (int i = 0 j = 0; i < MAX_CHANNEL; i++) { CHCT[i].channel_id = tmp++; CHCT[i].channel_status = 0; CHCT[i].COCT_id[0] = j++; CHCT[i].COCT_id[1] = j++; }}void menu() { cout << endl << endl; cout << “\t\t┃ 1、分配设备 ┃“ << endl; cout << “\t\t┃ 2、回收设备 ┃“ << endl; cout << “\t\t┃ 3、显示当前所有设备的状态 ┃“ << endl; cout << “\t\t┃ 0、退出 ┃“ << endl;}void show_SDT() { cout << “\t\t\t系统设备表(SDT)“ << endl; cout << “\t\t\t━━━━━━━━“ << endl; cout << “\t名称\t\t“; for(int i = 0; i < MAX_DEVICE; i++) { cout << SDT[i].device_id << “\t“; } cout << endl << “\t类型\t\t“; for(int i = 0; i < MAX_DEVICE; i++) { cout << SDT[i].device_type << “\t“; } cout << endl << “\t状态\t\t“; for(int i = 0; i < MAX_DEVICE; i++) { cout << SDT[i].DCT.device_status << “\t“; } cout << endl << “━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━“ << endl;}int check_device_allocate(int device_id) { int flag = -1; for (int i = 0; i < MAX_DEVICE; i++) { if (device_id == SDT[i].device_id) { flag = i; break; } } return flag;}void allocate_device() { int device_id; int flag; struct PCB PCB; string process_name; show_SDT(); cout << “请输入进程名:“ << endl; cin >> process_name; cout << “请输入要使用的设备:(10000-10011)“ << en
共有 条评论
评论
共有 条评论