Re: rwlock(9) and mutex(9) definitions

"Poul-Henning Kamp" <[email protected]>
Newsgroups gmane.os.freebsd.architechture
Message-ID <[email protected]>
--------
Gleb Smirnoff writes:

> Such wraps don't really behave as a true void. For example you
> can not tail call them:
>
> void
> smartass_lock(lock, clue)
> {
> 	if (clue)
> 		return (rw_rlock(lock));
> 	else
> 		return (rw_wlock(lock));
> }
>
> This will fail on rw_wlock, but not on rw_rlock. However, if you
> have WITNESS it will compile correctly :)

I'm not going to go full Bruce on you here, but...

In your example above, at the very least the "else" is surplus to requirements.

The "return" around rw_wlock also doesnt do nothing for its keep.

That leaves us with:

void
smartass_lock(lock, clue)
{
	if (clue)
		return (rw_rlock(lock));
	rw_wlock(lock);
}

That has pretty low aesthetic qualities, which is why I myself would
have written it as:

void
smartass_lock(lock, clue)
{
	if (clue)
		rw_rlock(lock);
	else
		rw_wlock(lock);
}

Finally "return(something_void)" is bad style in my book, because
"void" literally means there is no return value to begin with.

So all in all, I fail to see a problem that needs fixing ?

I realize that the above may be a simplified example of the real
problem you're trying to solve, but if so, it is too simplified
to carry your argument.

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
[email protected]         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.