Re: [PATCH -rt 7/9] introduce PICK_FUNCTION

2007-07-30 Thread Daniel Walker
On Mon, 2007-07-30 at 11:39 +0200, Peter Zijlstra wrote:
> On Sun, 2007-07-29 at 19:45 -0700, Daniel Walker wrote:
> 
> > +#undef TYPE_EQUAL
> > +#define TYPE_EQUAL(var, type) \
> > +   __builtin_types_compatible_p(typeof(var), type *)
> > +
> 
> If you're going to touch this code, could you perhaps change TYPE_EQUAL
> to do as it says and read like so:
> 
>   __builtin_types_compatible_p(typeof(var), type)
> 

Yeah that makes sense .. I'll add it to my tree ..

Daniel

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH -rt 7/9] introduce PICK_FUNCTION

2007-07-30 Thread Peter Zijlstra
On Sun, 2007-07-29 at 19:45 -0700, Daniel Walker wrote:

> +#undef TYPE_EQUAL
> +#define TYPE_EQUAL(var, type) \
> + __builtin_types_compatible_p(typeof(var), type *)
> +

If you're going to touch this code, could you perhaps change TYPE_EQUAL
to do as it says and read like so:

__builtin_types_compatible_p(typeof(var), type)



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH -rt 7/9] introduce PICK_FUNCTION

2007-07-30 Thread Peter Zijlstra
On Sun, 2007-07-29 at 19:45 -0700, Daniel Walker wrote:

 +#undef TYPE_EQUAL
 +#define TYPE_EQUAL(var, type) \
 + __builtin_types_compatible_p(typeof(var), type *)
 +

If you're going to touch this code, could you perhaps change TYPE_EQUAL
to do as it says and read like so:

__builtin_types_compatible_p(typeof(var), type)



-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH -rt 7/9] introduce PICK_FUNCTION

2007-07-30 Thread Daniel Walker
On Mon, 2007-07-30 at 11:39 +0200, Peter Zijlstra wrote:
 On Sun, 2007-07-29 at 19:45 -0700, Daniel Walker wrote:
 
  +#undef TYPE_EQUAL
  +#define TYPE_EQUAL(var, type) \
  +   __builtin_types_compatible_p(typeof(var), type *)
  +
 
 If you're going to touch this code, could you perhaps change TYPE_EQUAL
 to do as it says and read like so:
 
   __builtin_types_compatible_p(typeof(var), type)
 

Yeah that makes sense .. I'll add it to my tree ..

Daniel

-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH -rt 7/9] introduce PICK_FUNCTION

2007-07-29 Thread Daniel Walker
PICK_FUNCTION() is similar to the other PICK_OP style macros, and was
created to replace them all. I used variable argument macros to handle
PICK_FUNC_2ARG/PICK_FUNC_1ARG. Otherwise the marcos are similar to the
original macros used for semaphores. The entire system is used to do a
compile time switch between two different locking APIs. For example,
real spinlocks (raw_spinlock_t) and mutexes (or sleeping spinlocks).

This new macro replaces all the duplication from lock type to lock type.
The result of this patch, and the next two, is a fairly nice simplification,
and consolidation. Although the seqlock changes are larger than the originals
I think over all the patchset is worth while.

Signed-off-by: Daniel Walker <[EMAIL PROTECTED]>

---
 include/linux/pickop.h  |   32 +++
 include/linux/rt_lock.h |  129 +++-
 2 files changed, 73 insertions(+), 88 deletions(-)

Index: linux-2.6.22/include/linux/pickop.h
===
--- /dev/null
+++ linux-2.6.22/include/linux/pickop.h
@@ -0,0 +1,32 @@
+#ifndef _LINUX_PICKOP_H
+#define _LINUX_PICKOP_H
+
+#undef TYPE_EQUAL
+#define TYPE_EQUAL(var, type) \
+   __builtin_types_compatible_p(typeof(var), type *)
+
+extern int __bad_func_type(void);
+
+#define PICK_FUNCTION(type1, type2, func1, func2, arg0, ...)   \
+do {   \
+   if (TYPE_EQUAL((arg0), type1))  \
+   func1((type1 *)(arg0), ##__VA_ARGS__);  \
+   else if (TYPE_EQUAL((arg0), type2)) \
+   func2((type2 *)(arg0), ##__VA_ARGS__);  \
+   else __bad_func_type(); \
+} while (0)
+
+#define PICK_FUNCTION_RET(type1, type2, func1, func2, arg0, ...)   \
+({ \
+   unsigned long __ret;\
+   \
+   if (TYPE_EQUAL((arg0), type1))  \
+   __ret = func1((type1 *)(arg0), ##__VA_ARGS__);  \
+   else if (TYPE_EQUAL((arg0), type2)) \
+   __ret = func2((type2 *)(arg0), ##__VA_ARGS__);  \
+   else __ret = __bad_func_type(); \
+   \
+   __ret;  \
+})
+
+#endif /* _LINUX_PICKOP_H */
Index: linux-2.6.22/include/linux/rt_lock.h
===
--- linux-2.6.22.orig/include/linux/rt_lock.h
+++ linux-2.6.22/include/linux/rt_lock.h
@@ -156,76 +156,40 @@ extern void fastcall rt_up(struct semaph
 
 extern int __bad_func_type(void);
 
-#undef TYPE_EQUAL
-#define TYPE_EQUAL(var, type) \
-   __builtin_types_compatible_p(typeof(var), type *)
-
-#define PICK_FUNC_1ARG(type1, type2, func1, func2, arg)
\
-do {   \
-   if (TYPE_EQUAL((arg), type1))   \
-   func1((type1 *)(arg));  \
-   else if (TYPE_EQUAL((arg), type2))  \
-   func2((type2 *)(arg));  \
-   else __bad_func_type(); \
-} while (0)
+#include 
 
-#define PICK_FUNC_1ARG_RET(type1, type2, func1, func2, arg)\
-({ \
-   unsigned long __ret;\
-   \
-   if (TYPE_EQUAL((arg), type1))   \
-   __ret = func1((type1 *)(arg));  \
-   else if (TYPE_EQUAL((arg), type2))  \
-   __ret = func2((type2 *)(arg));  \
-   else __ret = __bad_func_type(); \
-   \
-   __ret;  \
-})
-
-#define PICK_FUNC_2ARG(type1, type2, func1, func2, arg0, arg1) \
-do {   \
-   if (TYPE_EQUAL((arg0), type1))  \
-   func1((type1 *)(arg0), arg1);   \
-   else if (TYPE_EQUAL((arg0), type2)) \
-   func2((type2 *)(arg0), arg1);   \
-   else __bad_func_type();   

[PATCH -rt 7/9] introduce PICK_FUNCTION

2007-07-29 Thread Daniel Walker
PICK_FUNCTION() is similar to the other PICK_OP style macros, and was
created to replace them all. I used variable argument macros to handle
PICK_FUNC_2ARG/PICK_FUNC_1ARG. Otherwise the marcos are similar to the
original macros used for semaphores. The entire system is used to do a
compile time switch between two different locking APIs. For example,
real spinlocks (raw_spinlock_t) and mutexes (or sleeping spinlocks).

This new macro replaces all the duplication from lock type to lock type.
The result of this patch, and the next two, is a fairly nice simplification,
and consolidation. Although the seqlock changes are larger than the originals
I think over all the patchset is worth while.

Signed-off-by: Daniel Walker [EMAIL PROTECTED]

---
 include/linux/pickop.h  |   32 +++
 include/linux/rt_lock.h |  129 +++-
 2 files changed, 73 insertions(+), 88 deletions(-)

Index: linux-2.6.22/include/linux/pickop.h
===
--- /dev/null
+++ linux-2.6.22/include/linux/pickop.h
@@ -0,0 +1,32 @@
+#ifndef _LINUX_PICKOP_H
+#define _LINUX_PICKOP_H
+
+#undef TYPE_EQUAL
+#define TYPE_EQUAL(var, type) \
+   __builtin_types_compatible_p(typeof(var), type *)
+
+extern int __bad_func_type(void);
+
+#define PICK_FUNCTION(type1, type2, func1, func2, arg0, ...)   \
+do {   \
+   if (TYPE_EQUAL((arg0), type1))  \
+   func1((type1 *)(arg0), ##__VA_ARGS__);  \
+   else if (TYPE_EQUAL((arg0), type2)) \
+   func2((type2 *)(arg0), ##__VA_ARGS__);  \
+   else __bad_func_type(); \
+} while (0)
+
+#define PICK_FUNCTION_RET(type1, type2, func1, func2, arg0, ...)   \
+({ \
+   unsigned long __ret;\
+   \
+   if (TYPE_EQUAL((arg0), type1))  \
+   __ret = func1((type1 *)(arg0), ##__VA_ARGS__);  \
+   else if (TYPE_EQUAL((arg0), type2)) \
+   __ret = func2((type2 *)(arg0), ##__VA_ARGS__);  \
+   else __ret = __bad_func_type(); \
+   \
+   __ret;  \
+})
+
+#endif /* _LINUX_PICKOP_H */
Index: linux-2.6.22/include/linux/rt_lock.h
===
--- linux-2.6.22.orig/include/linux/rt_lock.h
+++ linux-2.6.22/include/linux/rt_lock.h
@@ -156,76 +156,40 @@ extern void fastcall rt_up(struct semaph
 
 extern int __bad_func_type(void);
 
-#undef TYPE_EQUAL
-#define TYPE_EQUAL(var, type) \
-   __builtin_types_compatible_p(typeof(var), type *)
-
-#define PICK_FUNC_1ARG(type1, type2, func1, func2, arg)
\
-do {   \
-   if (TYPE_EQUAL((arg), type1))   \
-   func1((type1 *)(arg));  \
-   else if (TYPE_EQUAL((arg), type2))  \
-   func2((type2 *)(arg));  \
-   else __bad_func_type(); \
-} while (0)
+#include linux/pickop.h
 
-#define PICK_FUNC_1ARG_RET(type1, type2, func1, func2, arg)\
-({ \
-   unsigned long __ret;\
-   \
-   if (TYPE_EQUAL((arg), type1))   \
-   __ret = func1((type1 *)(arg));  \
-   else if (TYPE_EQUAL((arg), type2))  \
-   __ret = func2((type2 *)(arg));  \
-   else __ret = __bad_func_type(); \
-   \
-   __ret;  \
-})
-
-#define PICK_FUNC_2ARG(type1, type2, func1, func2, arg0, arg1) \
-do {   \
-   if (TYPE_EQUAL((arg0), type1))  \
-   func1((type1 *)(arg0), arg1);   \
-   else if (TYPE_EQUAL((arg0), type2)) \
-   func2((type2 *)(arg0), arg1);   \
-   else __bad_func_type();