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;
This commit is contained in:
Poul-Henning Kamp 2004-08-19 19:51:51 +00:00
parent 0ce70eb477
commit d298f91974
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=134038
2 changed files with 13 additions and 6 deletions

View File

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

View File

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