summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_disk.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2004-08-19 19:51:51 +0000
committerphk <phk@FreeBSD.org>2004-08-19 19:51:51 +0000
commit59d327838d010e655f4d83f7b6c5feedddbf9974 (patch)
treefd0cb614d638ff6fa714c3b48816580a8cca71ae /sys/kern/subr_disk.c
parent5681dff740eef38ded6f24d9dce49a1c30299df3 (diff)
downloadFreeBSD-src-59d327838d010e655f4d83f7b6c5feedddbf9974.zip
FreeBSD-src-59d327838d010e655f4d83f7b6c5feedddbf9974.tar.gz
Add bioq_takefirst().
If the bioq is empty, NULL is returned. Otherwise the front element is removed and returned. This can simplify locking in many drivers from: lock() bp = bioq_first(bq); if (bp == NULL) { unlock() return } bioq_remove(bp, bq) unlock to: lock() bp = bioq_takefirst(bq); unlock() if (bp == NULL) return;
Diffstat (limited to 'sys/kern/subr_disk.c')
-rw-r--r--sys/kern/subr_disk.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c
index 9756ca6..fcd0c9d 100644
--- a/sys/kern/subr_disk.c
+++ b/sys/kern/subr_disk.c
@@ -94,13 +94,8 @@ bioq_flush(struct bio_queue_head *head, struct devstat *stp, int error)
{
struct bio *bp;
- for (;;) {
- bp = bioq_first(head);
- if (bp == NULL)
- break;
- bioq_remove(head, bp);
+ while ((bp = bioq_takefirst(head)) != NULL)
biofinish(bp, stp, error);
- }
}
void
@@ -117,6 +112,16 @@ bioq_first(struct bio_queue_head *head)
return (TAILQ_FIRST(&head->queue));
}
+struct bio *
+bioq_takefirst(struct bio_queue_head *head)
+{
+ struct bio *bp;
+
+ bp = TAILQ_FIRST(&head->queue);
+ if (bp != NULL)
+ bioq_remove(head, bp);
+ return (bp);
+}
/*
* Seek sort for disks.
OpenPOWER on IntegriCloud