Meditations on Writing a Queue, Part 2

Queue Pop
Now that we have data in our queue, we need a way to get data out of it. Introducing tiny_queue_pop
void *tiny_queue_pop(tiny_queue_t *queue) {
pthread_mutex_lock(&queue->mutex);
while(queue->head == NULL) { // block if buffer is empty
pthread_cond_wait(&queue->wakeup, &queue->mutex);
}

struct tiny_linked_list_t* current_head = queue->head;
void *data = current_head->data;
if(queue->head == queue->tail) {
queue->head = queue->tail = NULL;
}
else {
queue->head = queue->head->next;
}
free(current_head);
pthread_mutex_unlock(&queue->mutex);

return data;
}
This function takes a tiny_queue_t pointer as an argument and returns an untyped pointer (void *).

Link: https://dzone.com/articles/meditations-on-writing-a-queue-part-2?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev