sched done
This commit is contained in:
		
							parent
							
								
									b032ac4783
								
							
						
					
					
						commit
						fc7925be3e
					
				| 
						 | 
					@ -296,17 +296,25 @@ void pre_sjf() {
 | 
				
			||||||
			if(processes[i].in_cpu != 1) {
 | 
								if(processes[i].in_cpu != 1) {
 | 
				
			||||||
				if(time.timer == processes[i].burst_times[0]) {
 | 
									if(time.timer == processes[i].burst_times[0]) {
 | 
				
			||||||
					ready_queue.push(&processes[i]);
 | 
										ready_queue.push(&processes[i]);
 | 
				
			||||||
					if(CPU != NULL) {
 | 
										if(CPU != NULL && CPU->burst_times[CPU->current_burst_index] != 0) {
 | 
				
			||||||
						ready_queue.push(CPU);
 | 
											ready_queue.push(CPU);
 | 
				
			||||||
						CPU->in_cpu = 0;
 | 
											CPU->in_cpu = 0;
 | 
				
			||||||
						out_string += " " + to_string(time.timer);
 | 
											out_string += " " + to_string(time.timer);
 | 
				
			||||||
						out_strings.push_back(out_string);
 | 
											out_strings.push_back(out_string);
 | 
				
			||||||
 | 
											CPU = NULL;
 | 
				
			||||||
						// output_file << " " << time.timer << endl;
 | 
											// output_file << " " << time.timer << endl;
 | 
				
			||||||
						CPU = ready_queue.top();
 | 
											// CPU = ready_queue.top();
 | 
				
			||||||
						CPU->in_cpu = 1;
 | 
											// CPU->in_cpu = 1;
 | 
				
			||||||
						out_string = "P" + to_string(CPU->pid+1) + "," + to_string((CPU->current_burst_index + 1 ) / 2) + " " + to_string(time.timer);
 | 
											// out_string = "P" + to_string(CPU->pid+1) + "," + to_string((CPU->current_burst_index + 1 ) / 2) + " " + to_string(time.timer);
 | 
				
			||||||
						// output_file << "P" << CPU->pid+1 << "," << (CPU->current_burst_index + 1) / 2 << " " << time.timer; // New entry time
 | 
											// // output_file << "P" << CPU->pid+1 << "," << (CPU->current_burst_index + 1) / 2 << " " << time.timer; // New entry time
 | 
				
			||||||
						ready_queue.pop();
 | 
											// ready_queue.pop();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										else if(CPU != NULL && CPU->burst_times[CPU->current_burst_index] == 0) {
 | 
				
			||||||
 | 
											waiting[CPU->pid] = CPU; // because times up!!
 | 
				
			||||||
 | 
											CPU->in_cpu = 0;
 | 
				
			||||||
 | 
											CPU->current_burst_index++;
 | 
				
			||||||
 | 
											CPU = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					processes[i].current_burst_index++;
 | 
										processes[i].current_burst_index++;
 | 
				
			||||||
| 
						 | 
					@ -319,19 +327,19 @@ void pre_sjf() {
 | 
				
			||||||
			if(waiting[j] != NULL) {
 | 
								if(waiting[j] != NULL) {
 | 
				
			||||||
				if(waiting[j]->burst_times[waiting[j]->current_burst_index] == 0) {
 | 
									if(waiting[j]->burst_times[waiting[j]->current_burst_index] == 0) {
 | 
				
			||||||
					ready_queue.push(waiting[j]);
 | 
										ready_queue.push(waiting[j]);
 | 
				
			||||||
					if(CPU != NULL) {
 | 
										// if(CPU != NULL && CPU->burst_times[processes[j].current_burst_index] != 0) {
 | 
				
			||||||
						ready_queue.push(CPU);
 | 
										// 	ready_queue.push(CPU);
 | 
				
			||||||
						CPU->in_cpu = 0;
 | 
										// 	CPU->in_cpu = 0;
 | 
				
			||||||
						out_string += " " + to_string(time.timer);
 | 
										// 	out_string += " " + to_string(time.timer);
 | 
				
			||||||
						out_strings.push_back(out_string);
 | 
										// 	out_strings.push_back(out_string);
 | 
				
			||||||
						// output_file << " " << time.timer << endl;
 | 
										// 	// output_file << " " << time.timer << endl;
 | 
				
			||||||
						CPU = ready_queue.top();
 | 
										// 	CPU = ready_queue.top();
 | 
				
			||||||
						CPU->in_cpu = 1;
 | 
										// 	CPU->in_cpu = 1;
 | 
				
			||||||
						out_string = "P" + to_string(CPU->pid+1) + "," + to_string((CPU->current_burst_index + 1 ) / 2) + " " + to_string(time.timer);
 | 
										// 	out_string = "P" + to_string(CPU->pid+1) + "," + to_string((CPU->current_burst_index + 1 ) / 2) + " " + to_string(time.timer);
 | 
				
			||||||
						// output_file << "P" << CPU->pid+1 << "," << (CPU->current_burst_index + 1) / 2 << " " << time.timer; // New entry time
 | 
										// 	// output_file << "P" << CPU->pid+1 << "," << (CPU->current_burst_index + 1) / 2 << " " << time.timer; // New entry time
 | 
				
			||||||
						ready_queue.pop();
 | 
										// 	ready_queue.pop();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					}
 | 
										// }
 | 
				
			||||||
					waiting[j]->current_burst_index++;
 | 
										waiting[j]->current_burst_index++;
 | 
				
			||||||
					waiting[j] = NULL;  // Process leaves waiting queue
 | 
										waiting[j] = NULL;  // Process leaves waiting queue
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					@ -516,7 +524,7 @@ int main(int argc, char **argv) {
 | 
				
			||||||
	char *scheduler_algorithm = argv[2];
 | 
						char *scheduler_algorithm = argv[2];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ifstream file(file_to_search_in, ios::binary);
 | 
					    ifstream file(file_to_search_in, ios::binary);
 | 
				
			||||||
    // ifstream file("../WorkloadFiles/process1.dat", ios::binary);
 | 
					    // ifstream file("../WorkloadFiles/process2.dat", ios::binary);
 | 
				
			||||||
    string buffer;
 | 
					    string buffer;
 | 
				
			||||||
    int pid = 0;
 | 
					    int pid = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -544,7 +552,7 @@ int main(int argc, char **argv) {
 | 
				
			||||||
	temp["rr"] = 4;
 | 
						temp["rr"] = 4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	string temp1 = scheduler_algorithm;
 | 
						string temp1 = scheduler_algorithm;
 | 
				
			||||||
	// string temp1 = "sjf";
 | 
						// string temp1 = "pre_sjf";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Start time point
 | 
						// Start time point
 | 
				
			||||||
    auto start = std::chrono::high_resolution_clock::now();
 | 
					    auto start = std::chrono::high_resolution_clock::now();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue