lkml.org 
[lkml]   [2008]   [Jan]   [18]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
DateFri, 18 Jan 2008 13:18:07 +0800
FromWANG Cong <>
SubjectRe: [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.



\
 
 \ /
  Last update: 2008-01-18 06:21    [from the cache]
©2003-2008