Ian Appru wrote:
While atomic increment/decrements (using cas) are suffiently well documented 
for me to be pretty confident in my implementation I would apreciate any input 
for an atomic conditional increment.

I'd expect the following to work on OpenSolaris:

#include <atomic.h>

int atomic_conditional_increment(int *target)
{
    for (;;) {
        int old = *target;
        if (old == 0)
            return 0;

        if (atomic_cas_uint((uint_t *) target, old, old + 1) == old)
            return old + 1;
    }
}
_______________________________________________
opensolaris-discuss mailing list
[email protected]

Reply via email to