Download h source code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * Copyright 2021 Jeisson Hidalgo-Cespedes - Universidad de Costa Rica
 */

#ifndef QUEUE_H
#define QUEUE_H

typedef struct queue_node {
  size_t product_number;
  struct queue_node* next;
} queue_node_t;

/**
 * Thread-safe queue
 */
typedef struct queue {
  queue_node_t* head;
  queue_node_t* tail;
  pthread_mutex_t mutex;
} queue_t;

int queue_init(queue_t* queue);

int queue_destroy(queue_t* queue);

bool queue_is_empty(queue_t* queue);

int queue_append(queue_t* queue, size_t data);

/**
 * @remarks Queue must be not empty, otherwise it will crash
 */
size_t queue_dequeue(queue_t* queue);

int queue_free(queue_t* queue);

#endif  // QUEUE_H