Commit 27a90695 authored by Ksenija Stanojevic's avatar Ksenija Stanojevic Committed by Greg Kroah-Hartman

Staging: comedi: Use mutex instead of semaphore in usbduxfast.c

Replace binary semaphore with mutex because mutex gives better
performance.
This change is safe because the thread that decrements the value of semaphore
is also the one that increments it, and acts like a mutex where owner of the
lock is the only one that can release the lock.
Signed-off-by: default avatarKsenija Stanojevic <ksenija.stanojevic@gmail.com>
Reviewed-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 1e5cae2f
......@@ -160,7 +160,7 @@ struct usbduxfast_private {
s8 *inbuf;
short int ai_cmd_running; /* asynchronous command is running */
int ignore; /* counter which ignores the first buffers */
struct semaphore sem;
struct mutex mut;
};
/*
......@@ -221,9 +221,9 @@ static int usbduxfast_ai_cancel(struct comedi_device *dev,
struct usbduxfast_private *devpriv = dev->private;
int ret;
down(&devpriv->sem);
mutex_lock(&devpriv->mut);
ret = usbduxfast_ai_stop(dev, 1);
up(&devpriv->sem);
mutex_unlock(&devpriv->mut);
return ret;
}
......@@ -444,7 +444,7 @@ static int usbduxfast_ai_inttrig(struct comedi_device *dev,
if (trig_num != cmd->start_arg)
return -EINVAL;
down(&devpriv->sem);
mutex_lock(&devpriv->mut);
if (!devpriv->ai_cmd_running) {
devpriv->ai_cmd_running = 1;
......@@ -452,14 +452,14 @@ static int usbduxfast_ai_inttrig(struct comedi_device *dev,
if (ret < 0) {
dev_err(dev->class_dev, "urbSubmit: err=%d\n", ret);
devpriv->ai_cmd_running = 0;
up(&devpriv->sem);
mutex_unlock(&devpriv->mut);
return ret;
}
s->async->inttrig = NULL;
} else {
dev_err(dev->class_dev, "ai is already running\n");
}
up(&devpriv->sem);
mutex_unlock(&devpriv->mut);
return 1;
}
......@@ -472,7 +472,7 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev,
int j, ret;
long steps, steps_tmp;
down(&devpriv->sem);
mutex_lock(&devpriv->mut);
if (devpriv->ai_cmd_running) {
ret = -EBUSY;
goto cmd_exit;
......@@ -751,7 +751,7 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev,
}
cmd_exit:
up(&devpriv->sem);
mutex_unlock(&devpriv->mut);
return ret;
}
......@@ -772,12 +772,12 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
int i, j, n, actual_length;
int ret;
down(&devpriv->sem);
mutex_lock(&devpriv->mut);
if (devpriv->ai_cmd_running) {
dev_err(dev->class_dev,
"ai_insn_read not possible, async cmd is running\n");
up(&devpriv->sem);
mutex_unlock(&devpriv->mut);
return -EBUSY;
}
......@@ -799,7 +799,7 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
ret = usbduxfast_send_cmd(dev, SENDADCOMMANDS);
if (ret < 0) {
up(&devpriv->sem);
mutex_unlock(&devpriv->mut);
return ret;
}
......@@ -809,7 +809,7 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
&actual_length, 10000);
if (ret < 0) {
dev_err(dev->class_dev, "insn timeout, no data\n");
up(&devpriv->sem);
mutex_unlock(&devpriv->mut);
return ret;
}
}
......@@ -820,13 +820,13 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
&actual_length, 10000);
if (ret < 0) {
dev_err(dev->class_dev, "insn data error: %d\n", ret);
up(&devpriv->sem);
mutex_unlock(&devpriv->mut);
return ret;
}
n = actual_length / sizeof(u16);
if ((n % 16) != 0) {
dev_err(dev->class_dev, "insn data packet corrupted\n");
up(&devpriv->sem);
mutex_unlock(&devpriv->mut);
return -EINVAL;
}
for (j = chan; (j < n) && (i < insn->n); j = j + 16) {
......@@ -835,7 +835,7 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
}
}
up(&devpriv->sem);
mutex_unlock(&devpriv->mut);
return insn->n;
}
......@@ -930,7 +930,7 @@ static int usbduxfast_auto_attach(struct comedi_device *dev,
if (!devpriv)
return -ENOMEM;
sema_init(&devpriv->sem, 1);
mutex_init(&devpriv->mut);
usb_set_intfdata(intf, devpriv);
devpriv->duxbuf = kmalloc(SIZEOFDUXBUF, GFP_KERNEL);
......@@ -989,7 +989,7 @@ static void usbduxfast_detach(struct comedi_device *dev)
if (!devpriv)
return;
down(&devpriv->sem);
mutex_lock(&devpriv->mut);
usb_set_intfdata(intf, NULL);
......@@ -1003,7 +1003,7 @@ static void usbduxfast_detach(struct comedi_device *dev)
kfree(devpriv->duxbuf);
up(&devpriv->sem);
mutex_unlock(&devpriv->mut);
}
static struct comedi_driver usbduxfast_driver = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment