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

Ingo Molnar
2005-12-13T10:13:45Z

* David Howells <dhowells@redhat.com> wrote:

> Nick Piggin <nickpiggin@yahoo.com.au> wrote:
>
> > We have atomic_cmpxchg. Can you use that for a sufficient generic
> > implementation?
>
> No. CMPXCHG/CAS is not as available as XCHG, and it's also unnecessary.

take a look at the PREEMPT_RT implementation of mutexes: it uses
cmpxchg(), and thus both the down() and the up() fastpath is lockless!
(And that is a mutex type that does alot more things, as it supports
priority inheritance.)

architectures which dont have cmpxchg can use a spinlock just fine.

Ingo