On Mon, Jun 21, 2010 at 10:40 AM, erik quanstrom <quanstro@quanstro.net> wrote:
void
lock(ulong *l)
{
ulong old;
ushort next, owner;
old = _xadd(l, 1);
for(;;){
next = old;
owner = old>>16;
old = *l;
if(next == owner)
break;
}
}
void
unlock(ulong *l)
{
_xadd(l, 1<<16);
}
Sure, that's reasonable in C; (i wasn't sure how to do it in asm for 8_a_, that was what I was asking about). Just also remember to provide xadd; the distribution 8a and 8l didn't support it last I checked.
Just another observation, we can bypass the load of old in the uncontended case if we reverse old = *l and the compare/break in lock.
Anyway, thoughts on this lock?
-- vs