-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueue.c
More file actions
executable file
·114 lines (96 loc) · 2.2 KB
/
Copy pathqueue.c
File metadata and controls
executable file
·114 lines (96 loc) · 2.2 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <glib.h>
#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>
#include "queue.h"
G_LOCK_DEFINE(queue_lock);
static Queue_node *new_node(void);
static Queue_node *new_node(void)
{
Queue_node *n;
n = (Queue_node *)malloc(sizeof(Queue_node));
assert (n != NULL);
return n;
}
Queue *new_empty_queue(void)
{
Queue *q;
q = (Queue *)malloc(sizeof(Queue));
assert(q != NULL);
q->head = NULL;
q->tail = NULL;
q->count = 0;
return q;
}
void *remove_first(Queue *q)
{
Queue_node *tmp;
void *result;
assert(q != NULL);
#ifdef ICC
#pragma warning (disable:1293) // icc complains about a may_alias attribute, which I think is gcc specific
#pragma warning (disable:1292)
#endif
G_LOCK(queue_lock);
/* nothing in the queue */
if (q->head == NULL)
{
assert (q->tail == NULL);
result = NULL;
}
/* one thing in the queue */
else if (q->head == q->tail)
{
q->count--;
tmp = q->head;
result = tmp->cell;
q->head = q->tail = NULL;
free(tmp);
}
/* more than on thing in the queue */
else
{
q->count--;
tmp = q->head;
result = tmp->cell;
q->head = q->head->next;
free(tmp);
}
#ifdef ICC
#pragma warning (disable:1293) // icc complains about a may_alias attribute, which I think is gcc specific
#pragma warning (disable:1292)
#endif
G_UNLOCK(queue_lock);
return (result);
}
void insert_last(Queue *q, void *cell)
{
Queue_node *node;
assert (q != NULL);
#ifdef ICC
#pragma warning (disable:1293) // icc complains about a may_alias attribute, which I think is gcc specific
#pragma warning (disable:1292)
#endif
G_LOCK(queue_lock);
node = new_node();
node->cell = cell;
node->next = NULL;
q->count++;
/* nothing in the queue */
if (q->head == NULL)
{
assert (q->tail == NULL);
q->head = q->tail = node;
}
/* at least one thing in the queue */
else
{
q->tail->next = node;
q->tail = node;
}
#ifdef ICC
#pragma warning (disable:1293) // icc complains about a may_alias attribute, which I think is gcc specific
#pragma warning (disable:1292)
#endif
G_UNLOCK(queue_lock);
}