queue.c: remove queue_clear.
client code knows what objects is stored in the queue and its only 3 lines to do a simple free() on the items.
This commit is contained in:
parent
1f1e9f7764
commit
4a2665004e
4 changed files with 6 additions and 23 deletions
|
|
@ -224,6 +224,9 @@ void notify_exit() {
|
|||
rbtree_free(&tree);
|
||||
|
||||
if (event_queue) {
|
||||
notify_event *e;
|
||||
while(e = queue_dequeue(event_queue))
|
||||
notify_event_del(e);
|
||||
queue_destroy(event_queue);
|
||||
event_queue = NULL;
|
||||
}
|
||||
|
|
|
|||
22
src/queue.c
22
src/queue.c
|
|
@ -70,28 +70,10 @@ queue_t queue_init() {
|
|||
return q;
|
||||
}
|
||||
|
||||
void queue_clear(queue_t q) {
|
||||
|
||||
struct node *t, *n;
|
||||
|
||||
if (q == NULL)
|
||||
return;
|
||||
|
||||
n = q->tail.n;
|
||||
|
||||
while(n) {
|
||||
t = n->next;
|
||||
free(n);
|
||||
n = t;
|
||||
}
|
||||
|
||||
init(q);
|
||||
}
|
||||
|
||||
void queue_destroy(queue_t q) {
|
||||
|
||||
queue_clear(q);
|
||||
free(q);
|
||||
if (q)
|
||||
free(q);
|
||||
}
|
||||
|
||||
void queue_enqueue(queue_t q, void *obj) {
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@ int queue_isempty(queue_t q);
|
|||
|
||||
size_t queue_num_items(queue_t q);
|
||||
|
||||
void queue_clear(queue_t q);
|
||||
|
||||
void queue_destroy(queue_t q);
|
||||
|
||||
#endif /* __QUEUE_H */
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ int main() {
|
|||
|
||||
assert(queue_isempty(q) == 0);
|
||||
|
||||
queue_clear(q);
|
||||
while(queue_dequeue(q));
|
||||
|
||||
assert(queue_isempty(q));
|
||||
|
||||
|
|
|
|||
Reference in a new issue