Re: [patch 04/19] mutex subsystem, add include/asm-i386/mutex.h

From: Nick Piggin
Date: Tue Jan 03 2006 - 08:24:12 EST


Ingo Molnar wrote:
From: Arjan van de Ven <arjan@xxxxxxxxxxxxx>

add the i386 version of mutex.h, optimized in assembly.


+static inline int
+__mutex_fastpath_trylock(atomic_t *count, int (*fail_fn)(atomic_t *))
+{
+ /*
+ * We have two variants here. The cmpxchg based one is the best one
+ * because it never induce a false contention state. It is included
+ * here because architectures using the inc/dec algorithms over the
+ * xchg ones are much more likely to support cmpxchg natively.
+ *
+ * If not we fall back to the spinlock based variant - that is
+ * just as efficient (and simpler) as a 'destructive' probing of
+ * the mutex state would be.
+ */
+#ifdef __HAVE_ARCH_CMPXCHG
+ if (likely(atomic_cmpxchg(count, 1, 0)) == 1)
+ return 1;
+ return 0;
+#else
+ return fail_fn(count);
+#endif
+}

asm-i386 version I think really should just use atomic_cmpxchg unconditionally,
because otherwise an i386 compatible kernel will not use cmpxchg even when
running on 486+ (not sure how important that is these days, but still...).

--
SUSE Labs, Novell Inc.

Send instant messages to your online friends http://au.messenger.yahoo.com -
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/