Skip to content

Commit 8e21a63

Browse files
committed
Emptying of queue when quitting
1 parent 21f8b96 commit 8e21a63

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

include/queue.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stdatomic.h>
55
#include <stdbool.h>
66
#include <stddef.h>
7+
#include <stdlib.h>
78

89
#include "data.h"
910

@@ -24,4 +25,6 @@ bool spsc_dequeue(spsc_queue_t *q, data_t **item);
2425

2526
bool spsc_is_empty(spsc_queue_t *q);
2627

28+
void empty_queue(spsc_queue_t *q);
29+
2730
#endif //SPSC_QUEUE_LIBRARY_H

src/query.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void *execute_step(void *args)
107107
if (spsc_dequeue(left_queue, &left_input)) break;
108108
if (atomic_load(&left_step->quit) && spsc_is_empty(left_queue)) {
109109
atomic_store(&step->quit, true);
110+
empty_queue(left_queue);
110111
break;
111112
}
112113
}
@@ -116,6 +117,7 @@ void *execute_step(void *args)
116117
if (spsc_dequeue(right_queue, &right_input)) break;
117118
if (atomic_load(&right_step->quit) && spsc_is_empty(right_queue)) {
118119
atomic_store(&step->quit, true);
120+
empty_queue(right_queue);
119121
break;
120122
}
121123
}
@@ -162,24 +164,20 @@ void *execute_step(void *args)
162164
skip:
163165
if (left_step) {
164166
if (op->left->type != WINDOW && left_input) {
165-
assert(left_input);
166167
free(left_input->data);
167168
left_input->data = NULL;
168-
free(left_input);
169-
left_input = NULL;
170-
} else {
169+
}
170+
if (left_input) {
171171
free(left_input);
172172
left_input = NULL;
173173
}
174174
}
175175
if (right_step) {
176176
if (op->right->type != WINDOW && right_input) {
177-
assert(right_input);
178177
free(right_input->data);
179178
right_input->data = NULL;
180-
free(right_input);
181-
right_input = NULL;
182-
} else {
179+
}
180+
if (right_input) {
183181
free(right_input);
184182
right_input = NULL;
185183
}

src/queue.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,13 @@ bool spsc_is_empty(spsc_queue_t *q)
6666
return head == tail;
6767
}
6868

69+
70+
void empty_queue(spsc_queue_t *q)
71+
{
72+
data_t *output;
73+
while (!spsc_is_empty(q)) {
74+
spsc_dequeue(q, &output);
75+
free(output->data);
76+
free(output);
77+
}
78+
}

0 commit comments

Comments
 (0)