Change pseudo-locking to spin locks.
authorDavid Schleef <ds@schleef.org>
Thu, 16 May 2002 22:10:53 +0000 (22:10 +0000)
committerDavid Schleef <ds@schleef.org>
Thu, 16 May 2002 22:10:53 +0000 (22:10 +0000)
comedi/comedi_fops.c
comedi/comedi_ksyms.c
comedi/kcomedilib/kcomedilib_main.c
include/linux/comedidev.h

index 0cc81a907bd8e9db9a74b01ed9ec84d2236ac022..9c8ed70ba57bce2afb583ec360fa03b72f8e839b 100644 (file)
@@ -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;
index 1b269ca1a16125511bfb1505a707f512f9116780..46681172922760d762bb7ea53d985ccd4e307416 100644 (file)
@@ -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
index 7043b032e85f1a148031918bfd0a4ce500971302..b4615886848985b21649b42c2791cbcfa7f256a1 100644 (file)
@@ -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;
 }
index 715db3271e07ce82d175d6a5b80e27f28f573dd8..fae7dc43a0e9bdfd474f2ad7e31e44efe22df689 100644 (file)
@@ -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 */