一、completion介绍

二、API

#define DECLARE_COMPLETION(work) \
struct completion work = COMPLETION_INITIALIZER(work)

//定义和初始化
struct completion completion;
static inline void init_completion(struct completion *x);

//等待完成量,此函数不可中断,即对临界区进行枷锁
void __sched wait_for_completion(struct completion x);

//等待超时的情况下返回,也就是说如果经过给定的时间该完成量还没有被唤醒,就直接返回,这样最大的好处就是经过一定的时间该进程已经不需要等待某事件,那么就可以直接被唤醒继续执行
unsigned long __sched wait_for_completion_timeout(struct completion x, unsigned long timeout);

void __sched wait_for_completion_io(struct completion x);

unsigned long __sched wait_for_completion_io_timeout(struct completion x, unsigned long timeout);

int __sched wait_for_completion_interruptible(struct completion x);

long __sched wait_for_completion_killable(struct completion x):

long __sched wait_for_completion_killable_timeout(struct completion x, unsigned long timeout);

bool try_wait_for_completion(struct completion x):

//用于唤醒一个等待该完成量的进程,即对临界区进行解锁
void complete(struct completion x);

//唤醒所有等待该完成量的进程
void complete_all(struct completion *x);

三、使用

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐