mlq-full
user_0531932
c_cpp
a year ago
1.8 kB
3
Indexable
Never
void init_scheduler(void) { #ifdef MLQ_SCHED // printf("%s", "MLQ init used\n"); int i ; for (i = 0; i < MAX_PRIO; i ++) mlq_ready_queue[i].size = 0; #endif //printf("%s", "non MLQ used\n"); ready_queue.size = 0; run_queue.size = 0; pthread_mutex_init(&queue_lock, NULL); } #ifdef MLQ_SCHED /* * Stateful design for routine calling * based on the priority and our MLQ policy * We implement stateful here using transition technique * State representation prio = 0 .. MAX_PRIO, curr_slot = 0..(MAX_PRIO - prio) */ struct pcb_t * get_mlq_proc(void) { // printf("%s", "MLQ get proc used\n"); struct pcb_t * proc = NULL; /*TODO: get a process from PRIORITY [ready_queue]. * Remember to use lock to protect the queue. * */ pthread_mutex_lock(&queue_lock); unsigned long prio; for (prio = 0; prio < MAX_PRIO; prio++) if(!empty(&mlq_ready_queue[prio])) { // printf("%s\n", "OK still"); proc = dequeue(&mlq_ready_queue[prio]); printf("Prio of dequeued process is: %d\n", proc->prio); break; } // printf("Prio of process if: %d\n", proc->prio); pthread_mutex_unlock(&queue_lock); return proc; } void put_mlq_proc(struct pcb_t * proc) { pthread_mutex_lock(&queue_lock); enqueue(&mlq_ready_queue[proc->prio], proc); pthread_mutex_unlock(&queue_lock); } void add_mlq_proc(struct pcb_t * proc) { pthread_mutex_lock(&queue_lock); enqueue(&mlq_ready_queue[proc->prio], proc); pthread_mutex_unlock(&queue_lock); } struct pcb_t * get_proc(void) { return get_mlq_proc(); } void put_proc(struct pcb_t * proc) { return put_mlq_proc(proc); } void add_proc(struct pcb_t * proc) { return add_mlq_proc(proc); }