Keith M Wesolowski wrote:
On Wed, May 16, 2007 at 03:01:52PM -0700, Bart Smaalders wrote:
<assuming your code is correct as written>
inline int atomic_conditional_increment(int * pw )
{
if (*pw)
return (atomic_inc_32(pw));
Well, atomic_inc_32_nv, yes. But it seemed that perhaps the test for
0 needed to be done atomically as well.
If someone is decrementing *pw or resetting it to zero, then
yes, that code won't work.
So use atomic_cas_32:
inline int atomic_conditional_increment(volatile int * pw )
{
int next;
while(next = *pw)
if (atomic_cas_32(pw, next, next + 1) == next)
return (next + 1);
return (0);
}
- Bart
--
Bart Smaalders Solaris Kernel Performance
[EMAIL PROTECTED] http://blogs.sun.com/barts
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code