LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1530|回复: 0

有关down_interruptible有些不明白的地方

[复制链接]
发表于 2008-5-23 14:21:46 | 显示全部楼层 |阅读模式
最近在看rt73芯片无线网卡的驱动,里面有这样几行代码  
                while (down_interruptible(&pAd->mlme_semaphore) == 0)
        {
                if(!netif_running(pAd->net_dev))
                        continue;


                /* lock the device pointers , need to check if required*/
                if (down_interruptible(&(pAd->usbdev_semaphore)))
                        break;


                // Always call Bulk routine, even reset bulk.
                // The protectioon of rest bulk should be in BulkOut routine
                RTUSBKickBulkOut(pAd);
                RTUSBDequeueRxPackets(pAd);//TO BE CONTINUED......
                MlmeHandler(pAd);

                /* unlock the device pointers */
                up(&(pAd->usbdev_semaphore));
        }
对down_interruptible来说,它能被信号打断,因此该函数有返回值来区分是正常返回还是被信号中断,如果返回0,表示获得信号量正常返回,如果被信号打断,返回-EINTR
我的理解是,如果没有信号中断,那么一旦执行了up(&pAd->mlme_semaphore),就会通过down_interruptible(&pAd->mlme_semaphore) == 0,重新进入while循环,依次往下执行,直到再次停在while (down_interruptible(&pAd->mlme_semaphore) == 0)这里。
    我不明白的是,
    1.mlme thread是怎么停在down_interruptible(&pAd->mlme_semaphore)这里的。是通过睡眠吗?
    2.一旦up了之后,是否这样,内核立即检查该信号所释放的资源有没有被其他线程申请,于是找到while (down_interruptible(&pAd->mlme_semaphore) == 0)这里,返回零,再进入while循环体?
   
    我刚开始学,很多地方不懂,请大家多指教。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表