0

Recently, I'm tracing source code about kthread-family. And I found something confused me.

#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;                                   \
})

If I replace above macro into real case ( call it ) will be:

// the type of `task_id` is struct task_struct
qinfo->task_id = ({                                    \
    struct task_struct *__k = kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \
    if (!IS_ERR(__k))wake_up_process(__k);\
    __k;
})

Follow by document, this macro can do kthread_create() followed by wake_up_process(). Also, returns the kthread. First two thing I can understand, but last I can't.

Following is my question: 1. Why __k can used as return value like this?

qinfo->task_id = ({statement1; statement2; __k});

2. What is the purpose or function of using curly braces '{....}'?

Steven
  • 811
  • 4
  • 23

0 Answers0