Untitled
unknown
plain_text
2 years ago
565 B
9
Indexable
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;
}Editor is loading...
Leave a Comment