core/queue: queue_remove_all() returns count of tracks removed

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-04-16 16:36:57 -04:00 committed by Anna Schumaker
parent 378ff72307
commit afb2653f65
3 changed files with 12 additions and 5 deletions

View File

@ -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)

View File

@ -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 *);

View File

@ -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);