Fix haggis_mq_pop function to return the EndOfArchive message while

leaving it in place for the next thread. Previously it was returning
'NULL' upon encountering this message type.
This commit is contained in:
Nathan Fisher 2023-09-18 18:28:40 -04:00
parent 7ac9d7f973
commit ba46a2e048
3 changed files with 5 additions and 4 deletions

2
mq.c
View file

@ -79,7 +79,7 @@ haggis_msg* haggis_mq_pop(haggis_mq *queue) {
queue->count--;
msg = queue->head;
if (msg->tag == EndOfArchive)
return NULL;
return msg;
if (queue->tail == queue->head) {
queue->tail = queue->head = NULL;
} else {

View file

@ -70,7 +70,7 @@ tests += create_symlink_node
tests += create_fifo_node
tests += create_dev_node
tests += create_file_node
tests += haggis_mq_push_pop
tests += mq_push_pop
total != echo $(tests) | wc -w | awk '{ print $$1 }'

View file

@ -44,7 +44,8 @@ int main() {
assert(memcmp(m3->body.f_name, "/bin/cat", 8) == 0);
free(m3);
/*m4 = haggis_mq_pop(&mq);
m4 = haggis_mq_pop(&mq);
assert(m4->tag == EndOfArchive);
assert(mq.head != NULL);*/
assert(mq.head != NULL);
free(m4);
}