From: WANG Cong <xiyou.wangcong@gmail.com>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 1/2] Make kthread_create and kthread_run typesafe
Date: Fri, 18 Jan 2008 13:18:07 +0800 [thread overview]
Message-ID: <20080118051807.GB2559@hacking> (raw)
In-Reply-To: <200801181151.40141.rusty@rustcorp.com.au>
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.
prev parent reply other threads:[~2008-01-18 5:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-18 0:51 [PATCH 1/2] Make kthread_create and kthread_run typesafe Rusty Russell
2008-01-18 0:52 ` [PATCH 2/2] Fix up the kthread function types Rusty Russell
2008-01-18 5:18 ` WANG Cong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080118051807.GB2559@hacking \
--to=xiyou.wangcong@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox