linux常用的锁及信号量的提取

1.信号量( 两个进程之间同步)
struct semaphore power_sem;
sema_init(&pdata->power_sem,1);
down(&pdata->power_sem);
up(&pdata->power_sem);


2.互斥量

struct mutex led_mutex;
mutex_init(&led_mutex);
mutex_lock(&led_mutex);
while(t--);// for delay
mutex_unlock(&led_mutex);
mutex_destroy(&led_mutex);

3.wakup锁:
static struct wake_lock ec43_wlock;
wake_lock_init(&ec43_wlock, WAKE_LOCK_SUSPEND, "ec43_wakelock");
wake_lock_timeout(&ec43_wlock, msecs_to_jiffies(10*1000));
//等于上面 wake_lock_timeout(&ec43_wlock, 10*HZ);
wake_lock_destroy(&ec43_wlock);

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。