Beispiel #1
0
/*Initialize status_queues structure Function
  Variable Definition:
  -- header: header pointer of process_info structure
  -- signal: signal that decide process priority
  Return value: status_queues structure pointer
*/
STATUS_QUEUES *initStatusQueues(PROCESS_INFO *header, const char signal){
	STATUS_QUEUES	*schedule = (STATUS_QUEUES*)malloc(sizeof(STATUS_QUEUES));	//status_queues structure
	int				count;														//counter
	
	//Sort the process by id number
	sortProcess(&header, NULL);
	//Set the process priority as start_time
	setProcessPriority(header, 'S');
	//Re-sort the process by start_time
	sortProcess(&header, NULL);
	//Set the process priority as "signal" decided
	setProcessPriority(header, signal);
	
	//Initialize the unarrival queue
	schedule->queues[0] = header;
	//Initialize the other four queues
	for (count = 1; count < QUEUES_SIZE; count++){
		//Allocate the memory for new queue front pointer
		schedule->queues[count] = (PROCESS_INFO*)malloc(sizeof(PROCESS_INFO));
		//Assign the front's next as NULL(empty queue)
		schedule->queues[count]->next = NULL;
	}

	return schedule;
}
Process deQueue(PriorityQueue* queue){
	Process deletedProcess;
	sortProcess(queue);

	deletedProcess = PROCESS[FRONT];
	FRONT = (FRONT+1) % MAX;
	return deletedProcess;
}