lab7/code/queue.c
/* Get PCB of a process from the queue (q).
 * Return NULL if the queue is empty */
Get PCB of a process from the queue (q).
Return NULL if the queue is empty
Get PCB of a process from the queue ( q ) . Return NULL if the queue is empty
pcb_t * de_queue(pqueue_t * q) {
	assert(q != NULL);
	pcb_t *proc = NULL;
	pthread_mutex_lock(&q->lock);
	if(!empty(q)) {
		qitem_t *dltItem = q->head;
		proc = dltItem->data;
		q->head = dltItem->next;
		if(empty(q)) q->tail = NULL;
		free(dltItem); 
	}
	pthread_mutex_unlock(&q->lock);
	return proc;
}
pcb_t * de_queue ( pqueue_t * q ) { assert ( q != NULL ) ; pcb_t * proc = NULL ; pthread_mutex_lock ( & q -> lock ) ; if ( ! empty ( q ) ) { qitem_t * dltItem = q -> head ; proc = dltItem -> data ; q -> head = dltItem -> next ; if ( empty ( q ) ) q -> tail = NULL ; free ( dltItem ) ; } pthread_mutex_unlock ( & q -> lock ) ; return proc ; }
Get PCB of a process from the queue (q).
Get PCB of a process from the queue ( q ) .
// 1 Save the head pointer // 2 Change the head pointer to the next node // 3 Deallocate storage space of node // 4 Return item