From: Luiz Fernando Capitulino <lcapitulino@mandriva.com.br>
To: gregkh@suse.de
Cc: linux-kernel@vger.kernel.org,
linux-usb-devel@lists.sourceforge.net, ehabkost@mandriva.com
Subject: [PATCH 01/10] usb-serial: URB write locking macros.
Date: Tue, 6 Dec 2005 09:57:22 -0200 [thread overview]
Message-ID: <20051206095722.45cf4a32.lcapitulino@mandriva.com.br> (raw)
Introduces URB write locking macros.
Signed-off-by: Luiz Capitulino <lcapitulino@mandriva.com.br>
drivers/usb/serial/usb-serial.h | 37 ++++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff -Nparu -X /home/lcapitulino/kernels/dontdiff a/drivers/usb/serial/usb-serial.h a~/drivers/usb/serial/usb-serial.h
--- a/drivers/usb/serial/usb-serial.h 2005-12-04 20:05:26.000000000 -0200
+++ a~/drivers/usb/serial/usb-serial.h 2005-12-04 20:06:53.000000000 -0200
@@ -17,6 +17,7 @@
#include <linux/config.h>
#include <linux/kref.h>
#include <asm/semaphore.h>
+#include <asm/atomic.h>
#define SERIAL_TTY_MAJOR 188 /* Nice legal number now */
#define SERIAL_TTY_MINORS 255 /* loads of devices :) */
@@ -83,7 +84,7 @@ struct usb_serial_port {
unsigned char * bulk_out_buffer;
int bulk_out_size;
struct urb * write_urb;
- int write_urb_busy;
+ atomic_t write_urb_busy;
__u8 bulk_out_endpointAddress;
wait_queue_head_t write_wait;
@@ -104,6 +105,40 @@ static inline void usb_set_serial_port_d
dev_set_drvdata(&port->dev, data);
}
+/*
+ * usb_serial URB write access locking functions
+ *
+ * Protects 'write_urb_busy' member access, used to avoid two or more threads
+ * trying to write the same URB at the same time.
+ */
+
+/* Initialize the lock */
+static inline void usb_serial_write_urb_lock_init(struct usb_serial_port *port)
+{
+ atomic_set(&port->write_urb_busy, 0);
+}
+
+/*
+ * Lock function: returns zero if the lock was acquired,
+ * and non-zero otherwise
+ */
+static inline int usb_serial_write_urb_lock(struct usb_serial_port *port)
+{
+ return !atomic_add_unless(&port->write_urb_busy, 1, 1);
+}
+
+/* unlock function */
+static inline void usb_serial_write_urb_unlock(struct usb_serial_port *port)
+{
+ atomic_set(&port->write_urb_busy, 0);
+}
+
+/* Lock test: returns non-zero if the port is locked, and zero otherwise */
+static inline int usb_serial_write_urb_locked(struct usb_serial_port *port)
+{
+ return atomic_read(&port->write_urb_busy);
+}
+
/**
* usb_serial - structure used by the usb-serial core for a device
* @dev: pointer to the struct usb_device for this device
--
Luiz Fernando N. Capitulino
next reply other threads:[~2005-12-06 12:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-06 11:57 Luiz Fernando Capitulino [this message]
2005-12-06 12:24 ` Arjan van de Ven
2005-12-06 12:37 ` Luiz Fernando Capitulino
2005-12-06 12:46 ` Eduardo Pereira Habkost
2005-12-06 12:35 ` [linux-usb-devel] " Oliver Neukum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20051206095722.45cf4a32.lcapitulino@mandriva.com.br \
--to=lcapitulino@mandriva.com.br \
--cc=ehabkost@mandriva.com \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®