Linux内核中的wake_lock

#include
#include

struct wake_lock wlock;

初始化(一般放在probe或者register函数里):
wake_lock_init(&wlock, WAKE_LOCK_SUSPEND, "wlock name");

判断是否已加锁,释放锁
if (wake_lock_active(&pon->wlock)) {
wake_unlock(&pon->wlock);
}

判断是否已加锁,加锁
if (!wake_lock_active(&pon->wlock)) {
wake_lock(&pon->wlock);
}

销毁锁(一般放在remove或者unregister函数里)
wake_lock_destroy(&pon->wlock);

超时锁
wake_lock_timeout(&pon->wlock, msecs_to_jiffies(N)); //N ms之后自动释放锁

你可能感兴趣的:(Linux,wake_lock)