diff options
author | phk <phk@FreeBSD.org> | 2004-08-19 19:51:51 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2004-08-19 19:51:51 +0000 |
commit | 59d327838d010e655f4d83f7b6c5feedddbf9974 (patch) | |
tree | fd0cb614d638ff6fa714c3b48816580a8cca71ae | |
parent | 5681dff740eef38ded6f24d9dce49a1c30299df3 (diff) | |
download | FreeBSD-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;
-rw-r--r-- | sys/kern/subr_disk.c | 17 | ||||
-rw-r--r-- | sys/sys/bio.h | 2 |
2 files changed, 13 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. diff --git a/sys/sys/bio.h b/sys/sys/bio.h index 33ae4e7..0f42cff 100644 --- a/sys/sys/bio.h +++ b/sys/sys/bio.h @@ -88,6 +88,7 @@ struct bio { #define BIO_WRITE 0x02 #define BIO_DELETE 0x04 #define BIO_GETATTR 0x08 +#define BIO_CMD0 0x20 /* Available for local hacks */ #define BIO_CMD1 0x40 /* Available for local hacks */ #define BIO_CMD2 0x80 /* Available for local hacks */ @@ -113,6 +114,7 @@ int biowait(struct bio *bp, const char *wchan); void bioq_disksort(struct bio_queue_head *ap, struct bio *bp); struct bio *bioq_first(struct bio_queue_head *head); +struct bio *bioq_takefirst(struct bio_queue_head *head); void bioq_flush(struct bio_queue_head *head, struct devstat *stp, int error); void bioq_init(struct bio_queue_head *head); void bioq_insert_tail(struct bio_queue_head *head, struct bio *bp); |