LinuxSir.cn,穿越时空的Linuxsir!

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

求助:设备驱动程序中进程的锁定

[复制链接]
发表于 2007-3-26 18:41:42 | 显示全部楼层 |阅读模式
写了一个PCI的字符设备,如下:

全局变量:
static int catch_interrupt = 0;
static char *mymem;
static DECLARE_WAIT_QUEUE_HEAD(read_wait);
static DECLARE_WAIT_QUEUE_HEAD(write_wait);
static DECLARE_MUTEX(wait);

....................
...................

my_func(BYTE *data, int len)
{
               if (down_interruptible(&wait)) {
                printk("write wait get wait error!\n");
                return -ERESTARTSYS;
        }
              time_out = HZ *10;
              memcpy(mymem, data, len);//写数据
             catch_interrupt = 0;
             寄存器操作,硬件设备完成后,产生中断,在中断处理程序中catch_interrupt =1
         添加定时器
          wait_event_interruptible(read_wait, catch_interrupt !=0);//等待硬件设备产生中断
              catch_interrupt = 0;
             if (signal_pending(current) || !time_out) {/* a signal arrived */
                printk("time_out = %d\n", time_out);
                up(&wait);
                删除定时器
                           return -ERESTARTSYS; /* tell the fs layer to handle it */
        }
            删除定时器
        memcpy(data, mymem, len);//写数据
            up(&wait);
return 0;
}

想要实现当进程A写数据并读出数据后,其他进程才能写数据,但现在多个进程进行操作时,却出现了错

误;
这样对进程进行锁定有问题吗?
 楼主| 发表于 2007-3-28 12:42:09 | 显示全部楼层
问题解决,
这样锁定没有问题;问题是当调用wait_event_interruptible,进程等待时,系统调用了其他进程
,其他的进程进行了一些操作,破坏了我的内存;
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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