Skip to content

Commit

Permalink
Make permissive log event queue circular
Browse files Browse the repository at this point in the history
  • Loading branch information
rinon committed Aug 18, 2023
1 parent 0cf4b5d commit 82d6718
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions libia2/include/permissive_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,24 @@ void release_queue(struct queue *q) {

void push_queue(struct queue *q, mpk_err e) {
assert(q);
assert(q->push < QUEUE_SIZE);
if (q->push == QUEUE_SIZE) {
q->push = 0;
}
// Check if the queue is full
assert(q->push + 1 != q->pop);
q->data[q->push] = e;
q->push += 1;
}

// Attempts to pop an entry from the queue and returns if it succeeded or not.
bool pop_queue(struct queue *q, mpk_err *e) {
assert(q);
assert(q->pop < QUEUE_SIZE);
assert(e);
if (q->pop == QUEUE_SIZE) {
q->pop = 0;
}
if (q->push == q->pop) {
// Queue is empty
return false;
} else {
*e = q->data[q->pop];
Expand Down

0 comments on commit 82d6718

Please sign in to comment.