|
写了一个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写数据并读出数据后,其他进程才能写数据,但现在多个进程进行操作时,却出现了错
误;
这样对进程进行锁定有问题吗? |
|