Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
565 B
4
Indexable
Never
struct pcb_t * get_mlq_proc(void) {
	struct pcb_t * proc = NULL;
	/*TODO: get a process from PRIORITY [ready_queue].
	 * Remember to use lock to protect the queue.
	 */
	
	static int queue_prio = 0;
	static int slot_max = MAX_PRIO;
	static int slot_count = 0;
	pthread_mutex_lock(&queue_lock);
	proc = dequeue(&mlq_ready_queue[queue_prio]);
	

	slot_count += 1;
	if(slot_count > slot_max) {
		queue_prio = (queue_prio + 1) % MAX_PRIO;
		slot_max = MAX_PRIO - queue_prio;
		slot_count = 0;
	}
	pthread_mutex_unlock(&queue_lock);
	return proc;	
}
Leave a Comment