From: David Schleef Date: Thu, 16 May 2002 22:10:53 +0000 (+0000) Subject: Change pseudo-locking to spin locks. X-Git-Tag: r0_7_65~39 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7b252dc2d2356d3f93bb5358f65357755ecf6e15;p=comedi.git Change pseudo-locking to spin locks. --- diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index 0cc81a90..9c8ed70b 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -54,6 +54,7 @@ MODULE_LICENSE("GPL"); #endif comedi_device *comedi_devices; +spinlock_t big_comedi_lock = SPIN_LOCK_UNLOCKED; static int do_devconfig_ioctl(comedi_device *dev,comedi_devconfig *arg,kdev_t minor); static int do_bufconfig_ioctl(comedi_device *dev,void *arg); @@ -1010,26 +1011,12 @@ cleanup: writes: none - non-RT linux always controls rtcomedi_lock_semaphore. If an - RT-linux process wants the lock, it first checks rtcomedi_lock_semaphore. - If it is 1, it knows it is pre-empting this function, and fails. - Obviously, if RT-linux fails to get a lock, it *must* allow - linux to run, since that is the only way to free the lock. - - This function is not SMP compatible. - - necessary locking: - - ioctl/rt lock (this type) - - lock while subdevice busy - - lock while subdevice being programmed - */ -volatile int rtcomedi_lock_semaphore=0; - static int do_lock_ioctl(comedi_device *dev,unsigned int arg,void * file) { int ret=0; + unsigned long flags; comedi_subdevice *s; if(arg>=dev->n_subdevices) @@ -1039,7 +1026,7 @@ static int do_lock_ioctl(comedi_device *dev,unsigned int arg,void * file) if(s->busy) return -EBUSY; - rtcomedi_lock_semaphore=1; + comedi_spin_lock_irqsave(&big_comedi_lock, flags); if(s->lock && s->lock!=file){ ret=-EACCES; @@ -1047,7 +1034,7 @@ static int do_lock_ioctl(comedi_device *dev,unsigned int arg,void * file) s->lock=file; } - rtcomedi_lock_semaphore=0; + comedi_spin_unlock_irqrestore(&big_comedi_lock, flags); if(ret<0) return ret; diff --git a/comedi/comedi_ksyms.c b/comedi/comedi_ksyms.c index 1b269ca1..46681172 100644 --- a/comedi/comedi_ksyms.c +++ b/comedi/comedi_ksyms.c @@ -61,7 +61,7 @@ EXPORT_SYMBOL(rt_pend_call); /* for kcomedilib */ EXPORT_SYMBOL(comedi_devices); -EXPORT_SYMBOL(rtcomedi_lock_semaphore); +EXPORT_SYMBOL(big_comedi_lock); EXPORT_SYMBOL(check_chanlist); #endif diff --git a/comedi/kcomedilib/kcomedilib_main.c b/comedi/kcomedilib/kcomedilib_main.c index 7043b032..b4615886 100644 --- a/comedi/kcomedilib/kcomedilib_main.c +++ b/comedi/kcomedilib/kcomedilib_main.c @@ -46,8 +46,6 @@ MODULE_DESCRIPTION("Comedi kernel library"); MODULE_LICENSE("GPL"); -static spinlock_t lock_spinlock; - comedi_t *comedi_open(const char *filename) { @@ -238,7 +236,7 @@ int comedi_do_insn(comedi_t *d,comedi_insn *insn) ret = -EBUSY; goto error; } - s->busy = (void *)&rtcomedi_lock_semaphore; + s->busy = d; switch(insn->insn){ case INSN_READ: @@ -297,7 +295,7 @@ int comedi_lock(comedi_t *d,unsigned int subdevice) unsigned long flags; int ret=0; - comedi_spin_lock_irqsave(&lock_spinlock,flags); + comedi_spin_lock_irqsave(&big_comedi_lock,flags); if(s->busy){ ret = -EBUSY; @@ -306,11 +304,11 @@ int comedi_lock(comedi_t *d,unsigned int subdevice) ret = -EACCES; }else{ __MOD_INC_USE_COUNT(dev->driver->module); - s->lock=(void *)&rtcomedi_lock_semaphore; + s->lock = d; } } - comedi_spin_unlock_irqrestore(&lock_spinlock,flags); + comedi_spin_unlock_irqrestore(&big_comedi_lock,flags); return ret; } @@ -339,15 +337,15 @@ int comedi_unlock(comedi_t *d,unsigned int subdevice) async = s->async; - comedi_spin_lock_irqsave(&lock_spinlock,flags); + comedi_spin_lock_irqsave(&big_comedi_lock,flags); if(s->busy){ - comedi_spin_unlock_irqrestore(&lock_spinlock,flags); + comedi_spin_unlock_irqrestore(&big_comedi_lock,flags); return -EBUSY; } if(s->lock && s->lock!=(void *)d){ - comedi_spin_unlock_irqrestore(&lock_spinlock,flags); + comedi_spin_unlock_irqrestore(&big_comedi_lock,flags); return -EACCES; } @@ -360,7 +358,7 @@ int comedi_unlock(comedi_t *d,unsigned int subdevice) } __MOD_DEC_USE_COUNT(dev->driver->module); - comedi_spin_unlock_irqrestore(&lock_spinlock,flags); + comedi_spin_unlock_irqrestore(&big_comedi_lock,flags); return 0; } diff --git a/include/linux/comedidev.h b/include/linux/comedidev.h index 715db327..fae7dc43 100644 --- a/include/linux/comedidev.h +++ b/include/linux/comedidev.h @@ -214,6 +214,7 @@ struct comedi_device_struct{ extern comedi_device *comedi_devices; +extern spinlock_t big_comedi_lock; /* * function prototypes @@ -270,8 +271,6 @@ static inline void comedi_proc_cleanup(void) {} int do_rangeinfo_ioctl(comedi_device *dev,comedi_rangeinfo *arg); int check_chanlist(comedi_subdevice *s,int n,unsigned int *chanlist); -extern volatile int rtcomedi_lock_semaphore; - /* range stuff */