简体   繁体   English

Down_Interruptible不起作用

[英]Down_Interruptible Not Working

In a Linux Kernel Module I am trying to change code that says: 在Linux内核模块中,我尝试更改代码,内容为:

down(&semaphore1);

down(&semaphore2);

   critical code here!

up(&semaphore2);

up(&semaphore1);

To use down_interruptible(); 使用down_interruptible();

if(down_interruptible(&semaphore1))
   return -ERESTARTSYS;

if(down_interruptible(&semaphore2))
   return -ERESTARTSYS;

   critical code here!

up(&semaphore2);

up(&semaphore1);

Is this the correct way to switch from the "depricated" down to down_interruptible ? 这是从“已down ”切换到down_interruptible的正确方法吗?

I don't understand what return -ERESTARTSYS; 我不明白return -ERESTARTSYS; does, but to me it seems that it makes my kernel module exit and allow the kernel to do some other stuff until my kernel module is awaken again, is that it? 确实如此,但是对我来说,这似乎使我的内核模块退出并允许内核做其他事情,直到我的内核模块再次被唤醒,是吗?

All fine, except one: you must release semaphore1 before second return: 一切正常,除了以下一项:您必须在第二次返回之前释放semaphore1:

if(down_interruptible(&semaphore1))
   return -ERESTARTSYS;

if(down_interruptible(&semaphore2)) {
   up(&semaphore1);
   return -ERESTARTSYS;
}

   critical code here!

up(&semaphore2);

up(&semaphore1);

Description about usage ERESTARTSYS see the answer . 有关用法的描述ERESTARTSYS参见答案

In general, down_interruptible could be interrupted by signal to userspace application. 通常,down_interruptible可以被发送给用户空间应用程序的信号中断。 Returning ERESTARTSYS you tell the kernel to handle signal and to call driver again. 返回ERESTARTSYS,您告诉内核处理信号并再次调用驱动程序。 Unless you release semaphore1 second call to driver would block on semaphore1. 除非释放semaphore1,否则第二次调用驱动程序将阻塞semaphore1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM