Add functions on fixed_queue to check empty state
diff --git a/osi/include/fixed_queue.h b/osi/include/fixed_queue.h
index a3b896c..42e72d8 100644
--- a/osi/include/fixed_queue.h
+++ b/osi/include/fixed_queue.h
@@ -35,6 +35,10 @@
// blocked on it) results in undefined behaviour.
void fixed_queue_free(fixed_queue_t *queue, fixed_queue_free_cb free_cb);
+// Returns a value indicating whether the given |queue| is empty. |queue| may
+// not be NULL.
+bool fixed_queue_is_empty(fixed_queue_t *queue);
+
// Enqueues the given |data| into the |queue|. The caller will be blocked
// if nore more space is available in the queue. Neither |queue| nor |data|
// may be NULL.
diff --git a/osi/src/fixed_queue.c b/osi/src/fixed_queue.c
index 2d64367..621a712 100644
--- a/osi/src/fixed_queue.c
+++ b/osi/src/fixed_queue.c
@@ -81,6 +81,16 @@
free(queue);
}
+bool fixed_queue_is_empty(fixed_queue_t *queue) {
+ assert(queue != NULL);
+
+ pthread_mutex_lock(&queue->lock);
+ bool is_empty = list_is_empty(queue->list);
+ pthread_mutex_unlock(&queue->lock);
+
+ return is_empty;
+}
+
void fixed_queue_enqueue(fixed_queue_t *queue, void *data) {
assert(queue != NULL);
assert(data != NULL);