diff --git a/core/queue.c b/core/queue.c index cdbd6d51..c5466e0c 100644 --- a/core/queue.c +++ b/core/queue.c @@ -192,17 +192,24 @@ void queue_remove(struct queue *queue, unsigned int index) __queue_remove(queue, &it); } -void queue_remove_all(struct queue *queue, struct track *track) +unsigned int queue_remove_all(struct queue *queue, struct track *track) { + unsigned int count = 0; struct queue_iter it; - while (queue_at(queue, 0) == track) + while (queue_at(queue, 0) == track) { queue_remove(queue, 0); + count++; + } queue_for_each(queue, &it) { - if (queue_iter_val(&it) == track) + if (queue_iter_val(&it) == track) { __queue_remove(queue, &it); + count++; + } } + + return count; } void queue_clear(struct queue *queue) diff --git a/include/core/queue.h b/include/core/queue.h index 3d8e19a1..623c931d 100644 --- a/include/core/queue.h +++ b/include/core/queue.h @@ -156,7 +156,7 @@ void queue_erase(struct queue *, unsigned int); void queue_remove(struct queue *, unsigned int); /* Called to remove all instances of the track from the queue. */ -void queue_remove_all(struct queue *, struct track *); +unsigned int queue_remove_all(struct queue *, struct track *); /* Called to remove all tracks from the queue. */ void queue_clear(struct queue *); diff --git a/tests/core/queue.c b/tests/core/queue.c index 8ad5df6a..8e76de3d 100644 --- a/tests/core/queue.c +++ b/tests/core/queue.c @@ -242,7 +242,7 @@ static void test_stress(unsigned int N) track = track_get(0); ex_length -= track->tr_length * (N / 13); ex_size -= (N / 13); - queue_remove_all(&q, track); + test_equal(queue_remove_all(&q, track), N / 13); test_equal(q.q_length, ex_length); test_equal(queue_size(&q), ex_size);