worenga
worenga

Reputation: 5856

kthread_run -- Purpose of last statement (__k;)

I am reading the linux kernel, specifically i am looking at the process creation and stumbled upon the following macro [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;                                   \
})

My question is simple: What is the purpose of the last line's : __k;?

[1] http://lxr.free-electrons.com/source/include/linux/kthread.h#L31

Upvotes: 3

Views: 514

Answers (1)

Richard Pennington
Richard Pennington

Reputation: 19975

That macro is a statement expression. __k is the return value (the thread pointer). Statement expressions are a GCC extension that is also supported by clang.

Upvotes: 5

Related Questions