[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20080118051807.GB2559@hacking>
Date: Fri, 18 Jan 2008 13:18:07 +0800
From: WANG Cong <xiyou.wangcong@...il.com>
To: Rusty Russell <rusty@...tcorp.com.au>
Cc: linux-kernel@...r.kernel.org,
Linus Torvalds <torvalds@...ux-foundation.org>,
Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH 1/2] Make kthread_create and kthread_run typesafe
On Fri, Jan 18, 2008 at 11:51:39AM +1100, Rusty Russell wrote:
>With a little macro ugliness, we can make kthread_create() and
>kthread_run() typesafe: avoid the casts to and from void *. To do
>this we use a temporary function pointer which takes the type of the
>data as a callback: if the function doesn't match, we get:
>
> warning: initialization from incompatible pointer type
>
>It's actually slightly over-strict, since a void * would be compatible
>with any function type, but there's only one such case in the kernel
>anyway.
{snip}
>+#define kthread_create(threadfn, data, namefmt...) ({ \
>+ int (*_threadfn)(typeof(data)) = (threadfn); \
>+ __kthread_create((void *)_threadfn, (data), namefmt); \
>+})
>+
>+struct task_struct *__kthread_create(int (*threadfn)(void *data),
>+ void *data,
>+ const char namefmt[], ...);
Rusty, excellent work!!
I really like this. It is a good trick, neat and clean.
Thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists