-
Notifications
You must be signed in to change notification settings - Fork 0
/
ts_queue.c
69 lines (59 loc) · 1.43 KB
/
ts_queue.c
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
#include "ts_queue.h"
void ts_queue_init(ts_queue_t *ts_queue)
{
pthread_mutex_init(&ts_queue->mutex_lock, NULL);
queue_init(&ts_queue->queue);
}
void ts_queue_destroy(ts_queue_t *ts_queue)
{
pthread_mutex_destroy(&ts_queue->mutex_lock);
queue_destroy(&ts_queue->queue);
}
void _queue_lock(ts_queue_t *ts_queue)
{
pthread_mutex_lock(&ts_queue->mutex_lock);
}
void _queue_unlock(ts_queue_t *ts_queue)
{
pthread_mutex_unlock(&ts_queue->mutex_lock);
}
void ts_queue_push(ts_queue_t *ts_queue, void *element, size_t bytes)
{
_queue_lock(ts_queue);
queue_push(&ts_queue->queue, element, bytes);
_queue_unlock(ts_queue);
}
void ts_queue_pop(ts_queue_t *ts_queue)
{
_queue_lock(ts_queue);
queue_pop(&ts_queue->queue);
_queue_unlock(ts_queue);
}
const void *ts_queue_front(ts_queue_t *ts_queue)
{
const void *elem = NULL;
_queue_lock(ts_queue);
elem = queue_front(&ts_queue->queue);
_queue_unlock(ts_queue);
return elem;
}
void ts_queue_top(ts_queue_t *ts_queue, void *element)
{
_queue_lock(ts_queue);
queue_top(&ts_queue->queue, element);
_queue_unlock(ts_queue);
}
void ts_queue_clear(ts_queue_t *ts_queue)
{
_queue_lock(ts_queue);
queue_clear(&ts_queue->queue);
_queue_unlock(ts_queue);
}
int ts_queue_size(ts_queue_t *ts_queue)
{
int size;
_queue_lock(ts_queue);
size = queue_size(&ts_queue->queue);
_queue_unlock(ts_queue);
return size;
}