Round-Robin

 avatar
user_0531932
c_cpp
a year ago
743 B
2
Indexable
Never
struct pcb_t * get_proc(void) {
    //printf("%s", "non MLQ get proc used\n");
    struct pcb_t * proc = NULL;
    /* TODO: get a process from [ready_queue].
     * Remember to use lock to protect the queue.
     * */
    pthread_mutex_lock(&queue_lock);
    if(!empty(&ready_queue)) {
        proc = dequeue(&ready_queue);
        enqueue(&run_queue, proc);
    }
    pthread_mutex_unlock(&queue_lock);
    return proc;
}

void put_proc(struct pcb_t * proc) {
    pthread_mutex_lock(&queue_lock);
    enqueue(&run_queue, proc);
    pthread_mutex_unlock(&queue_lock);
}

void add_proc(struct pcb_t * proc) {
    pthread_mutex_lock(&queue_lock);
    enqueue(&ready_queue, proc);
    pthread_mutex_unlock(&queue_lock);
}