Re: [PATCH 1/19] MUTEX: Introduce simple mutex implementation

David Howells
2005-12-16T15:25:20Z

linux@horizon.com wrote:

> > Can be turned into:
> >
> > 1,C,A x = LL()
> > 1,C,A x |= 2;
> > 1,C,A SC(3) [success]
> > 3,C,A ...
>
> ... which can be turned back into
>
> 1,C,A x = load()
> 1,C,A x' = x | 2;
> 1,C,A cmpxchg(x,x') [success]
> 3,C,A ...

Which would be totally pointless.

If you have LL/SC, then the odds are you _don't_ have CMPXCHG, and that
CMPXCHG is implemented using LL/SC, so what you end up with is:

1,C,A x = load()
1,C,A x' = x | 2;
1,C,A y = LL()
1,C,A if (y == x)
1,X,A SC(x');
3,C,A ...

David