kthread_run -- 最后一条语句的目的 (__k;)
kthread_run -- Purpose of last statement (__k;)
我正在阅读 linux 内核,特别是我正在查看进程创建并偶然发现以下宏 [1]
/**
* kthread_run - create and wake a thread.
* @threadfn: the function to run until signal_pending(current).
* @data: data ptr for @threadfn.
* @namefmt: printf-style name for the thread.
*
* Description: Convenient wrapper for kthread_create() followed by
* wake_up_process(). Returns the kthread or ERR_PTR(-ENOMEM).
*/
#define kthread_run(threadfn, data, namefmt, ...) \
({ \
struct task_struct *__k \
= kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \
if (!IS_ERR(__k)) \
wake_up_process(__k); \
__k; \
})
我的问题很简单:最后一行的目的是什么:__k;
?
[1] http://lxr.free-electrons.com/source/include/linux/kthread.h#L31
那个宏是 statement expression。 __k 是 return 值(线程指针)。
语句表达式是 clang 也支持的 GCC 扩展。
我正在阅读 linux 内核,特别是我正在查看进程创建并偶然发现以下宏 [1]
/**
* kthread_run - create and wake a thread.
* @threadfn: the function to run until signal_pending(current).
* @data: data ptr for @threadfn.
* @namefmt: printf-style name for the thread.
*
* Description: Convenient wrapper for kthread_create() followed by
* wake_up_process(). Returns the kthread or ERR_PTR(-ENOMEM).
*/
#define kthread_run(threadfn, data, namefmt, ...) \
({ \
struct task_struct *__k \
= kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \
if (!IS_ERR(__k)) \
wake_up_process(__k); \
__k; \
})
我的问题很简单:最后一行的目的是什么:__k;
?
[1] http://lxr.free-electrons.com/source/include/linux/kthread.h#L31
那个宏是 statement expression。 __k 是 return 值(线程指针)。 语句表达式是 clang 也支持的 GCC 扩展。