6 Queue *queue = malloc(sizeof(Queue));
7 queue->list = list_create(NULL);
8 pthread_mutex_init(&queue->mtx, NULL);
12 void queue_delete(Queue *queue)
14 pthread_mutex_destroy(&queue->mtx);
15 list_clear(&queue->list);
19 void queue_enqueue(Queue *queue, void *elem)
21 pthread_mutex_lock(&queue->mtx);
22 list_put(&queue->list, elem, NULL);
23 pthread_mutex_unlock(&queue->mtx);
26 void *dequeue(Queue *queue)
28 return queue_dequeue_callback(queue, NULL);
31 void *queue_dequeue_callback(Queue *queue, void (*callback)(void *elem))
33 pthread_mutex_lock(&queue->mtx);
35 ListPair **lptr = &queue->list.first;
38 ListPair *next = (*lptr)->next;
45 pthread_mutex_unlock(&queue->mtx);