refactor(interrupts): add queued counter
Adding queued counter to help checking whether the VI
queue is full or not, and use the full buffer size.
Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: I13f2d32d3633e617c714990741966eb7070f2ba7
diff --git a/src/vcpu.c b/src/vcpu.c
index e45e3de..a084671 100644
--- a/src/vcpu.c
+++ b/src/vcpu.c
@@ -385,13 +385,22 @@
return current_idx + 1;
}
+/**
+ * If tail reaches head of the queue, and the count of queued interrupts
+ * 0, then the queue is empty.
+ */
static bool is_queue_empty(struct interrupt_queue *q)
{
- if (q->head == q->tail) {
- return true;
- }
+ return q->head == q->tail && q->queued_vint_count == 0U;
+}
- return false;
+/**
+ * If tail reaches head of the queue, and the count of queued interrupts
+ * matches the size of the buffer, then the queue is full.
+ */
+static bool is_queue_full(struct interrupt_queue *q)
+{
+ return q->head == q->tail && q->queued_vint_count == VINT_QUEUE_MAX;
}
/**
@@ -416,8 +425,7 @@
*/
new_tail = queue_increment_index(q->tail);
- /* If new_tail reaches head of the queue, then the queue is full. */
- if (new_tail == q->head) {
+ if (is_queue_full(q)) {
return false;
}
@@ -425,6 +433,9 @@
q->vint_buffer[q->tail] = vint_id;
q->tail = new_tail;
+ assert(q->queued_vint_count < VINT_QUEUE_MAX);
+ q->queued_vint_count++;
+
return true;
}
@@ -455,6 +466,9 @@
*vint_id = q->vint_buffer[q->head];
q->head = new_head;
+ assert(q->queued_vint_count > 0);
+ q->queued_vint_count--;
+
return true;
}