-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbounded_queue.h
More file actions
70 lines (54 loc) · 1.47 KB
/
bounded_queue.h
File metadata and controls
70 lines (54 loc) · 1.47 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include <stddef.h>
typedef struct bounded_queue bounded_queue_t;
/*
* Initialize a bounded queue with fixed capacity.
*
* Returns:
* 0 on success
* -1 on failure (e.g., invalid capacity, allocation failure)
*/
int bq_init(bounded_queue_t *q, size_t capacity);
/*
* Destroy the queue and free internal resources.
*
* Undefined behavior if called while other threads
* are blocked in enqueue or dequeue.
*/
void bq_destroy(bounded_queue_t *q);
/*
* Enqueue an item into the queue.
* Undefined behavior if called while other threads
* are blocked in enqueue or dequeue.
* Blocks if the queue is full.
* The caller must ensure all producer and consumer threads
* have terminated or stopped using the queue before destruction.
*
* Returns:
* 0 on success
* -1 on failure (future extension)
*/
int bq_enqueue(bounded_queue_t *q, void *item);
/*
* Dequeue an item from the queue.
*
* Blocks if the queue is empty.
* The dequeued item is stored in *item.
*
* Returns:
* 0 on success
* -1 on failure (future extension)
*/
int bq_dequeue(bounded_queue_t *q, void **item);
/*
* Return the current number of items in the queue.
* Intended for debugging and testing.
*/
size_t bq_size(bounded_queue_t *q);
/*
* Return the fixed capacity of the queue.
* The returned value may be immediately outdated if called concurrently.
*/
size_t bq_capacity(bounded_queue_t *q);
//int bq_close(bounded_queue *q);
bounded_queue_t* bq_create(size_t capacity);