fix: harden panic logic

main
Sean McBride 4 years ago
parent 50b4ab1b6c
commit 7384b2de1e

@ -0,0 +1,15 @@
#pragma once
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
__attribute__((noreturn)) void
panic(const char *format, ...)
{
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
exit(EXIT_FAILURE);
}

@ -4,7 +4,8 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <priority_queue.h> #include "panic.h"
#include "priority_queue.h"
/**************************** /****************************
* Private Helper Functions * * Private Helper Functions *
@ -161,13 +162,7 @@ priority_queue_enqueue(struct priority_queue *self, void *value, char *name)
int pre_length = self->first_free - 1; int pre_length = self->first_free - 1;
if (priority_queue_append(self, value) == -1) { if (priority_queue_append(self, value) == -1) panic("Priority Queue is full");
printf("Priority Queue is full");
fflush(stdout);
exit(EXIT_FAILURE);
ck_spinlock_fas_unlock(&self->lock);
return -1;
}
int post_length = self->first_free - 1; int post_length = self->first_free - 1;

Loading…
Cancel
Save