linux内核函数kthread_run()

本文详细介绍了Linux内核中kthread_run宏的作用及使用方法。该宏用于创建并唤醒一个内核线程,简化了kthread_create和wake_up_process两个步骤。文章提供了宏的具体定义,帮助读者理解其内部实现。

在include/linux/kthread.h里有如下的宏定义,用来创建和唤醒一个线程

 /**
  18 * kthread_run - create and wake a thread.
  19 * @threadfn: the function to run until signal_pending(current).
  20 * @data: data ptr for @threadfn.
  21 * @namefmt: printf-style name for the thread.
  22 *
  23 * Description: Convenient wrapper for kthread_create() followed by
  24 * wake_up_process().  Returns the kthread or ERR_PTR(-ENOMEM).
  25 */
  26#define kthread_run(threadfn, data, namefmt, ...)                          \
  27({                                                                         \
  28        struct task_struct *__k                                            \
  29                = kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \
  30        if (!IS_ERR(__k))                                                  \
  31                wake_up_process(__k);                                      \
  32        __k;                                                               \
  33})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值