Commit 5a731c70 authored by Ksenija Stanojevic's avatar Ksenija Stanojevic Committed by Greg Kroah-Hartman

Staging: comedi: Use mutex instead of semaphore in ni_usb6501.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 27a90695
......@@ -166,7 +166,7 @@ enum commands {
struct ni6501_private {
struct usb_endpoint_descriptor *ep_rx;
struct usb_endpoint_descriptor *ep_tx;
struct semaphore sem;
struct mutex mut;
u8 *usb_rx_buf;
u8 *usb_tx_buf;
};
......@@ -183,7 +183,7 @@ static int ni6501_port_command(struct comedi_device *dev, int command,
if (command != SET_PORT_DIR && !bitmap)
return -EINVAL;
down(&devpriv->sem);
mutex_lock(&devpriv->mut);
switch (command) {
case READ_PORT:
......@@ -248,7 +248,7 @@ static int ni6501_port_command(struct comedi_device *dev, int command,
ret = -EINVAL;
}
end:
up(&devpriv->sem);
mutex_unlock(&devpriv->mut);
return ret;
}
......@@ -265,7 +265,7 @@ static int ni6501_counter_command(struct comedi_device *dev, int command,
if ((command == READ_COUNTER || command == WRITE_COUNTER) && !val)
return -EINVAL;
down(&devpriv->sem);
mutex_lock(&devpriv->mut);
switch (command) {
case START_COUNTER:
......@@ -338,7 +338,7 @@ static int ni6501_counter_command(struct comedi_device *dev, int command,
ret = -EINVAL;
}
end:
up(&devpriv->sem);
mutex_unlock(&devpriv->mut);
return ret;
}
......@@ -535,7 +535,7 @@ static int ni6501_auto_attach(struct comedi_device *dev,
if (ret)
return ret;
sema_init(&devpriv->sem, 1);
mutex_init(&devpriv->mut);
usb_set_intfdata(intf, devpriv);
ret = comedi_alloc_subdevices(dev, 2);
......@@ -573,14 +573,14 @@ static void ni6501_detach(struct comedi_device *dev)
if (!devpriv)
return;
down(&devpriv->sem);
mutex_lock(&devpriv->mut);
usb_set_intfdata(intf, NULL);
kfree(devpriv->usb_rx_buf);
kfree(devpriv->usb_tx_buf);
up(&devpriv->sem);
mutex_unlock(&devpriv->mut);
}
static struct comedi_driver ni6501_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