Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Oct 2021 21:17:27 -0700
From:      Gleb Smirnoff <glebius@freebsd.org>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        mjg@freebsd.org, jhb@freebsd.org, jeff@freebsd.org, arch@freebsd.org
Subject:   Re: rwlock(9) and mutex(9) definitions
Message-ID:  <YXjS16MQZiKm4E/r@FreeBSD.org>
In-Reply-To: <YXi0PM6babQKFulv@kib.kiev.ua>
References:  <YXiw1afVlQyEhQyc@FreeBSD.org> <YXizhiRnByvyisXe@kib.kiev.ua> <YXi0PM6babQKFulv@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?YXjS16MQZiKm4E/r>