- 論壇徽章:
- 0
|
自己寫了一個(gè)CAN驅(qū)動(dòng)。fops的read如下:static ssize_t mcp251x_read(struct file *file, char __user *buf, size_t count, loff_t *ofs)
{
struct mcp251x *chip = file->private_data;
struct can_frame *frame;
if (count != sizeof(struct can_frame))
return -EINVAL;
if (down_interruptible(&chip->rxblock))
return -ERESTARTSYS;
while (chip->rxbin == chip->rxbout) {
up(&chip->rxblock);
if (file->f_flags & O_NONBLOCK)
return -EAGAIN;
if (wait_event_interruptible(chip->wq, (chip->rxbin != chip->rxbout)))
return -ERESTARTSYS;
if (down_interruptible(&chip->rxblock))
return -ERESTARTSYS;
}
frame = &chip->rxb[chip->rxbout];
if (copy_to_user(buf, frame, sizeof(struct can_frame))) {
up(&chip->rxblock);
return -EFAULT;
}
chip->rxbout++;
if(chip->rxbout >= MCP251X_BUF_LEN)
chip->rxbout = 0;
up(&chip->rxblock);
return count;
} |
| 測(cè)試運(yùn)行時(shí)沒什么問題,但是如果User應(yīng)用程序從運(yùn)行于后臺(tái)模式,當(dāng)User應(yīng)用程序從后臺(tái)模式轉(zhuǎn)為前臺(tái)時(shí)就發(fā)生死鎖。找了很長時(shí)間都沒有找到原因。謝謝各們幫忙。
[ 本帖最后由 sleep_meng 于 2007-5-16 10:45 編輯 ] |
|