Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Jan 2006 20:22:05 +1100
From:      Peter Jeremy <peterjeremy@optushome.com.au>
To:        Scott Long <scottl@freebsd.org>
Cc:        cvs-src@freebsd.org, src-committers@freebsd.org, cvs-all@freebsd.org
Subject:   Re: cvs commit: src/sys/kern kern_rwlock.c
Message-ID:  <20060130092205.GB702@turion.vk2pj.dyndns.org>
In-Reply-To: <200601292048.k0TKmPSM000635@repoman.freebsd.org>
References:  <200601292048.k0TKmPSM000635@repoman.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 2006-Jan-29 20:48:25 +0000, Scott Long wrote:
>  gcc can't
>  figure out the order of operations at line 519, and neither can I, but this
>  is my best guess.  Also correct a number of typos and syntax errors.
>  
>  Revision  Changes    Path
>  1.3       +4 -4      src/sys/kern/kern_rwlock.c

-               if (rw->rw_lock == RW_UNLOCKED ||
-                   !(rw->rw_lock & RW_LOCK_READ) && (what == RW_RLOCKED ||
-                   RW_OWNER(rw) != (uintptr_t)curthread))
is perfectly well defined in C.  Simplifying names/macros/casts:
	if (a == b || !(a & c) && (d == e || f != g))
(partial) precedence rules from operator(7):
           () [] -> .                           left to right
           ! ~ ++ -- - (type) * & sizeof        right to left
           == !=                                left to right
           &                                    left to right
           &&                                   left to right
           ||                                   left to right
parenthesising to avoid the bottom 4 precedence rules:
        if ((a == b) || (!(a & c) && ((d == e) || (f != g))))
Note that this is different to your patch:
+               if ((rw->rw_lock == RW_UNLOCKED ||
+                   !(rw->rw_lock & RW_LOCK_READ)) && (what == RA_RLOCKED ||
+                   (rw_owner(rw) != curthread)))
which turns into:
        if ((a == b || !(a & c)) && (d == e || (f != g)))

If it's just a matter of silencing gcc, I believe that what is wanted
is (with grouping wraps and indents):
*               if (rw->rw_lock == RW_UNLOCKED ||
*                   (!(rw->rw_lock & RW_LOCK_READ) &&
*                    (what == RW_RLOCKED || rw_owner(rw) != curthread)))

Note that the behaviour in 1.2 and 1.3 is different if
(rw->rw_lock == RW_UNLOCKED)

-- 
Peter Jeremy



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