From: Ian Abbott Date: Wed, 5 Dec 2007 12:52:15 +0000 (+0000) Subject: Use per-subdevice spin-lock instead of big_comedi_lock. Renamed existing X-Git-Tag: v0_7_76~30 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8a78c59a89e2cfea9a0441220510230fed1050fd;p=comedi.git Use per-subdevice spin-lock instead of big_comedi_lock. Renamed existing subdevice 'runflags_lock' to 'spin_lock' for more general use. (Could have used a separate spin-lock for locking/unlocking subdevices, but there shouldn't be much contention for the existing spin-lock used for setting/ getting runflags.) --- diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index 2513b014..e686a178 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -60,7 +60,6 @@ module_param(comedi_debug, int, 0644); #endif comedi_device *comedi_devices; -spinlock_t big_comedi_lock; /* Dynamic initialization */ static int do_devconfig_ioctl(comedi_device * dev, comedi_devconfig * arg); static int do_bufconfig_ioctl(comedi_device * dev, void *arg); @@ -1159,17 +1158,13 @@ static int do_lock_ioctl(comedi_device * dev, unsigned int arg, void *file) return -EINVAL; s = dev->subdevices + arg; - comedi_spin_lock_irqsave(&big_comedi_lock, flags); - if (s->busy) { - comedi_spin_unlock_irqrestore(&big_comedi_lock, flags); - return -EBUSY; - } - if (s->lock) { + comedi_spin_lock_irqsave(&s->spin_lock, flags); + if (s->busy || s->lock) { ret = -EBUSY; } else { s->lock = file; } - comedi_spin_unlock_irqrestore(&big_comedi_lock, flags); + comedi_spin_unlock_irqrestore(&s->spin_lock, flags); if (ret < 0) return ret; @@ -1753,7 +1748,6 @@ static int __init comedi_init(void) printk("comedi: version " COMEDI_RELEASE " - David Schleef \n"); - spin_lock_init(&big_comedi_lock); retval = register_chrdev_region(MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS, "comedi"); if (retval) @@ -1912,10 +1906,10 @@ void comedi_set_subdevice_runflags(comedi_subdevice * s, unsigned mask, { unsigned long flags; - comedi_spin_lock_irqsave(&s->runflags_lock, flags); + comedi_spin_lock_irqsave(&s->spin_lock, flags); s->runflags &= ~mask; s->runflags |= (bits & mask); - comedi_spin_unlock_irqrestore(&s->runflags_lock, flags); + comedi_spin_unlock_irqrestore(&s->spin_lock, flags); } unsigned comedi_get_subdevice_runflags(comedi_subdevice * s) @@ -1923,8 +1917,8 @@ unsigned comedi_get_subdevice_runflags(comedi_subdevice * s) unsigned long flags; unsigned runflags; - comedi_spin_lock_irqsave(&s->runflags_lock, flags); + comedi_spin_lock_irqsave(&s->spin_lock, flags); runflags = s->runflags; - comedi_spin_unlock_irqrestore(&s->runflags_lock, flags); + comedi_spin_unlock_irqrestore(&s->spin_lock, flags); return runflags; } diff --git a/comedi/comedi_ksyms.c b/comedi/comedi_ksyms.c index bfdafed3..1189a896 100644 --- a/comedi/comedi_ksyms.c +++ b/comedi/comedi_ksyms.c @@ -61,7 +61,6 @@ EXPORT_SYMBOL(comedi_debug); /* for kcomedilib */ EXPORT_SYMBOL(comedi_devices); -EXPORT_SYMBOL(big_comedi_lock); EXPORT_SYMBOL(check_chanlist); EXPORT_SYMBOL(comedi_buf_put); diff --git a/comedi/kcomedilib/kcomedilib_main.c b/comedi/kcomedilib/kcomedilib_main.c index fecfecb7..c68e64cf 100644 --- a/comedi/kcomedilib/kcomedilib_main.c +++ b/comedi/kcomedilib/kcomedilib_main.c @@ -312,7 +312,7 @@ int comedi_lock(comedi_t * d, unsigned int subdevice) unsigned long flags; int ret = 0; - comedi_spin_lock_irqsave(&big_comedi_lock, flags); + comedi_spin_lock_irqsave(&s->spin_lock, flags); if (s->busy) { ret = -EBUSY; @@ -324,7 +324,7 @@ int comedi_lock(comedi_t * d, unsigned int subdevice) } } - comedi_spin_unlock_irqrestore(&big_comedi_lock, flags); + comedi_spin_unlock_irqrestore(&s->spin_lock, flags); return ret; } @@ -349,32 +349,31 @@ int comedi_unlock(comedi_t * d, unsigned int subdevice) comedi_subdevice *s = dev->subdevices + subdevice; unsigned long flags; comedi_async *async; + int ret; async = s->async; - comedi_spin_lock_irqsave(&big_comedi_lock, flags); + comedi_spin_lock_irqsave(&s->spin_lock, flags); if (s->busy) { - comedi_spin_unlock_irqrestore(&big_comedi_lock, flags); - return -EBUSY; - } - - if (s->lock && s->lock != (void *)d) { - comedi_spin_unlock_irqrestore(&big_comedi_lock, flags); - return -EACCES; - } + ret = -EBUSY; + } else if (s->lock && s->lock != (void *)d) { + ret = -EACCES; + } else { + s->lock = NULL; - s->lock = NULL; + if (async) { + async->cb_mask = 0; + async->cb_func = NULL; + async->cb_arg = NULL; + } - if (async) { - async->cb_mask = 0; - async->cb_func = NULL; - async->cb_arg = NULL; + ret = 0; } - comedi_spin_unlock_irqrestore(&big_comedi_lock, flags); + comedi_spin_unlock_irqrestore(&s->spin_lock, flags); - return 0; + return ret; } /* diff --git a/include/linux/comedidev.h b/include/linux/comedidev.h index 500d11d3..86bb0072 100644 --- a/include/linux/comedidev.h +++ b/include/linux/comedidev.h @@ -106,7 +106,7 @@ struct comedi_subdevice_struct { void *lock; void *busy; unsigned runflags; - spinlock_t runflags_lock; + spinlock_t spin_lock; int io_bits; @@ -256,7 +256,6 @@ struct comedi_inode_private { }; extern comedi_device *comedi_devices; -extern spinlock_t big_comedi_lock; #ifdef CONFIG_COMEDI_DEBUG extern int comedi_debug; @@ -440,7 +439,7 @@ static inline int alloc_subdevices(comedi_device * dev, for (i = 0; i < num_subdevices; ++i) { dev->subdevices[i].device = dev; dev->subdevices[i].async_dma_dir = DMA_NONE; - spin_lock_init(&dev->subdevices[i].runflags_lock); + spin_lock_init(&dev->subdevices[i].spin_lock); } return 0; }