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

Gleb Smirnoff <[email protected]>
Newsgroups gmane.os.freebsd.architechture
Message-ID <YXjS16MQZiKm4E/[email protected]>
On Wed, Oct 27, 2021 at 05:06:52AM +0300, Konstantin Belousov wrote:
K> > counters.
K> 
K> That said, you seems to use wrong syntax for your example.  Might be, it
K> is enough to fix that, and not change the definition?
K> 
K> void
K> something(bool clue)
K> {
K>  	if (clue) {
K>  		rw_rlock(lock);
K>  	else
K> 		rw_wlock(lock);
K> }
K> Both rw_rlock and rw_wlock are in tail context.  You cannot _return_ void.

You actually can return void to hint compiler for a tail call optimization.
It is not a wrong syntax.

Other code that is working with true void functions (e.g. with WITNESS) and
doesn't work with "do {} while" is:

void
something(bool clue)
{
	return (clue ? rw_rlock(lock) : rw_wlock(lock));
}

This is explicitly allowed in 6.5.15 of the C11 standard.

Of course all this code can be written in some other way, so constraint
of KPI not being true functions can be worked around, but I believe better
it be fixed.

-- 
Gleb Smirnoff
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.