Subject: Re: Rewrite of buffer queue interface
To: Chris Jepeway <jepeway@blasted-heath.com>
From: Jason R Thorpe <thorpej@wasabisystems.com>
List: tech-kern
Date: 09/04/2002 18:53:43
On Wed, Sep 04, 2002 at 09:16:27PM -0400, Chris Jepeway wrote:

 > Does MP-safety matter, here?  If so, I'm not sure the BUFQ_PEEK()
 > operation can be made MP-safe.

There isn't currently a locking protocol for it.  However, presumably
the protocol, when defined, would require you to hold the lock before
doing PEEK, GET, etc.

 > Eg, I don't think code like this
 > 
 > 	bp = BUFQ_PEEK(bstate);
 > 	if (I like bp) {
 > 		/* Dequeue bp so nobody else gets it */
 > 		(void) BUFQ_GET(bstate);
 > 
 > 		/* Do whatever I want with bp */
 > 	}
 > 
 > works in the MP case.  I think you're stuck doing
 > 
 > 	bp = BUFQ_GET(bstate);
 > 	if (I don't like bp)
 > 		BUFQ_PUT(bstate, bp);
 > 	else {
 > 		/*
 > 		 * I know I like bp, and it's safe
 > 		 * for me to do with it as I wish
 > 		 */
 > 
 > 	}

No, you can do this:

	BUFQ_LOCK(bstate);

	bp = BUFQ_PEEK(bstate);
	if (I like bp) {
		/* Dequeue bp so nobody else gets it */
		(void) BUFQ_GET(bstate);
	} else
		bp = NULL;

	BUFQ_UNLOCK(bstate);

	if (bp != NULL) {
		/* Do whatever I want with bp. */
	}

...doing GET/PUT is bad.

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>