lab7/code/queue.c
/* Put PCB of a process to the queue. */
Put PCB of a process to the queue.
Put PCB of a process to the queue .
void en_queue(struct pqueue_t * q, struct pcb_t * proc) {
	assert(q != NULL && proc != NULL);
    qitem_t *newItem = (qitem_t*) malloc(sizeof(qitem_t));
	newItem->data = proc; 
	newItem->next = NULL;
	pthread_mutex_lock(&q->lock);
	if(!empty(q)) q->tail->next = newItem;
    q->tail = newItem;
    if(empty(q)) q->head = newItem;
	pthread_mutex_unlock(&q->lock);
}
void en_queue ( struct pqueue_t * q , struct pcb_t * proc ) { assert ( q != NULL && proc != NULL ) ; qitem_t * newItem = ( qitem_t * ) malloc ( sizeof ( qitem_t ) ) ; newItem -> data = proc ; newItem -> next = NULL ; pthread_mutex_lock ( & q -> lock ) ; if ( ! empty ( q ) ) q -> tail -> next = newItem ; q -> tail = newItem ; if ( empty ( q ) ) q -> head = newItem ; pthread_mutex_unlock ( & q -> lock ) ; }
Put PCB of a process to the queue.
Put PCB of a process to the queue .
// 1 Create the new node // 2 Link the rear node to the new node // 3 Change the rear pointer to the new node //   If the new node is the first node, update head pointer