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: Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
struct ni6501_private {
struct usb_endpoint_descriptor *ep_rx;
struct usb_endpoint_descriptor *ep_tx;
struct ni6501_private {
struct usb_endpoint_descriptor *ep_rx;
struct usb_endpoint_descriptor *ep_tx;
u8 *usb_rx_buf;
u8 *usb_tx_buf;
};
u8 *usb_rx_buf;
u8 *usb_tx_buf;
};
if (command != SET_PORT_DIR && !bitmap)
return -EINVAL;
if (command != SET_PORT_DIR && !bitmap)
return -EINVAL;
+ mutex_lock(&devpriv->mut);
switch (command) {
case READ_PORT:
switch (command) {
case READ_PORT:
+ mutex_unlock(&devpriv->mut);
if ((command == READ_COUNTER || command == WRITE_COUNTER) && !val)
return -EINVAL;
if ((command == READ_COUNTER || command == WRITE_COUNTER) && !val)
return -EINVAL;
+ mutex_lock(&devpriv->mut);
switch (command) {
case START_COUNTER:
switch (command) {
case START_COUNTER:
+ mutex_unlock(&devpriv->mut);
- sema_init(&devpriv->sem, 1);
+ mutex_init(&devpriv->mut);
usb_set_intfdata(intf, devpriv);
ret = comedi_alloc_subdevices(dev, 2);
usb_set_intfdata(intf, devpriv);
ret = comedi_alloc_subdevices(dev, 2);
+ mutex_lock(&devpriv->mut);
usb_set_intfdata(intf, NULL);
kfree(devpriv->usb_rx_buf);
kfree(devpriv->usb_tx_buf);
usb_set_intfdata(intf, NULL);
kfree(devpriv->usb_rx_buf);
kfree(devpriv->usb_tx_buf);
+ mutex_unlock(&devpriv->mut);
}
static struct comedi_driver ni6501_driver = {
}
static struct comedi_driver ni6501_driver = {